From 4cf5366fdcb6cdaf8dc241c17caf95b34c09a5b0 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 3 Jan 2024 14:36:27 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 26 ++++++++++++++ .../order/StoreOtherOrderCreateRepository.php | 3 ++ .../store/order/StoreOtherOrderRepository.php | 35 ++++++++----------- .../api/store/order/StoreOrderOther.php | 13 +++++++ crmeb/services/SmsService.php | 13 +++++++ 5 files changed, 70 insertions(+), 20 deletions(-) diff --git a/app/common.php b/app/common.php index cc258ef0..e324f660 100644 --- a/app/common.php +++ b/app/common.php @@ -13,9 +13,12 @@ use app\common\repositories\system\config\ConfigValueRepository; use app\common\repositories\system\groupData\GroupDataRepository; +use crmeb\jobs\SendSmsJob; use crmeb\services\UploadService; use Swoole\Lock; use think\db\BaseQuery; +use think\facade\Db; +use think\facade\Queue; if (!function_exists('go')) { function go(): bool @@ -1152,5 +1155,28 @@ if (!function_exists('checkSuffix')) { } } +if (!function_exists('Financial_Operations')) { + + function Financial_Operations($activity_type,$order_id,$tempId='ORDER_CREATE',$id=0){ + //发送运营财务短信 + $group_id=0; + if($activity_type==98){ + $group_id=Db::name('system_group')->where('group_key','city_operations')->value('group_id'); + }else{ + $group_id=Db::name('system_group')->where('group_key','town_operation')->value('group_id'); + } + if($group_id){ + $group_value=Db::name('system_group_data')->where('group_id',$group_id)->column('value'); + if($group_value){ + foreach($group_value as $k=>$v){ + $phone=json_decode($v,true); + Queue::push(SendSmsJob::class, ['tempId' => $tempId, 'phone' => $phone['phone'],'orderId'=>$order_id,'id'=>$id]);//短信通知 + } + } + + } + } +} + diff --git a/app/common/repositories/store/order/StoreOtherOrderCreateRepository.php b/app/common/repositories/store/order/StoreOtherOrderCreateRepository.php index ca8eda07..ee7f93d1 100644 --- a/app/common/repositories/store/order/StoreOtherOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOtherOrderCreateRepository.php @@ -722,6 +722,9 @@ class StoreOtherOrderCreateRepository extends StoreOtherOrderRepository Db::name('store_order_product_other')->insertAll($orderProduct); return $groupOrder; }); + + //下单发送运营财务短信 + Financial_Operations(98,$groupOrder['group_order_sn'],'ORDER_CREATE'); return $group; } } diff --git a/app/common/repositories/store/order/StoreOtherOrderRepository.php b/app/common/repositories/store/order/StoreOtherOrderRepository.php index a7d4ce4b..214891b5 100644 --- a/app/common/repositories/store/order/StoreOtherOrderRepository.php +++ b/app/common/repositories/store/order/StoreOtherOrderRepository.php @@ -298,6 +298,12 @@ class StoreOtherOrderRepository extends BaseRepository // if (!$is_combine) { // app()->make(MerchantRepository::class)->addLockMoney($order->mer_id, 'order', $order->order_id, $_payPrice); // } + //短信 订单通知商户 + $mer_phone=Db::name('merchant')->where('mer_id',$order->mer_id)->value('mer_phone'); + if($mer_phone){ + Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'phone' => $mer_phone,'orderId'=>$order->order_id,'id'=>0]);//短信通知 + } + } $userMerchantRepository->updatePayTime($uid, $order->mer_id, $order->pay_price); SwooleTaskService::merchant('notice', [ @@ -309,22 +315,6 @@ class StoreOtherOrderRepository extends BaseRepository ] ], $order->mer_id); - $group_id=0; - if($order->activity_type==98){ - $group_id=Db::name('system_group')->where('group_key','city_operations')->value('group_id'); - }else{ - $group_id=Db::name('system_group')->where('group_key','town_operation')->value('group_id'); - } - if($group_id){ - $group_value=Db::name('system_group_data')->where('group_id',$group_id)->column('value'); - if($group_value){ - foreach($group_value as $k=>$v){ - $phone=json_decode($v,true); - Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'phone' => $phone['phone'],'orderId'=>$order->order_id,'id'=>0]);//短信通知 - } - } - - } } $this->giveIntegral($groupOrder); @@ -332,6 +322,7 @@ class StoreOtherOrderRepository extends BaseRepository $storeOrderStatusRepository->batchCreateLog($orderStatus); $groupOrder->save(); Db::commit(); + return true; } catch (\Exception $e) { Log::error('财务点击支付失败'.$e->getMessage()); @@ -615,6 +606,8 @@ class StoreOtherOrderRepository extends BaseRepository $this->takeAfter($order, $user); $order->save(); $storeOrderStatusRepository->{$func}($orderStatus); + Financial_Operations(98,$order->order_id,'OTHER_ADMIN_TAKE_DELIVERY_CODE',$order->order_id); + }); // event('order.take', compact('order')); } @@ -1256,9 +1249,6 @@ class StoreOtherOrderRepository extends BaseRepository $query = $this->dao->search($where, null)->where($this->getOrderType($status)) ->with([ 'orderProduct', - 'merchant' => function ($query) { - return $query->field('mer_id,mer_name,is_trader,financial_bank,auto_margin_rate,commission_rate'); - }, 'verifyService' => function ($query) { return $query->field('service_id,nickname'); }, @@ -1278,7 +1268,7 @@ class StoreOtherOrderRepository extends BaseRepository }, ]); $count = $query->count(); - $list = $query->page($page, $limit)->select()->each(function ($item) { + $list = $query->page($page, $limit)->select()->each(function ($item) use($status){ $auto_margin= Db::name('financial_record_transfer') ->where('order_id',$item['order_id'])->where('financial_type','auto_margin')->where('financial_pm',0)->value('number'); $order_charge= Db::name('financial_record_transfer') @@ -1289,6 +1279,11 @@ class StoreOtherOrderRepository extends BaseRepository 'order_charge'=>$order_charge, 'order_charge_lv'=>$item->merchant->commission_rate?round($item->merchant->commission_rate,2):0, ]; + if(in_array($status,[4,5])){ + $item['merchant']= Db::name('merchant')->where('mer_id',$item['mer_id'])->field('mer_id,mer_name,is_trader,financial_bank,auto_margin_rate,commission_rate')->find(); + }else{ + $item['merchant']= Db::name('merchant')->where('uid',$item['uid'])->where('status',1)->field('mer_id,mer_name,is_trader,financial_bank,auto_margin_rate,commission_rate')->find(); + } }); return compact('count', 'list'); } diff --git a/app/controller/api/store/order/StoreOrderOther.php b/app/controller/api/store/order/StoreOrderOther.php index ab879fdc..d0ebd7f3 100644 --- a/app/controller/api/store/order/StoreOrderOther.php +++ b/app/controller/api/store/order/StoreOrderOther.php @@ -288,4 +288,17 @@ class StoreOrderOther extends BaseController $res = $orderRepository->show($id, $this->request->uid()); return app('json')->success($res); } + + /** + * 上传凭证 + */ + public function upload_voucher($order_id){ + $find=Db::name('store_order_other')->where('order_id',$order_id)->where('uid', $this->request->uid())->find(); + if($find){ + Financial_Operations(98,$order_id,'ADMIN_PAY_SUCCESS_CODE'); + return app('json')->success('操作成功'); + } + return app('json')->fail('操作失败'); + + } } diff --git a/crmeb/services/SmsService.php b/crmeb/services/SmsService.php index edd26381..1d47f918 100644 --- a/crmeb/services/SmsService.php +++ b/crmeb/services/SmsService.php @@ -12,8 +12,10 @@ namespace crmeb\services; use app\common\repositories\store\broadcast\BroadcastRoomRepository; +use app\common\repositories\store\order\StoreGroupOrderOtherRepository; use app\common\repositories\store\order\StoreGroupOrderRepository; use app\common\repositories\store\order\StoreOrderRepository; +use app\common\repositories\store\order\StoreOtherOrderRepository; use app\common\repositories\store\order\StoreRefundOrderRepository; use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\product\ProductTakeRepository; @@ -285,9 +287,20 @@ class SmsService case 'MERCHANT_CREDIT_BUY_NOTICE': self::sendMerMessage($id, $tempId, ['order_id' => $data['orderId']]); break; + //下单通知 case 'ORDER_CREATE': self::create()->send($data['phone'], $tempId, ['name' => $data['orderId']]); break; + //管理员确认收货提醒 + case 'OTHER_ADMIN_TAKE_DELIVERY_CODE': + $order = app()->make(StoreOtherOrderRepository::class)->get($id); + if (!$order) return; + self::sendMerMessage($order->mer_id, 'ADMIN_TAKE_DELIVERY_CODE', ['order_id' => $order->order_sn]); + break; + //管理员 支付成功提醒 + case 'OTHER_ADMIN_PAY_SUCCESS_CODE': + self::create()->send($data['phone'], 'ADMIN_PAY_SUCCESS_CODE', ['order_id' => $data['orderId']]); + break; } } From d8a60832479ad16c45e685a997b959762f8c4442 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 3 Jan 2024 15:02:44 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/order/StoreOtherOrderRepository.php | 2 +- app/event.php | 1 + app/listener/paySuccessOrderOther.php | 137 ++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 app/listener/paySuccessOrderOther.php diff --git a/app/common/repositories/store/order/StoreOtherOrderRepository.php b/app/common/repositories/store/order/StoreOtherOrderRepository.php index 214891b5..355c6a7b 100644 --- a/app/common/repositories/store/order/StoreOtherOrderRepository.php +++ b/app/common/repositories/store/order/StoreOtherOrderRepository.php @@ -240,7 +240,7 @@ class StoreOtherOrderRepository extends BaseRepository $_payPrice = bcsub($_payPrice, $_order_rate, 2); // 结算各镇 小组佣金 - event('order.paySuccessOrder', compact('order', '_order_rate')); + event('order.paySuccessOrderOther', compact('order', '_order_rate')); } if (!$presell) { diff --git a/app/event.php b/app/event.php index 30312949..039bcf71 100644 --- a/app/event.php +++ b/app/event.php @@ -66,6 +66,7 @@ return [ 'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class], // 'community_address'=>[\app\listener\CommunityAddress::class], 'order.paySuccessOrder'=>[\app\listener\paySuccessOrder::class], + 'order.paySuccessOrderOther'=>[\app\listener\paySuccessOrderOther::class], 'order.paySuccess'=>[\app\listener\paySuccess::class], 'pay_success_margin'=>[\app\listener\paySuccessMargin::class], 'order.sendGoodsCode'=>[\app\listener\SendGoodsCode::class], diff --git a/app/listener/paySuccessOrderOther.php b/app/listener/paySuccessOrderOther.php new file mode 100644 index 00000000..cf1539c0 --- /dev/null +++ b/app/listener/paySuccessOrderOther.php @@ -0,0 +1,137 @@ +event = $event; + $this->finance = []; + $this->index = 1; + Db::startTrans(); + try { + $financialRecordRepository = app()->make(FinancialRecordRepository::class); + $this->financeSn = $financialRecordRepository->getSn(); + $merchant = Merchant::find($event['order']['mer_id']); + + if (!$merchant || $merchant['street_id'] == 0) { + throw new \Exception('商户地址不存在', 200); + } + $this->streetId = $merchant['street_id']; + + $commission_rate = ($event['order']['commission_rate'] / 100); + //该笔订单平台总手续费 + $realPrice = bcsub((string)$event['order']['total_price'], (string)$event['order']['extension_one'], 2); + $realPrice = bcsub($realPrice, (string)$event['order']['extension_two'], 2); + $this->totalAmount = bcmul($realPrice, (string)$commission_rate, 2); + $this->remain = $this->totalAmount; + + // $typeTownServerId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeTownServer'])->value('mer_type_id'); + // $typeVillageServerId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeVillageServer'])->value('mer_type_id'); + // $typeTeamServerId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeTeamServer'])->value('mer_type_id'); + + // //镇团队佣金 + // $this->calculate($typeTownServerId, 'commission_to_town_rate'); + // //村团队佣金 + // $this->calculate($typeVillageServerId, 'commission_to_village_rate'); + // //小组服务团队佣金 + // $this->calculate($typeTeamServerId, 'commission_to_service_team_rate'); + + if ($this->remain > 0) { + //平台佣金 + $this->finance[] = [ + 'order_id' => $this->event['order']['order_id'], + 'order_sn' => $this->event['order']['order_sn'], + 'user_info' => $this->event['order']->user->nickname, + 'user_id' => $this->event['order']['uid'], + 'financial_type' => 'commission_to_platform', + 'financial_pm' => 1, + 'type' => 1, + 'number' => $this->remain, + 'mer_id' => 0, + 'financial_record_sn' => $this->financeSn . $this->index + ]; + } + + if ($financialRecordRepository->insertAll($this->finance) === false) { + throw new \Exception('财务流水保存出错'); + } + Db::commit(); + } catch (\Exception $e) { + if ($e->getCode() == 200) { + Db::commit(); + } else { + Db::rollback(); + } + Log::error('订单分润出错', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); + DingTalk::exception($e, '订单分润出错'); + } + } + + public function calculate($type, $field) + { + $merId = Db::name('merchant')->where('type_id', $type) + ->where('street_id', $this->streetId) + ->where('status', 1) + ->where('mer_state', 1) + ->value('mer_id'); + $rate = systemConfig($field); + $typeName = Merchant::TypeMap[$type]; + if (empty($merId) || $rate <= 0) { + Log::info("订单分佣:没有 $typeName 或比例为0"); + return false; + } + $financialTypeMap = [ + 'commission_to_town_rate' => 'town', + 'commission_to_village_rate' => 'village', + 'commission_to_service_team_rate' => 'service_team', + 'commission_to_cloud_rate' => 'cloud_warehouse', + ]; + $amount = bcmul($this->totalAmount, (string)($rate / 100), 2); + if ($amount <= 0) { + Log::info("订单分佣:$typeName 佣金为0"); + return false; + } + $this->remain = bcsub($this->remain, $amount, 2); + $this->finance[] = [ + 'order_id' => $this->event['order']['order_id'], + 'order_sn' => $this->event['order']['order_sn'], + 'user_info' => $this->event['order']->user->nickname, + 'user_id' => $this->event['order']['uid'], + 'financial_type' => 'commission_to_' . $financialTypeMap[$field], + 'financial_pm' => 1, + 'type' => 1, + 'number' => $amount, + 'mer_id' => $merId, + 'financial_record_sn' => $this->financeSn . $this->index + ]; + $this->index++; + app()->make(MerchantRepository::class)->addLockMoney($merId, 'order', $this->event['order']['order_id'], (float)$amount); + return true; + } + +} \ No newline at end of file From 5357e9fa081ce4c09c96381ec9eafe892104958d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 4 Jan 2024 10:10:00 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=93=B6=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/financial/FinancialRepository.php | 77 ++++++++++--------- app/listener/paySuccessOrderOther.php | 10 +-- 2 files changed, 41 insertions(+), 46 deletions(-) diff --git a/app/common/repositories/system/financial/FinancialRepository.php b/app/common/repositories/system/financial/FinancialRepository.php index db7f41d3..4d696576 100644 --- a/app/common/repositories/system/financial/FinancialRepository.php +++ b/app/common/repositories/system/financial/FinancialRepository.php @@ -41,33 +41,34 @@ class FinancialRepository extends BaseRepository Elm::radio('financial_type', '转账类型', $merchant->financial_type) ->setOptions([ ['value' => 1, 'label' => '银行卡'], - ['value' => 2, 'label' => '微信'], - ['value' => 3, 'label' => '支付宝'], + // ['value' => 2, 'label' => '微信'], + // ['value' => 3, 'label' => '支付宝'], ])->control([ [ 'value' => 1, 'rule'=> [ - Elm::input('name', '姓名')->value($merchant->financial_bank->name??'')->required(), + Elm::input('name', '公司名称')->value($merchant->financial_bank->name??'')->required(), Elm::input('bank', '开户银行')->value($merchant->financial_bank->bank??'')->required(), - Elm::input('bank_code', '银行卡号')->value($merchant->financial_bank->bank_code??'')->required(), - ] - ], - [ - 'value' => 2, - 'rule'=> [ - Elm::input('name', '姓名')->value($merchant->financial_wechat->name??'')->required(), - Elm::input('wechat', '微信号')->value($merchant->financial_wechat->wechat??'')->required(), - Elm::frameImage('wechat_code', '收款二维码', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=wechat_code&type=1')->value($merchant->financial_wechat->wechat_code??'')->modal(['modal' => false])->width('896px')->height('480px'), - ] - ], - [ - 'value' => 3, - 'rule'=> [ - Elm::input('name', '姓名')->value($merchant->financial_alipay->name??'')->required(), - Elm::input('alipay', '支付宝账号')->value($merchant->financial_alipay->alipay??'')->required(), - Elm::frameImage('alipay_code', '收款二维码', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=alipay_code&type=1')->value($merchant->financial_alipay->alipay_code??'')->modal(['modal' => false])->width('896px')->height('480px'), + Elm::input('bank_code', '对公账号')->value($merchant->financial_bank->bank_code??'')->required(), + Elm::input('bank_branch', '开户网点')->value($merchant->financial_bank->bank_branch??'')->required(), ] ], + // [ + // 'value' => 2, + // 'rule'=> [ + // Elm::input('name', '姓名')->value($merchant->financial_wechat->name??'')->required(), + // Elm::input('wechat', '微信号')->value($merchant->financial_wechat->wechat??'')->required(), + // Elm::frameImage('wechat_code', '收款二维码', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=wechat_code&type=1')->value($merchant->financial_wechat->wechat_code??'')->modal(['modal' => false])->width('896px')->height('480px'), + // ] + // ], + // [ + // 'value' => 3, + // 'rule'=> [ + // Elm::input('name', '姓名')->value($merchant->financial_alipay->name??'')->required(), + // Elm::input('alipay', '支付宝账号')->value($merchant->financial_alipay->alipay??'')->required(), + // Elm::frameImage('alipay_code', '收款二维码', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=alipay_code&type=1')->value($merchant->financial_alipay->alipay_code??'')->modal(['modal' => false])->width('896px')->height('480px'), + // ] + // ], ]), ]); @@ -93,24 +94,24 @@ class FinancialRepository extends BaseRepository 'bank_code' => $data['bank_code'], ]; break; - case 2: - $key = 'financial_wechat' ; - $update = [ - 'name' => $data['name'], - //'idcard' => $data['idcard'], - 'wechat' => $data['wechat'], - 'wechat_code' => $data['wechat_code'], - ]; - break; - case 3: - $key = 'financial_alipay' ; - $update = [ - 'name' => $data['name'], - //'idcard' => $data['idcard'], - 'alipay' => $data['alipay'], - 'alipay_code' => $data['alipay_code'], - ]; - break; + // case 2: + // $key = 'financial_wechat' ; + // $update = [ + // 'name' => $data['name'], + // //'idcard' => $data['idcard'], + // 'wechat' => $data['wechat'], + // 'wechat_code' => $data['wechat_code'], + // ]; + // break; + // case 3: + // $key = 'financial_alipay' ; + // $update = [ + // 'name' => $data['name'], + // //'idcard' => $data['idcard'], + // 'alipay' => $data['alipay'], + // 'alipay_code' => $data['alipay_code'], + // ]; + // break; } return app()->make(MerchantRepository::class)->update($merId,[$key => json_encode($update),'financial_type' => $data['financial_type']]); } diff --git a/app/listener/paySuccessOrderOther.php b/app/listener/paySuccessOrderOther.php index cf1539c0..26e5446d 100644 --- a/app/listener/paySuccessOrderOther.php +++ b/app/listener/paySuccessOrderOther.php @@ -45,9 +45,7 @@ class paySuccessOrderOther $commission_rate = ($event['order']['commission_rate'] / 100); //该笔订单平台总手续费 - $realPrice = bcsub((string)$event['order']['total_price'], (string)$event['order']['extension_one'], 2); - $realPrice = bcsub($realPrice, (string)$event['order']['extension_two'], 2); - $this->totalAmount = bcmul($realPrice, (string)$commission_rate, 2); + $this->totalAmount = bcmul((string)$event['order']['total_price'], (string)$commission_rate, 2); $this->remain = $this->totalAmount; // $typeTownServerId = Db::name('MerchantType')->where('type_code', Merchant::TypeCode['TypeTownServer'])->value('mer_type_id'); @@ -82,11 +80,7 @@ class paySuccessOrderOther } Db::commit(); } catch (\Exception $e) { - if ($e->getCode() == 200) { - Db::commit(); - } else { - Db::rollback(); - } + Db::rollback(); Log::error('订单分润出错', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); DingTalk::exception($e, '订单分润出错'); } From 6856704551ae1bb31198bff2a465a31792a6ccd7 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 4 Jan 2024 14:04:34 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/product/CloudWarehouse.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index 576fd5d4..92a2fe10 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -70,7 +70,7 @@ class CloudWarehouse extends BaseController 'status' => 1, 'is_del' => 0, 'mer_status' => 1, - 'product_type' => 98, + 'product_type' => 0, 'product_id' => $cloud_product ]; if (!$cloud_product) { @@ -82,7 +82,6 @@ class CloudWarehouse extends BaseController $query->whereOr('mer_labels', '') ->whereOr('mer_labels',',5,'); })->count(); - $products = $this->spuRepository->getApiSearch($where, $page, 10, false, true); if ($products['list']) { $list = $products['list'];