Merge branch 'main' of https://gitea.lihaink.cn/mkm/multi-store
This commit is contained in:
commit
ba0ddbe1ac
@ -37,6 +37,6 @@ class ExceptionHandler extends Handler
|
||||
return response(json_encode($error, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
// 非json请求则返回一个页面
|
||||
return new Response(200, [], $exception->getMessage());
|
||||
return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile());
|
||||
}
|
||||
}
|
||||
|
@ -5,24 +5,60 @@ namespace app\api\controller;
|
||||
use app\admin\validate\tools\GenerateTableValidate;
|
||||
use app\admin\logic\tools\GeneratorLogic;
|
||||
use app\common\logic\store_order\StoreOrderLogic;
|
||||
use app\common\service\pay\PayService;
|
||||
use app\common\service\wechat\WechatTemplate;
|
||||
use Exception;
|
||||
use think\facade\Db;
|
||||
use Webman\Config;
|
||||
use hg\apidoc\annotation as ApiDoc;
|
||||
use Yansongda\Pay\Exception\InvalidSignException;
|
||||
|
||||
#[ApiDoc\NotParse()]
|
||||
|
||||
class IndexController extends BaseApiController
|
||||
{
|
||||
public $notNeedLogin = ['index','app_update','express_list','province','city','area','street'];
|
||||
public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street'];
|
||||
|
||||
public function index()
|
||||
{
|
||||
try{
|
||||
$a=new WechatTemplate();
|
||||
$a->NewQuotationNotification(['openid'=>'ocqhF6UfFQXE-SbzbP5YVQJlQAh0','data1'=>'阿萨','data2'=>date('Y-m-d H:i:s'),'data3'=>'占山','data3'=>18982406440]);
|
||||
}catch (Exception $e){
|
||||
d($e);
|
||||
}
|
||||
|
||||
d(2);
|
||||
|
||||
$params=['store_id'=>2,'pay_type'=>17];
|
||||
$a=StoreOrderLogic::createOrder([1],0,null,$params);
|
||||
d(22);
|
||||
$auth_code = $this->request->get('code');
|
||||
$pay = (new PayService());
|
||||
$order = [
|
||||
'description' => '条码商品',
|
||||
'out_trade_no' => (string)time(),
|
||||
'payer' => [
|
||||
'auth_code' => (string)$auth_code
|
||||
],
|
||||
'amount' => [
|
||||
'total' =>1,
|
||||
],
|
||||
'scene_info' => [
|
||||
"store_info" => [
|
||||
'id' => '1'
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
try{
|
||||
$a= $pay->wechat->pos($order);
|
||||
|
||||
}catch (\Exception $th) {
|
||||
d($th);
|
||||
}
|
||||
d($a);
|
||||
$params = ['store_id' => 2, 'pay_type' => 17];
|
||||
$a = StoreOrderLogic::createOrder([1], 0, null, $params);
|
||||
d($a);
|
||||
return json(['msg' =>create_password(123456, '11d3')]);
|
||||
return json(['msg' => create_password(123456, '11d3')]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,42 +77,46 @@ class IndexController extends BaseApiController
|
||||
/**
|
||||
* @notes 获取app更新信息
|
||||
*/
|
||||
public function app_update(){
|
||||
$find= Db::name('app_update')->where('type',2)->order('id','desc')->findOrEmpty();
|
||||
return $this->success('ok',$find);
|
||||
public function app_update()
|
||||
{
|
||||
$find = Db::name('app_update')->where('type', 2)->order('id', 'desc')->findOrEmpty();
|
||||
return $this->success('ok', $find);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取省列表
|
||||
*/
|
||||
public function province(){
|
||||
$list= Db::name('geo_province')->select()->toArray();
|
||||
return $this->success('ok',$list);
|
||||
public function province()
|
||||
{
|
||||
$list = Db::name('geo_province')->select()->toArray();
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
/**
|
||||
* @notes 获取市列表
|
||||
*/
|
||||
public function city(){
|
||||
$province_code=$this->request->get('code');
|
||||
$list= Db::name('geo_city')->where('province_code',$province_code)->select()?->toArray();
|
||||
return $this->success('ok',$list);
|
||||
public function city()
|
||||
{
|
||||
$province_code = $this->request->get('code');
|
||||
$list = Db::name('geo_city')->where('province_code', $province_code)->select()?->toArray();
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
/**
|
||||
* @notes 获取区列表
|
||||
*/
|
||||
public function area(){
|
||||
$city_code=$this->request->get('code');
|
||||
$list= Db::name('geo_area')->where('city_code',$city_code)->select()?->toArray();
|
||||
return $this->success('ok',$list);
|
||||
public function area()
|
||||
{
|
||||
$city_code = $this->request->get('code');
|
||||
$list = Db::name('geo_area')->where('city_code', $city_code)->select()?->toArray();
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
/**
|
||||
* @notes 获取街道列表
|
||||
*/
|
||||
public function street(){
|
||||
$area_code=$this->request->get('area_code');
|
||||
$list= Db::name('geo_street')->where('area_code',$area_code)->select()?->toArray();
|
||||
return $this->success('ok',$list);
|
||||
public function street()
|
||||
{
|
||||
$area_code = $this->request->get('area_code');
|
||||
$list = Db::name('geo_street')->where('area_code', $area_code)->select()?->toArray();
|
||||
return $this->success('ok', $list);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,18 +28,19 @@ class PayController extends BaseApiController
|
||||
{
|
||||
$app = new PayService(1);
|
||||
$result = $app->wechat->callback(Request()->post());
|
||||
Cache::set('log'.time(),$result);
|
||||
Cache::set('logJ'.time(),json_encode($result));
|
||||
if ($result && $result->event_type == 'TRANSACTION.SUCCESS') {
|
||||
$ciphertext = $result->resource['ciphertext'];
|
||||
if ($ciphertext['trade_state'] === 'SUCCESS') {
|
||||
$extra['transaction_id'] = $ciphertext['transaction_id'];
|
||||
$attach = $ciphertext['attach'];
|
||||
switch ($attach) {
|
||||
case 'wechat_common':
|
||||
PayNotifyLogic::handle('wechat_common', $ciphertext['out_trade_no'], $ciphertext);
|
||||
$app->wechat->success();
|
||||
break;
|
||||
case 'recharge':
|
||||
PayNotifyLogic::handle('recharge', $ciphertext['out_trade_no'], $ciphertext);
|
||||
$app->wechat->success();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,30 @@ class OrderController extends BaseApiController
|
||||
return $this->dataLists(new OrderList());
|
||||
}
|
||||
|
||||
#[
|
||||
ApiDoc\Title('核销订单列表'),
|
||||
ApiDoc\url('/api/order/order/write_list'),
|
||||
ApiDoc\Method('POST'),
|
||||
ApiDoc\Param(name: "status", type: "int", require: true, desc: "1:待核销;2:已核销"),
|
||||
ApiDoc\Param(name: "page_no", type: "int", require: true, desc: "默认1页数"),
|
||||
ApiDoc\Param(name: "page_size", type: "int", require: false, desc: "条数默认15"),
|
||||
ApiDoc\NotHeaders(),
|
||||
ApiDoc\Header(name: "token", type: "string", require: true, desc: "token"),
|
||||
ApiDoc\ResponseSuccess("data", type: "array"),
|
||||
]
|
||||
public function write_list()
|
||||
{
|
||||
$status = (int)$this->request->post('status',1);
|
||||
$params = $this->request->post();
|
||||
$params['page_no'] = isset($params['page_no'])?: 1;
|
||||
$params['page_size'] = isset($params['page_size'])?: 15;
|
||||
$info = $this->userInfo;
|
||||
$res = OrderLogic::write_list($info,$status,$params);
|
||||
$res['page_no'] =$params['page_no'];
|
||||
$res['page_size'] =$params['page_size'];
|
||||
return $this->success('ok',$res);
|
||||
|
||||
}
|
||||
#[
|
||||
ApiDoc\Title('订单校验'),
|
||||
ApiDoc\url('/api/order/order/checkOrder'),
|
||||
@ -130,7 +154,7 @@ class OrderController extends BaseApiController
|
||||
case PayEnum::WECHAT_PAY:
|
||||
//微信支付
|
||||
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
|
||||
$result = PaymentLogic::pay($pay_type, 'StoreOrder', $order, $this->userInfo['terminal'], $redirectUrl);
|
||||
$result = PaymentLogic::pay($pay_type, 'wechat_common', $order, $this->userInfo['terminal'], $redirectUrl);
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError(), $params);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class UserController extends BaseApiController
|
||||
$params['channel_type'] = $this->userInfo['terminal'];
|
||||
$order = UserLogic::recharge($params);
|
||||
$redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
|
||||
$result = PaymentLogic::pay(PayEnum::WECHAT_PAY, 'StoreOrder', $order, $this->userInfo['terminal'], $redirectUrl);
|
||||
$result = PaymentLogic::pay(PayEnum::WECHAT_PAY, 'recharge', $order, $this->userInfo['terminal'], $redirectUrl);
|
||||
if (PaymentLogic::hasError()) {
|
||||
return $this->fail(PaymentLogic::getError(), $params);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_attr_value\StoreProductAttrValue;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\system_store\SystemStoreStaff;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAddress;
|
||||
use support\Log;
|
||||
@ -438,4 +439,54 @@ class OrderLogic extends BaseLogic
|
||||
}
|
||||
|
||||
|
||||
public static function write_list($info,$status,$params)
|
||||
{
|
||||
|
||||
$store_id = SystemStoreStaff::where('phone',$info['mobile'])->value('store_id');
|
||||
if(empty($store_id)){
|
||||
throw new \Exception('该用户未绑定店铺请查看');
|
||||
}
|
||||
|
||||
//先查商品相似
|
||||
$query = StoreOrderCartInfo::alias('o')
|
||||
->leftJoin('store_branch_product p','p.id = o.product_id')
|
||||
->leftJoin('store_order s','s.id = o.oid')
|
||||
->field('o.oid,p.store_name,s.order_id')
|
||||
->where('o.store_id',$store_id);
|
||||
|
||||
if(isset($params['name']) && $params['name']){
|
||||
if($params['name'] && preg_match('/[\x{4e00}-\x{9fff}]+/u', $params['name'])==1){
|
||||
$query->where('p.store_name','like','%'.$params['name'].'%');
|
||||
}else{
|
||||
$query->where('s.order_id',$params['name']);
|
||||
}
|
||||
|
||||
}
|
||||
$product = $query->select();
|
||||
if(empty($product)){
|
||||
return [
|
||||
'list'=>[],
|
||||
'count'=>0
|
||||
];
|
||||
}
|
||||
$oids = array_column($product->toArray(), 'oid');
|
||||
$uniqueOids = array_unique($oids);
|
||||
$query = StoreOrder::with(['store'])
|
||||
->whereIn('id',$uniqueOids)
|
||||
->where('status',$status);
|
||||
$count = $query->count();
|
||||
$list = $query
|
||||
->page($params['page_no'], $params['page_size'])
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
->each(function($item){
|
||||
$item['goods_list']=StoreOrderCartInfo::where('oid',$item['id'])->with('goodsName')->field('product_id,cart_num,verify_code,is_writeoff,writeoff_time')->limit(3)->select();
|
||||
$item['goods_count']=count(explode(',',$item['cart_id']));
|
||||
})
|
||||
->toArray();
|
||||
return [
|
||||
'list'=>$list,
|
||||
'count'=>$count
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,14 @@ class OrderEnum
|
||||
*/
|
||||
const IS_OK = 1;
|
||||
|
||||
/**
|
||||
* 回调订单相关
|
||||
* @PAY 支付
|
||||
* @IBACK 退款
|
||||
*/
|
||||
const PAY = 1;
|
||||
const BACK = 0;
|
||||
|
||||
/**
|
||||
* 账户类型
|
||||
* @USER 用户
|
||||
|
@ -4,9 +4,11 @@ namespace app\common\logic;
|
||||
|
||||
use app\common\enum\OrderEnum;
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\model\pay\PayNotify;
|
||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserRecharge;
|
||||
use app\common\service\PushService;
|
||||
use support\Log;
|
||||
use think\facade\Db;
|
||||
@ -97,7 +99,7 @@ class PayNotifyLogic extends BaseLogic
|
||||
} else {
|
||||
PushService::push('store_merchant_' . $order['id'], $order['id'], ['type' => 'store_merchant', 'msg' => '您有一笔新的订单']);
|
||||
Redis::send('push-platform-print', ['order_id' => $order['id']], 60);
|
||||
Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
|
||||
// Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
|
||||
}
|
||||
if (!empty($extra['payer']['openid']) && $order->pay_type != 9) {
|
||||
Redis::send('push-delivery', ['order_sn' => $order['order_id'], 'openid' => $extra['payer']['openid']], 5);
|
||||
@ -105,6 +107,21 @@ class PayNotifyLogic extends BaseLogic
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static function recharge($orderSn, $extra = [])
|
||||
{
|
||||
$order = UserRecharge::where('order_id', $orderSn)->findOrEmpty();
|
||||
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
|
||||
return true;
|
||||
}
|
||||
$order->price = bcdiv($extra['amount']['payer_total'], 100, 2);
|
||||
$order->paid = 1;
|
||||
$order->pay_time = time();
|
||||
$order->save();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 现金支付
|
||||
*/
|
||||
@ -179,4 +196,25 @@ class PayNotifyLogic extends BaseLogic
|
||||
$financeLogic->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 回调日志
|
||||
* @param $order
|
||||
* @param $extra
|
||||
* @return void
|
||||
*/
|
||||
public static function notifyLog($order,$extra)
|
||||
{
|
||||
$data = [
|
||||
'pay_type'=>'wechat',
|
||||
'type'=>OrderEnum::PAY,
|
||||
'amount'=>$extra['amount']['payer_total'],//分
|
||||
'order_sn'=>$order,
|
||||
'out_trade_no'=>$extra['transaction_id'],
|
||||
'attach'=>$extra['attach'],
|
||||
'create_time'=>date('Y-m-d H:i:s',time()),
|
||||
];
|
||||
PayNotify::create($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
10
app/common/model/pay/PayNotify.php
Normal file
10
app/common/model/pay/PayNotify.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\pay;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class PayNotify extends BaseModel
|
||||
{
|
||||
protected $name = 'pay_notify_log';
|
||||
}
|
@ -23,7 +23,8 @@ class StoreOrder extends BaseModel
|
||||
|
||||
public function store()
|
||||
{
|
||||
return $this->hasOne(SystemStore::class, 'id','store_id');
|
||||
return $this->hasOne(SystemStore::class, 'id','store_id')
|
||||
->bind(['store_name'=>'name', 'store_phone'=>'phone']);
|
||||
}
|
||||
|
||||
public function getPayTypeAttr($value, $data)
|
||||
|
@ -49,7 +49,7 @@ class WechatTemplate
|
||||
'data' => [
|
||||
'thing2' => ['value' => $data['data1']],
|
||||
'thing3' => ['value' => $data['data2']],
|
||||
'const4' => ['value' => $data['data3']??08302669767],
|
||||
'const4' => ['value' => $data['data3']??'08302669767'],
|
||||
]
|
||||
];
|
||||
return $this->post($template);
|
||||
|
Loading…
x
Reference in New Issue
Block a user