From 075c61c2484a8d024657ef0371e98f3d6c000311 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 12 Jul 2023 16:43:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E7=94=A8=E8=B4=AD=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E5=90=8E=EF=BC=8C=E5=86=99=E5=85=A5=E8=B4=A2?= =?UTF-8?q?=E5=8A=A1=E8=B4=A6=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/store/order/StoreOrderInterest.php | 1 + .../store/order/StoreGroupOrderRepository.php | 5 +++ .../store/order/StoreOrderRepository.php | 27 ++++++++------ .../system/merchant/MerchantRepository.php | 31 +--------------- .../api/store/merchant/Merchant.php | 12 ++++--- app/controller/api/store/order/StoreOrder.php | 2 +- app/event.php | 3 +- .../{OrderTake.php => OrderCreate.php} | 20 +++++------ crmeb/listens/AutoFreezeMerchantListen.php | 35 ------------------- .../pay/OrderSettlePaySuccessListen.php | 12 +++---- 10 files changed, 49 insertions(+), 99 deletions(-) rename app/listener/{OrderTake.php => OrderCreate.php} (50%) delete mode 100644 crmeb/listens/AutoFreezeMerchantListen.php diff --git a/app/common/model/store/order/StoreOrderInterest.php b/app/common/model/store/order/StoreOrderInterest.php index 231e8d3e..7abcd2b7 100644 --- a/app/common/model/store/order/StoreOrderInterest.php +++ b/app/common/model/store/order/StoreOrderInterest.php @@ -9,6 +9,7 @@ class StoreOrderInterest extends BaseModel const STATUS_SETTLED = 1; //已结算 const STATUS_UNSETTLED = 0; //未结算 + const STATUS_DELETED = 1; //已删除 public static function tablePk(): ?string { diff --git a/app/common/repositories/store/order/StoreGroupOrderRepository.php b/app/common/repositories/store/order/StoreGroupOrderRepository.php index 39121df4..e411afa0 100644 --- a/app/common/repositories/store/order/StoreGroupOrderRepository.php +++ b/app/common/repositories/store/order/StoreGroupOrderRepository.php @@ -17,6 +17,7 @@ namespace app\common\repositories\store\order; use app\common\dao\store\order\StoreGroupOrderDao; use app\common\model\store\order\StoreGroupOrder; use app\common\model\store\order\StoreOrder; +use app\common\model\store\order\StoreOrderInterest; use app\common\repositories\BaseRepository; use app\common\repositories\store\coupon\StoreCouponRepository; use app\common\repositories\store\coupon\StoreCouponUserRepository; @@ -208,6 +209,10 @@ class StoreGroupOrderRepository extends BaseRepository 'user_type' => $storeOrderStatusRepository::U_TYPE_SYSTEM, ]; } + if (!empty($order->interest) && $order->interest->status == StoreOrderInterest::STATUS_UNSETTLED) { + $order->interest->status = StoreOrderInterest::STATUS_DELETED; + $order->interest->save(); + } $groupOrder->save(); $storeOrderStatusRepository->batchCreateLog($orderStatus); }); diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index db518890..2219475f 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -731,6 +731,10 @@ class StoreOrderRepository extends BaseRepository if ($order->pay_type != StoreGroupOrder::PAY_TYPE_CREDIT_BUY) { app()->make(MerchantRepository::class)->computedLockMoney($order); } + if (!empty($order->interest) && $order->interest->status == StoreOrderInterest::STATUS_UNSETTLED) { + $order->interest->start_time = date('Y-m-d H:i:s', strtotime("+{$order['merchant']['settle_cycle']} days")); + $order->interest->save(); + } $order->save(); }); } @@ -2477,10 +2481,7 @@ class StoreOrderRepository extends BaseRepository } $groupOrder->interest->interest = $interest; if ($result === true) { - app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->orderList[0]); - $groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED; - $groupOrder->interest->settle_time = date('Y-m-d H:i:s'); - + //写入用户账单 /** @var UserBillRepository $userBillRepository */ $userBillRepository = app()->make(UserBillRepository::class); $userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [ @@ -2491,12 +2492,14 @@ 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); - } + + /** @var StoreOrderRepository $storeOrderRepo */ + $storeOrderRepo = app()->make(StoreOrderRepository::class); + $storeOrderRepo->paySuccess($groupOrder); + app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->orderList[0]); + $groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED; + $groupOrder->interest->settle_time = date('Y-m-d H:i:s'); + //订单结算之后,修改订单支付方式为真实的支付方式 $groupOrder->pay_type = $type; $groupOrder->save(); @@ -2536,6 +2539,10 @@ class StoreOrderRepository extends BaseRepository if ($type == 2) { $order->is_del = 1; $groupOrder->is_del = 1; + if (!empty($order->interest) && $order->interest->status == StoreOrderInterest::STATUS_UNSETTLED) { + $order->interest->status = StoreOrderInterest::STATUS_DELETED; + $order->interest->save(); + } } else { $order->status = StoreOrder::STATUS_WAIT_PAY; $groupOrder->paid = 1; diff --git a/app/common/repositories/system/merchant/MerchantRepository.php b/app/common/repositories/system/merchant/MerchantRepository.php index 870c1cd0..baefe349 100644 --- a/app/common/repositories/system/merchant/MerchantRepository.php +++ b/app/common/repositories/system/merchant/MerchantRepository.php @@ -18,6 +18,7 @@ use app\common\dao\system\merchant\MerchantDao; use app\common\dao\system\serve\ServeOrderDao; use app\common\model\store\order\StoreGroupOrder; use app\common\model\store\order\StoreOrder; +use app\common\model\store\order\StoreOrderInterest; use app\common\model\store\product\ProductReply; use app\common\model\store\service\StoreService; use app\common\model\system\merchant\Merchant; @@ -743,34 +744,4 @@ 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 e7d556f3..9fb63d5d 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -12,6 +12,7 @@ namespace app\controller\api\store\merchant; +use app\common\model\store\order\StoreOrderInterest; use app\common\repositories\store\MerchantTakeRepository; use app\common\repositories\store\product\ProductRepository; use app\common\repositories\system\config\ConfigValueRepository; @@ -283,7 +284,7 @@ class Merchant extends BaseController { $data = $this->request->param(['extract_money','financial_type', 'financial_bank_name', 'financial_bank_bank', 'financial_bank_code', 'financial_bank_branch']); $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('reg_admin_id,uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type,is_frozen')->find(); - if (!$msg = $this->checkAuth($merchant)) { + if (($msg = $this->checkAuth($merchant)) !== true) { return app('json')->fail($msg); } $bankInfo = [ @@ -302,7 +303,7 @@ class Merchant extends BaseController public function listApply($merId) { $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('reg_admin_id,uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type,is_frozen')->find(); - if (!$msg = $this->checkAuth($merchant)) { + if (($msg = $this->checkAuth($merchant)) !== true) { return app('json')->fail($msg); } [$page, $limit] = $this->getPage(); @@ -315,7 +316,7 @@ class Merchant extends BaseController public function account($merId) { $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type,is_frozen')->find(); - if (!$msg = $this->checkAuth($merchant)) { + if (($msg = $this->checkAuth($merchant)) !== true) { return app('json')->fail($msg); } $data = [ @@ -332,7 +333,7 @@ class Merchant extends BaseController $data = $this->request->param(['name','bank','bank_code','financial_type']); app()->make(MerchantFinancialAccountValidate::class)->check($data); $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type,is_frozen')->find(); - if (!$msg = $this->checkAuth($merchant)) { + if (($msg = $this->checkAuth($merchant)) !== true) { return app('json')->fail($msg); } $update = [ @@ -349,7 +350,8 @@ class Merchant extends BaseController if ($this->userInfo['uid'] != $merchant->uid) { return '你不是管理员无法进行提现操作'; } - if ($merchant->is_frozen){ + $unSettleCount = StoreOrderInterest::where('mer_id', $merchant->mer_id)->where('status', StoreOrderInterest::STATUS_UNSETTLED)->count(); + if ($unSettleCount > 0) { return '有未结清的订单,请结清订单后再进行提现'; } return true; diff --git a/app/controller/api/store/order/StoreOrder.php b/app/controller/api/store/order/StoreOrder.php index 22e14b0c..6c8a6851 100644 --- a/app/controller/api/store/order/StoreOrder.php +++ b/app/controller/api/store/order/StoreOrder.php @@ -244,7 +244,7 @@ class StoreOrder extends BaseController 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) { + if ($groupOrder['pay_price'] == 0) { $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 a571f362..67765853 100644 --- a/app/event.php +++ b/app/event.php @@ -55,7 +55,6 @@ return [ \crmeb\listens\AuthCancelActivityListen::class, \crmeb\listens\CloseUserSvipListen::class, \crmeb\listens\SendSvipCouponListen::class, - \crmeb\listens\AutoFreezeMerchantListen::class, \crmeb\listens\AutoCheckCreditBuyListen::class, ] : [], 'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class], @@ -70,7 +69,7 @@ return [ 'product.create'=>[\app\listener\ProductCreate::class], 'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架 'refund.after'=>[\app\listener\AfterRefund::class], - 'order.take'=>[\app\listener\OrderTake::class], + 'order.create'=>[\app\listener\OrderCreate::class], ], 'subscribe' => [], diff --git a/app/listener/OrderTake.php b/app/listener/OrderCreate.php similarity index 50% rename from app/listener/OrderTake.php rename to app/listener/OrderCreate.php index 73da22b5..4900896b 100644 --- a/app/listener/OrderTake.php +++ b/app/listener/OrderCreate.php @@ -8,25 +8,25 @@ use app\common\model\system\merchant\Merchant; use app\common\repositories\store\order\StoreOrderInterestRepository; /** - * 订单确认收货后置事件 + * 下单后置事件 */ -class OrderTake +class OrderCreate { public function handle($event) { - $order = $event['order']; + $groupOrder = $event['groupOrder']; + $order = $groupOrder->orderList[0]; /** @var StoreOrderInterestRepository $storeOrderInterestRepository */ $storeOrderInterestRepository = app()->make(StoreOrderInterestRepository::class); - $merchantId = Merchant::where('uid', $order['uid'])->value('mer_id'); + $merchantId = Merchant::where('uid', $groupOrder['uid'])->value('mer_id'); $data = [ - 'group_order_id' => $order['group_order_id'], - 'order_id' => $order['order_id'], + 'group_order_id' => $groupOrder['group_order_id'], + 'order_id' => $order['order_id'] ?? 0, 'mer_id' => $merchantId, - 'to_mer_id' => $order['mer_id'], - 'total_price' => $order['total_price'], - 'rate' => $order['merchant']['interest_rate'], - 'start_time' => date('Y-m-d H:i:s', strtotime("+{$order['merchant']['settle_cycle']} days")), + 'to_mer_id' => $order['mer_id'] ?? 0, + 'total_price' => $groupOrder['total_price'], + 'rate' => $order['merchant']['interest_rate'] ?? 0, ]; return $storeOrderInterestRepository->create($data); } diff --git a/crmeb/listens/AutoFreezeMerchantListen.php b/crmeb/listens/AutoFreezeMerchantListen.php deleted file mode 100644 index c7b77054..00000000 --- a/crmeb/listens/AutoFreezeMerchantListen.php +++ /dev/null @@ -1,35 +0,0 @@ - -// +---------------------------------------------------------------------- - - -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 AutoFreezeMerchantListen 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/crmeb/listens/pay/OrderSettlePaySuccessListen.php b/crmeb/listens/pay/OrderSettlePaySuccessListen.php index efa77c95..75d8d604 100644 --- a/crmeb/listens/pay/OrderSettlePaySuccessListen.php +++ b/crmeb/listens/pay/OrderSettlePaySuccessListen.php @@ -16,6 +16,7 @@ namespace crmeb\listens\pay; use app\common\model\store\order\StoreOrderInterest; use app\common\repositories\store\order\StoreGroupOrderRepository; +use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\system\merchant\MerchantRepository; use crmeb\interfaces\ListenerInterface; use crmeb\utils\DingTalk; @@ -34,18 +35,17 @@ class OrderSettlePaySuccessListen implements ListenerInterface if (!$groupOrder || !$groupOrder->interest || $groupOrder->interest->status == StoreOrderInterest::STATUS_SETTLED) { throw new \Exception('订单无需结算'); } + + /** @var StoreOrderRepository $storeOrderRepo */ + $storeOrderRepo = app()->make(StoreOrderRepository::class); + $storeOrderRepo->paySuccess($groupOrder); + app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->order); $groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED; $groupOrder->interest->settle_time = date('Y-m-d H:i:s'); if (!$groupOrder->interest->save()) { throw new \Exception('订单结算信息保存失败'); } - $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); - } //订单结算之后,修改订单支付方式为真实的支付方式 $groupOrder->pay_type = 1; $groupOrder->save();