commit
5b31405686
@ -16,6 +16,7 @@ use app\common\model\store_order\StoreOrder;
|
|||||||
use app\common\model\system_store\SystemStoreStaff;
|
use app\common\model\system_store\SystemStoreStaff;
|
||||||
use app\common\model\user\User;
|
use app\common\model\user\User;
|
||||||
use app\common\model\user\UserAddress;
|
use app\common\model\user\UserAddress;
|
||||||
|
use think\facade\Db;
|
||||||
use Webman\RedisQueue\Redis;
|
use Webman\RedisQueue\Redis;
|
||||||
|
|
||||||
class OrderController extends BaseApiController
|
class OrderController extends BaseApiController
|
||||||
@ -181,7 +182,8 @@ class OrderController extends BaseApiController
|
|||||||
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
||||||
PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result);
|
PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result);
|
||||||
} else {
|
} 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('用户支付中');
|
||||||
}
|
}
|
||||||
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
|
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'] == '支付成功') {
|
if (isset($result['trade_state_desc']) && $result['trade_state_desc'] == '支付成功') {
|
||||||
PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result);
|
PayNotifyLogic::handle('StoreOrder', $result['out_trade_no'], $result);
|
||||||
} else {
|
} 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('用户支付中');
|
||||||
}
|
}
|
||||||
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
|
return $this->success('支付成功', ['out_trade_no' => $result['out_trade_no'], 'pay_type' => PayEnum::WECHAT_PAY_BARCODE, 'transaction_id' => $result['transaction_id']]);
|
||||||
|
@ -330,19 +330,30 @@ class OrderLogic extends BaseLogic
|
|||||||
try {
|
try {
|
||||||
$order = StoreOrder::create($_order);
|
$order = StoreOrder::create($_order);
|
||||||
$goods_list = $orderInfo['cart_list'];
|
$goods_list = $orderInfo['cart_list'];
|
||||||
|
|
||||||
|
$updateData = [];
|
||||||
|
$updateDataTwo = [];
|
||||||
foreach ($goods_list as $k => $v) {
|
foreach ($goods_list as $k => $v) {
|
||||||
$goods_list[$k]['oid'] = $order->id;
|
$goods_list[$k]['oid'] = $order->id;
|
||||||
$goods_list[$k]['uid'] = $uid;
|
$goods_list[$k]['uid'] = $uid;
|
||||||
$goods_list[$k]['cart_id'] = implode(',', $cartId);
|
$goods_list[$k]['cart_id'] = implode(',', $cartId);
|
||||||
$goods_list[$k]['delivery_id'] = $params['store_id']; //商家id
|
$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) {
|
$updateData[] = [
|
||||||
// Db::name('store_product_cate')->where(['cate_id' => $StoreBranchProduct['cate_id'], 'store_id' => $params['store_id']])->update(['count' => 0]);
|
'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);
|
(new StoreOrderCartInfo())->saveAll($goods_list);
|
||||||
$where = ['is_pay' => 0];
|
$where = ['is_pay' => 0];
|
||||||
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
Cart::whereIn('id', $cartId)->where($where)->update(['is_pay' => 1]);
|
||||||
|
(new StoreBranchProduct())->saveAll($updateData);
|
||||||
|
(new StoreProduct())->saveAll($updateDataTwo);
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return $order;
|
return $order;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -2,13 +2,16 @@
|
|||||||
|
|
||||||
namespace process;
|
namespace process;
|
||||||
|
|
||||||
|
use app\common\logic\PayNotifyLogic;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
use app\common\model\store_order_cart_info\StoreOrderCartInfo;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\user_recharge\UserRecharge;
|
use app\common\model\user_recharge\UserRecharge;
|
||||||
|
use think\facade\Db;
|
||||||
use Webman\RedisQueue\Redis;
|
use Webman\RedisQueue\Redis;
|
||||||
use Workerman\Crontab\Crontab;
|
use Workerman\Crontab\Crontab;
|
||||||
|
use app\common\service\pay\PayService;
|
||||||
|
|
||||||
class Task
|
class Task
|
||||||
{
|
{
|
||||||
@ -29,7 +32,8 @@ class Task
|
|||||||
foreach ($arr as $v) {
|
foreach ($arr as $v) {
|
||||||
$updateData[] = [
|
$updateData[] = [
|
||||||
'id' => $v['branch_product_id'],
|
'id' => $v['branch_product_id'],
|
||||||
'sales' => ['dec', $v['cart_num']]
|
'sales' => ['dec', $v['cart_num']],
|
||||||
|
'stock' => ['inc', $v['cart_num']],
|
||||||
];
|
];
|
||||||
$updateDataTwo[] = [
|
$updateDataTwo[] = [
|
||||||
'id' => $v['product_id'],
|
'id' => $v['product_id'],
|
||||||
@ -58,5 +62,28 @@ class Task
|
|||||||
Redis::send('task-recharge-query', ['order_id' => $v]);
|
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);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user