diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 299cbc2bb..3fbb8e1fb 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -16,6 +16,7 @@ use app\common\model\store_order\StoreOrder; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user\User; use app\common\model\user\UserAddress; +use think\facade\Db; use Webman\RedisQueue\Redis; class OrderController extends BaseApiController @@ -181,7 +182,8 @@ class OrderController extends BaseApiController if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result); } else { - Redis::send('send-code-pay', ['number' => $order['number']]); + Db::name('wechat_micropay')->insert(['order_id'=>$order['order_id'],'create_time'=>time(),'update_time'=>time()]); + Redis::send('send-code-pay',['order_id' => $order['order_id']]); return $this->success('用户支付中'); } return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]); @@ -290,7 +292,7 @@ class OrderController extends BaseApiController if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') { PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result); } else { - Redis::send('send-code-pay', ['number' => $order['number']]); + Redis::send('send-code-pay', ['order_id' => $order['order_id']]); return $this->success('用户支付中'); } return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]); diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php index d6e84dfff..e63c90afd 100644 --- a/app/api/logic/order/OrderLogic.php +++ b/app/api/logic/order/OrderLogic.php @@ -330,19 +330,30 @@ class OrderLogic extends BaseLogic try { $order = StoreOrder::create($_order); $goods_list = $orderInfo['cart_list']; + + $updateData = []; + $updateDataTwo = []; foreach ($goods_list as $k => $v) { $goods_list[$k]['oid'] = $order->id; $goods_list[$k]['uid'] = $uid; $goods_list[$k]['cart_id'] = implode(',', $cartId); $goods_list[$k]['delivery_id'] = $params['store_id']; //商家id - // $StoreBranchProduct = StoreBranchProduct::where('id', $v['branch_product_id'])->withTrashed()->find(); - // if ($StoreBranchProduct['stock'] - $v['cart_num'] <= 0) { - // Db::name('store_product_cate')->where(['cate_id' => $StoreBranchProduct['cate_id'], 'store_id' => $params['store_id']])->update(['count' => 0]); - // } + + $updateData[] = [ + 'id' => $v['branch_product_id'], + 'sales' => ['inc', $v['cart_num']], + 'stock' => ['dec', $v['cart_num']], + ]; + $updateDataTwo[] = [ + 'id' => $v['product_id'], + 'sales' => ['inc', $v['cart_num']] + ]; } (new StoreOrderCartInfo())->saveAll($goods_list); $where = ['is_pay' => 0]; Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]); + (new StoreBranchProduct())->saveAll($updateData); + (new StoreProduct())->saveAll($updateDataTwo); Db::commit(); return $order; } catch (\Exception $e) { diff --git a/process/Task.php b/process/Task.php index 789c98e80..0d5b35169 100644 --- a/process/Task.php +++ b/process/Task.php @@ -2,13 +2,16 @@ namespace process; +use app\common\logic\PayNotifyLogic; use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\user_recharge\UserRecharge; +use think\facade\Db; use Webman\RedisQueue\Redis; use Workerman\Crontab\Crontab; +use app\common\service\pay\PayService; class Task { @@ -29,7 +32,8 @@ class Task foreach ($arr as $v) { $updateData[] = [ 'id' => $v['branch_product_id'], - 'sales' => ['dec', $v['cart_num']] + 'sales' => ['dec', $v['cart_num']], + 'stock' => ['inc', $v['cart_num']], ]; $updateDataTwo[] = [ 'id' => $v['product_id'], @@ -58,5 +62,28 @@ class Task Redis::send('task-recharge-query', ['order_id' => $v]); } }); + //每10秒执行一次 + // new Crontab('*/10 * * * * *', function () { + // $select=Db::name('wechat_micropay')->limit(100)->select(); + // $pay = new PayService(); + // foreach ($select as $k=>$v) { + // $time = time(); + // if ($time - $v['create_time'] > 60){ + // Db::name('wechat_micropay')->where('id',$v['id'])->delete(); + // continue; + // } + // $order = [ + // 'out_trade_no' => $v['order_id'], + // ]; + // $res = $pay->wechat->query($order); + // if ($res['trade_state'] == 'SUCCESS' && $res['trade_state_desc'] == '支付成功') { + // if(isset($data['pay_type']) && $data['pay_type']=='recharge'){ + // PayNotifyLogic::handle('recharge', $res['out_trade_no'], $res); + // }else{ + // PayNotifyLogic::handle('wechat_common', $res['out_trade_no'], $res); + // } + // } + // } + // }); } }