diff --git a/app/common/model/store/order/StoreOrder.php b/app/common/model/store/order/StoreOrder.php index 9a4ebdd2..c57dd5b3 100644 --- a/app/common/model/store/order/StoreOrder.php +++ b/app/common/model/store/order/StoreOrder.php @@ -186,4 +186,9 @@ class StoreOrder extends BaseModel return $this->hasOne(StoreOrderInterest::class, 'order_id', 'order_id'); } + public function allowCreditPay() + { + return $this->pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && $this->status == self::STATUS_WAIT_PAY; + } + } diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index c88f9c65..fad9f4e3 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -2486,6 +2486,12 @@ class StoreOrderRepository extends BaseRepository 'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品', 'balance' => $user->now_money ]); + $unSettleCount = StoreOrderInterest::where('mer_id', $groupOrder->interest->mer_id)->where('status', 0)->count(); + if ($unSettleCount === 0) { + /** @var MerchantRepository $merchantRepo */ + $merchantRepo = app()->make(MerchantRepository::class); + $merchantRepo->unfreeze($groupOrder->interest->mer_id); + } } Db::commit(); return $data; diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 3b2b27ac..b9869c7e 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -743,5 +743,34 @@ class MerchantRepository extends BaseRepository return [$income, $finance, true]; } + /** + * 冻结商户提现 + * @param $merchantId + * @return void + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function freeze($merchantId) + { + $merchant = $this->get($merchantId); + $merchant->is_fronze = 1; + $merchant->save(); + } + + /** + * 解冻商户提现 + * @param $merchantId + * @return void + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function unfreeze($merchantId) + { + $merchant = $this->get($merchantId); + $merchant->is_fronze = 0; + $merchant->save(); + } } diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 81e7a929..cbd1f7bf 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -283,6 +283,9 @@ class Merchant extends BaseController if ($this->userInfo['uid'] != $merchant->uid){ return app('json')->fail('你不是管理员无法进行提现操作'); } + if ($merchant->is_frozen){ + return app('json')->fail('账户被冻结,无法进行提现操作'); + } $bankInfo = [ 'name' => $data['financial_bank_name'], 'bank' => $data['financial_bank_bank'], diff --git a/app/controller/api/store/order/StoreOrder.php b/app/controller/api/store/order/StoreOrder.php index c6e8529c..09047bf5 100644 --- a/app/controller/api/store/order/StoreOrder.php +++ b/app/controller/api/store/order/StoreOrder.php @@ -240,6 +240,9 @@ class StoreOrder extends BaseController if (!$groupOrder) return app('json')->fail('订单不存在或已支付'); $this->repository->changePayType($groupOrder, array_search($type, StoreOrderRepository::PAY_TYPE)); + if ($groupOrder['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && !$groupOrder->orderList[0]->allowCreditPay()) { + return app('json')->fail('请等待商家确认订单'); + } if ($groupOrder['pay_price'] == 0 || $groupOrder['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) { $this->repository->paySuccess($groupOrder); return app('json')->status('success', '支付成功', ['order_id' => $groupOrder['group_order_id']]); diff --git a/app/event.php b/app/event.php index 089e8908..cc18c4ad 100644 --- a/app/event.php +++ b/app/event.php @@ -55,6 +55,7 @@ return [ \crmeb\listens\AuthCancelActivityListen::class, \crmeb\listens\CloseUserSvipListen::class, \crmeb\listens\SendSvipCouponListen::class, + \crmeb\listens\AutoUnfreezeMerchantListen::class, ] : [], 'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class], 'pay_success_user_order' => [\crmeb\listens\pay\UserOrderSuccessListen::class], diff --git a/app/listener/OrderTake.php b/app/listener/OrderTake.php index 859e6c3b..96a81048 100644 --- a/app/listener/OrderTake.php +++ b/app/listener/OrderTake.php @@ -23,6 +23,7 @@ class OrderTake $storeOrderInterestRepository = app()->make(StoreOrderInterestRepository::class); $merchantId = Merchant::where('uid', $order['uid'])->value('mer_id'); $data = [ + 'group_order_id' => $order['group_order_id'], 'order_id' => $order['order_id'], 'mer_id' => $merchantId, 'to_mer_id' => $order['mer_id'], diff --git a/crmeb/listens/AutoUnfreezeMerchantListen.php b/crmeb/listens/AutoUnfreezeMerchantListen.php new file mode 100644 index 00000000..ad91d8b0 --- /dev/null +++ b/crmeb/listens/AutoUnfreezeMerchantListen.php @@ -0,0 +1,35 @@ + +// +---------------------------------------------------------------------- + + +namespace crmeb\listens; + + +use app\common\model\store\order\StoreOrderInterest; +use app\common\repositories\system\merchant\MerchantRepository; +use crmeb\interfaces\ListenerInterface; +use crmeb\services\TimerService; + +class AutoUnfreezeMerchantListen extends TimerService implements ListenerInterface +{ + public function handle($event): void + { + $this->tick(1000 * 60, function () { + request()->clearCache(); + $unSettle = StoreOrderInterest::whereTime('start_time', '<=', time())->where('status', 0)->group('mer_id')->column('mer_id'); + /** @var MerchantRepository $merchantRepo */ + $merchantRepo = app()->make(MerchantRepository::class); + foreach ($unSettle as $merId) { + $merchantRepo->freeze($merId); + } + }); + } +} diff --git a/route/api.php b/route/api.php index 72ba6e29..9dbb2448 100644 --- a/route/api.php +++ b/route/api.php @@ -91,6 +91,7 @@ Route::group('api/', function () { Route::post('receipt/:id', '/createReceipt'); Route::get('delivery/:id', '/getOrderDelivery'); Route::post('settle', '/settle'); + Route::post('confirm', '/confirm'); })->prefix('api.store.order.StoreOrder'); // 预售