From c5e79115b8dd52601537336595d5d3711472ad43 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 10 Sep 2020 10:19:11 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/OrderOnlineController.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 554a029..ce37e77 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -93,15 +93,13 @@ class OrderOnlineController extends BaseController ]) ->select('id') ->first(); - $res['location'] = $this->userAddressService->getAddressAndDistributionRrice($address->id,$marketId); + $res['location'] = $this->userAddressService->getAddressAndDistributionRrice($address->id,$marketId); //返回预约送达时间 数组 $res['appointment_time'] = $this->appointmentTimeService->do(); // $res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds); //获取用户优惠券 $res['coupon'] = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId); - //获取配送费 - $res['distribution_price'] = '5.0'; //增值服务接口 $res['value_added_service'] = [ 'select' => 1, @@ -110,10 +108,10 @@ class OrderOnlineController extends BaseController $total = 0; foreach ($res['store_list'] as $store) { - $total+= $store['subtotal']; + $total = bcadd($total,$store['subtotal'],2); } - $total+= $res['value_added_service']['price']; - $total+= $res['distribution_price']; + $total = bcadd($total,$res['value_added_service']['price'],2); + $total = bcadd($total,$res['location']['distribution_price'],2); $res['total'] = $total; return $this->success($res); } From 1c74a5261627f2a9352cf93bc99fb486de59bcd4 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 10 Sep 2020 10:33:46 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=A2=9E=E5=80=BC=E6=9C=8D=E5=8A=A1text?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/OrderOnlineController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index ce37e77..4ef6e3d 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -102,6 +102,7 @@ class OrderOnlineController extends BaseController $res['coupon'] = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId); //增值服务接口 $res['value_added_service'] = [ + 'text' => '买鸡买鸭,免费帮杀;买瓜买黇,包熟包甜', 'select' => 1, 'price' => 3.50 ]; From c13addad24366685c76fe162429f8d2c8c8e272c Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 10 Sep 2020 10:44:59 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/UserAddressService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index 06d3bcf..e84ce0d 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -100,7 +100,8 @@ class UserAddressService implements UserAddressServiceInterface $distributionRrice = bcmul(1.50,($km-3),2); break; case ($km >= 10) : - throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); + $distributionRrice = bcmul(1.50,($km-3),2); + // throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); break; default: $distributionRrice = 0; From 9f5815eaf4fbcd41c8ece1b6d544c0bad348a006 Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 10 Sep 2020 11:41:04 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E6=94=B9=E7=94=A8global=5Forder=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/ErrorCode.php | 6 + app/Constants/v3/LogLabel.php | 10 ++ app/Controller/v3/NotifyController.php | 149 ++++++++++++++++-- app/Controller/v3/OrderOnlineController.php | 12 +- app/JsonRpc/OrderOnlineService.php | 87 ---------- app/JsonRpc/OrderOnlineServiceInterface.php | 8 - app/JsonRpc/OrderService.php | 83 +++++----- .../SeparateAccountsServiceInterface.php | 10 -- app/JsonRpc/SeparateaccountsService.php | 28 ---- app/Request/v3/OrderOnlineStateRequest.php | 2 +- .../Implementations/CouponRebateService.php | 10 +- .../v3/Implementations/CouponService.php | 10 +- .../v3/Implementations/DeviceService.php | 6 +- .../v3/Implementations/FeiePrintService.php | 4 +- .../v3/Implementations/MiniprogramService.php | 10 +- .../v3/Implementations/MqttService.php | 6 +- .../Implementations/OrderOfflineService.php | 7 +- .../v3/Implementations/OrderOnlineService.php | 66 +++++--- .../v3/Implementations/PaymentService.php | 59 +++++-- .../SeparateAccountsService.php | 29 ++-- .../v3/Implementations/UserService.php | 18 +-- .../v3/Interfaces/CouponServiceInterface.php | 8 +- .../MiniprogramServiceInterface.php | 8 +- .../OrderOfflineServiceInterface.php | 2 +- .../OrderOnlineServiceInterface.php | 38 +++-- .../v3/Interfaces/PaymentServiceInterface.php | 2 +- .../SeparateAccountsServiceInterface.php | 12 +- .../v3/Interfaces/UserServiceInterface.php | 16 +- config/autoload/wechat.php | 1 + config/routes.php | 1 + 30 files changed, 393 insertions(+), 315 deletions(-) delete mode 100644 app/JsonRpc/OrderOnlineService.php delete mode 100644 app/JsonRpc/OrderOnlineServiceInterface.php delete mode 100644 app/JsonRpc/SeparateAccountsServiceInterface.php delete mode 100644 app/JsonRpc/SeparateaccountsService.php diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index f516122..2529791 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -77,6 +77,12 @@ class ErrorCode extends AbstractConstants */ const ORDER_COMPLETE_FAIL = 609; + /** + * 订单退款失败 + * @Message("订单退款失败") + */ + const ORDER_REFUND_FAIL = 610; + /************************************/ /* 支付相关 651-700 */ /************************************/ diff --git a/app/Constants/v3/LogLabel.php b/app/Constants/v3/LogLabel.php index 4b0b65e..48ce8d5 100644 --- a/app/Constants/v3/LogLabel.php +++ b/app/Constants/v3/LogLabel.php @@ -47,6 +47,11 @@ class LogLabel extends AbstractConstants */ const ORDER_OFFLINE_PAY_NOTIFY_LOG = 'order_offline_pay_notify_log'; + /** + * @Message("退款通知") + */ + const ORDER_REFUND_NOTIFY_LOG = 'order_refund_notify_log'; + /** * @Message("订单支付") */ @@ -57,6 +62,11 @@ class LogLabel extends AbstractConstants */ const ORDER_COMPLETE_LOG = 'order_complete_log'; + /** + * @Message("订单退款") + */ + const ORDER_REFUND_LOG = 'order_refund_log'; + /** * @Message("IOT设备绑定") */ diff --git a/app/Controller/v3/NotifyController.php b/app/Controller/v3/NotifyController.php index 2796af8..5461b72 100644 --- a/app/Controller/v3/NotifyController.php +++ b/app/Controller/v3/NotifyController.php @@ -5,23 +5,32 @@ namespace App\Controller\v3; use App\Constants\v3\LogLabel; use App\Constants\v3\OrderState; use App\Constants\v3\OrderType; +use App\Constants\v3\Payment; +use App\Constants\v3\SsdbKeys; use App\Controller\BaseController; +use App\Model\v3\Order; +use App\Model\v3\OrderGoods; use App\Model\v3\OrderMain; use App\Service\v3\Interfaces\CouponRebateServiceInterface; +use App\Service\v3\Interfaces\CouponServiceInterface; use App\Service\v3\Interfaces\DeviceServiceInterface; use App\Service\v3\Interfaces\FeiePrintServiceInterface; +use App\Service\v3\Interfaces\FinancialRecordServiceInterface; +use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\MiniprogramServiceInterface; use App\Service\v3\Interfaces\MqttServiceInterface; use App\Service\v3\Interfaces\OrderOfflineServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; use App\Service\v3\Interfaces\UserServiceInterface; +use App\TaskWorker\SSDBTask; use EasyWeChat\Factory; use Hyperf\DbConnection\Db; use Hyperf\Guzzle\CoroutineHandler; use Exception; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpMessage\Stream\SwooleStream; +use Hyperf\Utils\ApplicationContext; use Symfony\Component\HttpFoundation\Request; class NotifyController extends BaseController @@ -81,6 +90,24 @@ class NotifyController extends BaseController */ protected $separateAccountsService; + /** + * @Inject + * @var CouponServiceInterface + */ + protected $couponService; + + /** + * @Inject + * @var FinancialRecordServiceInterface + */ + protected $financialService; + + /** + * @Inject + * @var GoodsActivityServiceInterface + */ + protected $goodsActivityService; + public function wxminiOnline() { @@ -132,21 +159,21 @@ class NotifyController extends BaseController return true; } - $this->orderOnlineService->doByPaid($orderMain->id); - $this->separateAccountsService->orderOnlinePaid($orderMain->id); + $this->orderOnlineService->doByPaid($orderMain->global_order_id); + $this->separateAccountsService->orderOnlinePaid($orderMain->global_order_id); // 优惠券返券 - $this->couponRebateService->couponRebateInTask($orderMain->id); + $this->couponRebateService->couponRebateInTask($orderMain->global_order_id); // 喇叭通知,兼容旧音响,MQTT+IOT - $res = $this->mqttService->speakToStore($orderMain->id); - $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMain->id); + $res = $this->mqttService->speakToStore($orderMain->global_order_id); + $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMain->global_order_id); // 公众号模板消息 - $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->id); + $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->global_order_id); // 打印订单,自动打印 - $res = $this->feiePrintService->feiePrint($orderMain->id); + $res = $this->feiePrintService->feiePrint($orderMain->global_order_id); Db::commit(); return true; @@ -225,15 +252,15 @@ class NotifyController extends BaseController return true; } - $orderPaid = $this->orderOfflineService->doPaid($orderMain->id); - $separate = $this->separateAccountsService->orderOfflinePaid($orderMain->id); + $orderPaid = $this->orderOfflineService->doPaid($orderMain->global_order_id); + $separate = $this->separateAccountsService->orderOfflinePaid($orderMain->global_order_id); // 喇叭通知,兼容旧音响,MQTT+IOT - $res = $this->mqttService->speakToStore($orderMain->id); - $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMain->id); + $res = $this->mqttService->speakToStore($orderMain->global_order_id); + $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMain->global_order_id); // 公众号模板消息 - $res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMain->id); + $res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMain->global_order_id); Db::commit(); return true; @@ -255,4 +282,102 @@ class NotifyController extends BaseController ->withStatus(200) ->withBody(new SwooleStream($response->getContent())); } + + public function wxminiRefund() + { + + $config = config('wxpay'); + $app = Factory::payment($config); + $app['guzzle_handler'] = CoroutineHandler::class; + + $get = $this->request->getQueryParams(); + $post = $this->request->getParsedBody(); + $cookie = $this->request->getCookieParams(); + $files = $this->request->getUploadedFiles(); + $server = $this->request->getServerParams(); + $xml = $this->request->getBody()->getContents(); + + $app['request'] = new Request($get,$post,[],$cookie,$files,$server,$xml); + + // 通知回调,进行业务处理 + $response = $app->handleRefundedNotify(function ($message, $reqInfo, $fail) use ($app) { + + Db::beginTransaction(); + try { + // 支付失败或者通知失败 + if ( + empty($message) + || $message['return_code'] != 'SUCCESS' + || !isset($message['result_code']) + || $message['result_code'] != 'SUCCESS' + ) { + $this->log->event( + LogLabel::ORDER_REFUND_NOTIFY_LOG, + $message + ); + Db::rollBack(); + return $fail('Unknown error but FAIL'); + } + + // 查询订单 + $orderMain = OrderMain::query() + ->whereIn('state', [OrderState::PAID, OrderState::DELIVERY, OrderState::COMPLETED, OrderState::EVALUATED, OrderState::REFUNDING]) + ->where(['global_order_id' => $message['global_order_id'], 'pay_type' => Payment::WECHAT]) + ->whereRaw('refund_time is null') + ->first(); + + // 订单不存在 + if (empty($orderMain)) { + $this->log->event( + LogLabel::ORDER_REFUND_NOTIFY_LOG, + ['global_order_id_fail' => $message['out_trade_no']] + ); + Db::rollBack(); + return true; + } + + // 添加退款时间 + $orderMain->refund_time = time(); + $orderMain->state = OrderState::REFUNDED; + $orderMain->save(); + + // 退款返还优惠券 + $this->couponService->orderRefundCoupons($orderMain->global_order_id); + + // 处理特价商品缓存 + $orderChildren = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray(); + $orderGoods = OrderGoods::query() + ->where(['activity_type' => 2]) + ->whereIn('order_id', array_values(array_column($orderChildren, 'id')))->get(); + foreach ($orderGoods as $key => &$item) { + $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->userId); + } + + // 添加用户的流水 + $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); + + Db::commit(); + + // 记录badge + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'refund', 1); + return true; + + } catch (Exception $e) { + + $this->log->event( + LogLabel::ORDER_REFUND_NOTIFY_LOG, + ['exception_fail' => $e->getMessage()] + ); + Db::rollBack(); + return $fail('Exception'); + } + + }); + + return $this->response + ->withHeader('Content-Type', 'text/xml') + ->withStatus(200) + ->withBody(new SwooleStream($response->getContent())); + } } \ No newline at end of file diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index ecab40c..b2a73d1 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -172,7 +172,7 @@ class OrderOnlineController extends BaseController public function pay(OrderOnlineStateRequest $request) { $params = $request->validated(); - $data = $this->orderOnlineService->doPay($params['order_id'], $params['user_id']); + $data = $this->orderOnlineService->doPay($params['global_order_id'], $params['user_id']); return $this->success(['data' => $data]); } @@ -184,7 +184,7 @@ class OrderOnlineController extends BaseController public function cancel(OrderOnlineStateRequest $request) { $params = $request->validated(); - $this->orderOnlineService->undo($params['order_id'], $params['user_id']); + $this->orderOnlineService->undo($params['global_order_id'], $params['user_id']); return $this->success([]); } @@ -196,7 +196,7 @@ class OrderOnlineController extends BaseController public function del(OrderOnlineStateRequest $request) { $params = $request->validated(); - $this->orderOnlineService->doDel($params['order_id'], $params['user_id']); + $this->orderOnlineService->doDel($params['global_order_id'], $params['user_id']); return $this->success([]); } @@ -208,7 +208,7 @@ class OrderOnlineController extends BaseController public function applyRefund(OrderOnlineStateRequest $request) { $params = $request->validated(); - $this->orderOnlineService->doApplyRefund($params['order_id'], $params['user_id']); + $this->orderOnlineService->doApplyRefund($params['global_order_id'], $params['user_id']); return $this->success([]); } @@ -223,8 +223,8 @@ class OrderOnlineController extends BaseController try { $params = $request->validated(); - $this->orderOnlineService->doComplete($params['order_id'], $params['user_id']); - $this->separateAccountsService->orderOnlineCompleted($params['order_id'], $params['user_id']); + $this->orderOnlineService->doComplete($params['global_order_id'], $params['user_id']); + $this->separateAccountsService->orderOnlineCompleted($params['global_order_id'], $params['user_id']); Db::commit(); return $this->success([]); diff --git a/app/JsonRpc/OrderOnlineService.php b/app/JsonRpc/OrderOnlineService.php deleted file mode 100644 index b7d0360..0000000 --- a/app/JsonRpc/OrderOnlineService.php +++ /dev/null @@ -1,87 +0,0 @@ -orderOnlineService->doComplete($orderMainId, $userId); - $this->separateAccountsService->orderOnlineCompleted($orderMainId, $userId); - - Db::commit(); - return [ - "status" => 200, - "code" => 0, - "result" => [], - "message" => '调用成功' - ]; - } catch (\Exception $e) { - - Db::rollBack(); - $this->log->event(LogLabel::ORDER_COMPLETE_LOG, ['exception' => $e->getMessage()]); - throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL, $e->getMessage()); - } - - } - - /** - * 线上订单退款 - * 申请退款 state = 8 - * 退款成功 state = 9 - */ - public function onlineRefund($global_order_id){ - $result = [ - "status" => 200, - "code" => ErrorCode::ORDER_FAILURE, - "result" => [], - "message" => '' - ]; - - $res = $this->orderOnlineService->onlineRefund($global_order_id); - if($res['code'] > 0){ - $result['result'] = $res; - $result['message'] = '退款失败'; - }else{ - $result['code'] = 0; - $result['result'] = $res; - $result['message'] = '退款成功'; - }; - - return $result; - } -} \ No newline at end of file diff --git a/app/JsonRpc/OrderOnlineServiceInterface.php b/app/JsonRpc/OrderOnlineServiceInterface.php deleted file mode 100644 index 5f26e43..0000000 --- a/app/JsonRpc/OrderOnlineServiceInterface.php +++ /dev/null @@ -1,8 +0,0 @@ -orderService->onlineCompleted($global_order_id); - $this->separateAccountsService->orderOnlineCompleted($global_order_id); + $this->orderOnlineService->doComplete($global_order_id, $user_id); + $this->separateAccountsService->orderOnlineCompleted($global_order_id, $user_id); Db::commit(); return [ "status" => 200, "code" => 0, "result" => [], - "message" => '调用成功' + "message" => '处理成功' ]; } catch (\Exception $e) { Db::rollBack(); - $this->log->event(LogLabel::ONLINE_COMPLETE_LOG, ['exception' => $e->getMessage()]); + $this->log->event(LogLabel::ORDER_COMPLETE_LOG, ['jsonrpc_order_service_exception_onlineComplete' => $e->getMessage(), 'params' => json([$global_order_id, $user_id])]); + throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL); + } + + } + + /** + * 线上订单退款,整个订单退 + * @param $global_order_id + * @param $user_id + * @return array + */ + public function onlineRefund($global_order_id, $user_id){ + + Db::beginTransaction(); + try { + + $this->orderOnlineService->doRefund($global_order_id, $user_id); + + Db::commit(); return [ "status" => 200, - "code" =>ErrorCode::SEPARATE_ACCOUNTS_ERROR, + "code" => 0, "result" => [], - "message" => ErrorCode::getMessage(ErrorCode::SEPARATE_ACCOUNTS_ERROR) + "message" => '处理成功' ]; - } + } catch (\Exception $e) { - } + Db::rollBack(); + $this->log->event(LogLabel::ORDER_REFUND_LOG, ['jsonrpc_order_service_exception_onlineRefund' => $e->getMessage(), 'params' => json([$global_order_id, $user_id])]); + throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL); + } - /** - * 线上订单退款 - * 申请退款 state = 8 - * 退款成功 state = 9 - */ - public function onlineRefund($global_order_id){ - $result = [ - "status" => 200, - "code" => ErrorCode::ORDER_FAILURE, - "result" => [], - "message" => '' - ]; - - $res = $this->orderService->onlineRefund($global_order_id); - if($res['code'] > 0){ - $result['result'] = $res; - $result['message'] = '退款失败'; - }else{ - $result['code'] = 0; - $result['result'] = $res; - $result['message'] = '退款成功'; - }; - - return $result; } } \ No newline at end of file diff --git a/app/JsonRpc/SeparateAccountsServiceInterface.php b/app/JsonRpc/SeparateAccountsServiceInterface.php deleted file mode 100644 index 28a8174..0000000 --- a/app/JsonRpc/SeparateAccountsServiceInterface.php +++ /dev/null @@ -1,10 +0,0 @@ -separateaccountsService->orderOnlineCompleted($orderMainId, $userId); - - } -} \ No newline at end of file diff --git a/app/Request/v3/OrderOnlineStateRequest.php b/app/Request/v3/OrderOnlineStateRequest.php index 523fb40..ae960c1 100644 --- a/app/Request/v3/OrderOnlineStateRequest.php +++ b/app/Request/v3/OrderOnlineStateRequest.php @@ -15,7 +15,7 @@ class OrderOnlineStateRequest extends BaseFormRequest public function rules(): array { return [ - 'order_id' => 'required|nonempty|integer', + 'global_order_id' => 'required|nonempty|integer', 'user_id' => 'required|nonempty|integer', ]; } diff --git a/app/Service/v3/Implementations/CouponRebateService.php b/app/Service/v3/Implementations/CouponRebateService.php index 2fdf94b..6195443 100644 --- a/app/Service/v3/Implementations/CouponRebateService.php +++ b/app/Service/v3/Implementations/CouponRebateService.php @@ -382,7 +382,7 @@ class CouponRebateService implements CouponRebateServiceInterface /* * 支付成功 返券 */ - public function couponRebateInTask($order_id) + public function couponRebateInTask($global_order_id) { //获取SSDB上的活动信息 $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); @@ -404,7 +404,7 @@ class CouponRebateService implements CouponRebateServiceInterface $coupon = Db::table('ims_system_coupon_user_receive as r') ->leftjoin('ims_system_coupon_user_use as u', 'u.user_receive_id', '=', 'r.id') ->where([ - ['u.order_main_id', '=', $order_id], + ['u.order_main_id', '=', $global_order_id], ['r.send_user_id', '>', 0], ['r.rebate_type', '=', 1], ['r.receive_type', '=', 4], @@ -461,7 +461,7 @@ class CouponRebateService implements CouponRebateServiceInterface 'status' => 0, 'number' => 1, 'number_remain' => 1, - 'order_main_id' => $order_id, + 'order_main_id' => $global_order_id, 'receive_time' => $nowTime, 'update_time' => $nowTime, 'created_at' => $nowTime, @@ -484,7 +484,7 @@ class CouponRebateService implements CouponRebateServiceInterface //添加领取记录到ssdb $data = [ - $order_id,$coupon->user_id, + $global_order_id,$coupon->user_id, ]; $ssdb->exec('multi_hset', SsdbKeys::COUPON_REBATE_LIST.$coupon->send_user_id, $data); // 提交 @@ -493,7 +493,7 @@ class CouponRebateService implements CouponRebateServiceInterface //写入日志文件 $log_Data = array(); $log_Data['name'] = '返券'; - $log_Data['order_id'] = $order_id; + $log_Data['order_id'] = $global_order_id; $log_Data['msg'] = '返券失败'; $this->log->event( LogLabel::COUPON_REBATE_LOG, diff --git a/app/Service/v3/Implementations/CouponService.php b/app/Service/v3/Implementations/CouponService.php index 38d83c5..c1b432b 100644 --- a/app/Service/v3/Implementations/CouponService.php +++ b/app/Service/v3/Implementations/CouponService.php @@ -69,7 +69,7 @@ class CouponService implements CouponServiceInterface return $couponTodayUsedIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); } - public function orderUseCoupons($orderMainId, $couponRecs) + public function orderUseCoupons($globalOrderId, $couponRecs) { Db::beginTransaction(); try { @@ -81,7 +81,7 @@ class CouponService implements CouponServiceInterface 'user_id' => $coupon['user_id'], 'user_receive_id' => $coupon['id'], 'coupon_id' => $coupon['coupon_id'], - 'order_main_id' => $orderMainId, + 'order_main_id' => $globalOrderId, 'use_time' => time(), 'return_time' => 0, 'number' => 1, @@ -133,16 +133,16 @@ class CouponService implements CouponServiceInterface * 退还优惠券,订单取消,申请退款成功时 * 先查询是否正常使用优惠券 * 修改状态,退还领取记录库存,删除ssdb缓存 - * @param $orderMainId + * @param $globalOrderId * @return bool */ - public function orderRefundCoupons($orderMainId) + public function orderRefundCoupons($globalOrderId) { $currentTime = time(); Db::beginTransaction(); try { $couponUses = CouponUse::query() - ->where('order_main_id', $orderMainId) + ->where('order_main_id', $globalOrderId) ->where('status', 1) ->get(); if (!empty($couponUses)) { diff --git a/app/Service/v3/Implementations/DeviceService.php b/app/Service/v3/Implementations/DeviceService.php index 4d264c7..ddb3917 100644 --- a/app/Service/v3/Implementations/DeviceService.php +++ b/app/Service/v3/Implementations/DeviceService.php @@ -95,15 +95,15 @@ class DeviceService implements DeviceServiceInterface return true; } - public function pubMsgToStoreByOrderMainId($order_id, $is_main = true) + public function pubMsgToStoreByOrderMainId($global_order_id, $is_main = true) { // 获取订单 $orders = Order::query()->with('orderMain'); if ($is_main) { - $orders = $orders->where(['order_main_id' => $order_id])->get()->toArray(); + $orders = $orders->where(['order_main_id' => $global_order_id])->get()->toArray(); } else { - $orders = $orders->where(['id' => $order_id])->get()->toArray(); + $orders = $orders->where(['global_order_id' => $global_order_id])->get()->toArray(); } if(empty($orders)) return; diff --git a/app/Service/v3/Implementations/FeiePrintService.php b/app/Service/v3/Implementations/FeiePrintService.php index cecda5f..eca012b 100644 --- a/app/Service/v3/Implementations/FeiePrintService.php +++ b/app/Service/v3/Implementations/FeiePrintService.php @@ -38,7 +38,7 @@ class FeiePrintService implements FeiePrintServiceInterface $this->feieApiPath = config('feie.api_path'); } - public function feiePrint($orderMainId) + public function feiePrint($globalOrderId) { // TODO 对象数组=》二维数组 $data = Db::table('lanzu_order_main as m') @@ -46,7 +46,7 @@ class FeiePrintService implements FeiePrintServiceInterface ->join('lanzu_order_goods as g','o.id','=', 'g.order_id','inner') ->join('lanzu_feprint as f','m.market_id','=', 'f.market_id','inner') ->join('lanzu_store as s','s.id','=', 'o.store_id','inner') - ->where('m.id', $orderMainId) + ->where('m.global_order_id', $globalOrderId) ->selectRaw("o.note as o_note,g.name,g.number,g.price,g.goods_unit,m.delivery_time_note as ps_time,m.address,m.note,m.name as user_name,m.delivery_money,m.money as m_money,m.coupon_money,m.services_money,f.sn,m.tel,m.order_num,g.id,g.spec,s.name as shopname") ->orderBy('s.id') ->get() diff --git a/app/Service/v3/Implementations/MiniprogramService.php b/app/Service/v3/Implementations/MiniprogramService.php index 3115292..27d2476 100644 --- a/app/Service/v3/Implementations/MiniprogramService.php +++ b/app/Service/v3/Implementations/MiniprogramService.php @@ -17,11 +17,11 @@ class MiniprogramService implements MiniprogramServiceInterface /** * @inheritDoc */ - public function sendTemMsgForOnlineOrder($order_main_id) + public function sendTemMsgForOnlineOrder($globalOrderId) { // 查询订单信息 - $order = OrderMain::query()->find($order_main_id)->toArray(); + $order = OrderMain::query()->where(['global_order_id' => $globalOrderId])->first()->toArray(); $payTypes = ['1' => '微信支付', '2' => '余额支付', '3' => '积分支付', '4' => '货到付款']; $address_store = $order['address'] . ';' .$order['name']. ';'. substr_replace($order['tel'],'****',3,4); @@ -30,7 +30,7 @@ class MiniprogramService implements MiniprogramServiceInterface // 查询子订单,用于发消息给商户 $order_children = Order::query() ->with('orderMain') - ->where(['order_main_id' => $order_main_id]) + ->where(['order_main_id' => $globalOrderId]) ->get(); $goods_temp_all = []; @@ -94,12 +94,12 @@ class MiniprogramService implements MiniprogramServiceInterface /** * @inheritDoc */ - public function sendTemMsgForOfflineOrder($order_main_id) + public function sendTemMsgForOfflineOrder($globalOrderId) { // 查询子订单,用于发消息给商户 $order_children = Order::query() - ->where(['order_main_id' => $order_main_id]) + ->where(['order_main_id' => $globalOrderId]) ->get() ->toArray(); diff --git a/app/Service/v3/Implementations/MqttService.php b/app/Service/v3/Implementations/MqttService.php index 64be0d3..4a508a3 100644 --- a/app/Service/v3/Implementations/MqttService.php +++ b/app/Service/v3/Implementations/MqttService.php @@ -15,16 +15,16 @@ class MqttService implements MqttServiceInterface /** * @inheritDoc */ - public function speakToStore($orderId, $isMain = true) + public function speakToStore($globalOrderId, $isMain = true) { // 获取订单 $orders = Order::query() ->with('orderMain'); if ($isMain) { - $orders = $orders->where(['order_main_id' => $orderId])->get(); + $orders = $orders->where(['order_main_id' => $globalOrderId])->get(); } else { - $orders = $orders->where(['id' => $orderId])->get(); + $orders = $orders->where(['global_order_id' => $globalOrderId])->get(); } if(empty($orders)) return; diff --git a/app/Service/v3/Implementations/OrderOfflineService.php b/app/Service/v3/Implementations/OrderOfflineService.php index f0e76e5..0ca4633 100644 --- a/app/Service/v3/Implementations/OrderOfflineService.php +++ b/app/Service/v3/Implementations/OrderOfflineService.php @@ -65,7 +65,6 @@ class OrderOfflineService implements OrderOfflineServiceInterface ]; $orderMain = OrderMain::query()->create($dataMain); - $orderMainId = $orderMain->id; // 店铺今天的订单数 $count = Order::query() @@ -76,7 +75,7 @@ class OrderOfflineService implements OrderOfflineServiceInterface // 子订单数据 $dataChildren = [ - 'order_main_id' => $orderMainId, + 'order_main_id' => $orderMain->global_order_id, 'user_id' => $userId, 'store_id' => $storeId, 'money' => $money, @@ -108,14 +107,14 @@ class OrderOfflineService implements OrderOfflineServiceInterface // TODO: Implement undo() method. } - public function doPaid($orderMainId) + public function doPaid($globalOrderId) { Db::beginTransaction(); try { // 主订单状态更新 $orderMain = OrderMain::query() - ->where(['id' => $orderMainId, 'type' => OrderType::OFFLINE]) + ->where(['global_order_id' => $globalOrderId, 'type' => OrderType::OFFLINE]) ->first(); if (empty($orderMain)) { diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 444c64b..7ce5089 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -3,16 +3,15 @@ namespace App\Service\v3\Implementations; use App\Commons\Log; -use App\Constants\v3\ActivityType; use App\Constants\v3\ErrorCode; use App\Constants\v3\LogLabel; use App\Constants\v3\OrderState; use App\Constants\v3\OrderType; +use App\Constants\v3\Payment; use App\Constants\v3\SsdbKeys; use App\Exception\ErrorCodeException; use App\Model\v3\Coupon; use App\Model\v3\CouponRec; -use App\Model\v3\CouponUse; use App\Model\v3\Goods; use App\Model\v3\GoodsActivity; use App\Model\v3\Order; @@ -293,11 +292,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 生成主订单 $orderMain = OrderMain::query()->create($dataMain); - $orderMainId = $orderMain->id; // 处理子订单 foreach ($dataChildren as $key => &$child) { - $child['order_main_id'] = $orderMainId; + $child['order_main_id'] = $globalOrderId; $orderChild = Order::query()->create($child); $orderChildId = $orderChild->id; @@ -325,7 +323,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface } // 优惠券红包使用记录 - $this->couponService->orderUseCoupons($orderMainId, $couponRec); + $this->couponService->orderUseCoupons($globalOrderId, $couponRec); Db::commit(); @@ -345,10 +343,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface } } - public function check($orderMainId, $userId, $state): Model + public function check($globalOrderId, $userId, $state): Model { $builder = OrderMain::query() - ->where(['id' => $orderMainId, 'user_id' => $userId]); + ->where(['global_order_id' => $globalOrderId, 'user_id' => $userId]); if (is_array($state)) { $builder = $builder->whereIn('state', $state); @@ -366,22 +364,22 @@ class OrderOnlineService implements OrderOnlineServiceInterface /** * @inheritDoc */ - public function undo($orderMainId, $userId) + public function undo($globalOrderId, $userId) { Db::beginTransaction(); try { // 订单待支付 - $orderMain = $this->check($orderMainId, $userId, OrderState::UNPAID); + $orderMain = $this->check($globalOrderId, $userId, OrderState::UNPAID); $orderMain->state = OrderState::CANCELED; if (!$orderMain->save()) { throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE); } // 退还优惠券 - $this->couponService->orderRefundCoupons($orderMainId); + $this->couponService->orderRefundCoupons($globalOrderId); // 撤销活动商品购买记录 - $orders = Order::query()->where(['order_main_id' => $orderMainId])->get()->toArray(); + $orders = Order::query()->where(['order_main_id' => $globalOrderId])->get()->toArray(); $orderGoods = OrderGoods::query() ->where('activity_type', 2) ->whereIn('order_id', array_values(array_column($orders, 'id'))) @@ -398,12 +396,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface } } - public function detailByUser($orderMainId, $userId) + public function detailByUser($globalOrderId, $userId) { - $orderMain = OrderMain::with(['market'])->find($orderMainId); + $orderMain = OrderMain::with(['market'])->where(['global_order_id' => $globalOrderId])->first(); $orders = Order::query() - ->where(['order_main_id' => $orderMainId, 'user_id' => $userId]) + ->where(['order_main_id' => $globalOrderId, 'user_id' => $userId]) ->with([ 'orderGoods', 'store' @@ -416,7 +414,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface /** * @inheritDoc */ - public function doByPaid($orderMainId) + public function doByPaid($globalOrderId) { Db::beginTransaction(); try { @@ -425,7 +423,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 查询订单 $orderMain = OrderMain::query() - ->where(['id' => $orderMainId,'type' => OrderType::ONLINE]) + ->where(['global_order_id' => $globalOrderId,'type' => OrderType::ONLINE]) ->first(); // 修改订单、子订单状态 @@ -436,7 +434,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 更新商品库存和销量 $orders = Order::query() - ->where(['order_main_id' => $orderMain->id]) + ->where(['order_main_id' => $globalOrderId]) ->get() ->toArray(); @@ -508,10 +506,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface /** * @inheritDoc */ - public function doPay($orderMainId, $userId) + public function doPay($globalOrderId, $userId) { // 订单待支付 - $orderMain = $this->check($orderMainId, $userId, OrderState::UNPAID); + $orderMain = $this->check($globalOrderId, $userId, OrderState::UNPAID); return $this->paymentService->do( $orderMain->global_order_id, $orderMain->money, @@ -524,10 +522,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface * @inheritDoc * @throws Exception */ - public function doDel($orderMainId, $userId) + public function doDel($globalOrderId, $userId) { // 订单完成 - $orderMain = $this->check($orderMainId, $userId, OrderState::CAN_DEL); + $orderMain = $this->check($globalOrderId, $userId, OrderState::CAN_DEL); if (!$orderMain->delete()) { throw new ErrorCodeException(ErrorCode::ORDER_DELETE_FAIL); } @@ -537,10 +535,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface /** * @inheritDoc */ - public function doApplyRefund($orderMainId, $userId) + public function doApplyRefund($globalOrderId, $userId) { // 未接单 - $orderMain = $this->check($orderMainId, $userId, OrderState::PAID); + $orderMain = $this->check($globalOrderId, $userId, OrderState::PAID); $orderMain->state = OrderState::REFUNDING; if (!$orderMain->save()) { throw new ErrorCodeException(ErrorCode::ORDER_APPLY_REFUND_FAIL); @@ -555,9 +553,9 @@ class OrderOnlineService implements OrderOnlineServiceInterface /** * @inheritDoc */ - public function doComplete($orderMainId, $userId) + public function doComplete($globalOrderId, $userId) { - $orderMain = $this->check($orderMainId, $userId, OrderState::RECEIVING); + $orderMain = $this->check($globalOrderId, $userId, OrderState::RECEIVING); $orderMain->state = OrderState::COMPLETED; if (!$orderMain->save()) { throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL); @@ -567,4 +565,22 @@ class OrderOnlineService implements OrderOnlineServiceInterface $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'completed', 1); return true; } + + /** + * @inheritDoc + */ + public function doRefund($globalOrderId, $userId) + { + + $orderMain = $this->check($globalOrderId, $userId, OrderState::REFUNDING); + $orderMain->state = OrderState::REFUNDED; + if (!$orderMain->save()) { + throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL); + } + + // 微信退款 + if ($orderMain->pay_type == Payment::WECHAT) { + return $this->paymentService->undo($orderMain->global_order_id, $userId); + } + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/PaymentService.php b/app/Service/v3/Implementations/PaymentService.php index 5da66e7..0f92373 100644 --- a/app/Service/v3/Implementations/PaymentService.php +++ b/app/Service/v3/Implementations/PaymentService.php @@ -7,15 +7,21 @@ use App\Constants\v3\ErrorCode; use App\Constants\v3\LogLabel; use App\Constants\v3\OrderState; use App\Constants\v3\OrderType; +use App\Constants\v3\Payment; use App\Exception\ErrorCodeException; use App\Model\v3\OrderMain; use App\Model\v3\User; use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\PaymentServiceInterface; use EasyWeChat\Factory; +use EasyWeChat\Kernel\Exceptions\InvalidConfigException; +use EasyWeChat\Kernel\Support\Collection; use GuzzleHttp\Exception\GuzzleException; +use Hyperf\DbConnection\Db; use Hyperf\Guzzle\CoroutineHandler; use Hyperf\Di\Annotation\Inject; +use Psr\Http\Message\ResponseInterface; +use function AlibabaCloud\Client\json; class PaymentService implements PaymentServiceInterface { @@ -25,12 +31,6 @@ class PaymentService implements PaymentServiceInterface */ protected $log; - /** - * @Inject - * @var GoodsActivityServiceInterface - */ - protected $goodsActivityService; - public function do($globalOrderId, $money, $userId, $notifyUrl) { @@ -79,12 +79,12 @@ class PaymentService implements PaymentServiceInterface ]; $parameters['paySign'] = $this->signture($parameters, $config['key']); - $parameters['order_main_id'] = $orderMain->id; + $parameters['order_main_id'] = $orderMain->global_order_id; return $parameters; } catch (\Exception $e) { - $this->log->event(LogLabel::ORDER_PAYMENT_LOG, ['payment_exception_msg' => $e->getMessage()]); + $this->log->event(LogLabel::ORDER_PAYMENT_LOG, ['payment_do_exception_msg' => $e->getMessage()]); throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL, '[支付失败]'.$e->getMessage()); } } @@ -94,9 +94,48 @@ class PaymentService implements PaymentServiceInterface // TODO: Implement check() method. } - public function undo() + /** + * 退款的整单,允许后台操作退款 + * @param $globalOrderId + * @param $userId + * @return array|bool|Collection|object|ResponseInterface|string + */ + public function undo($globalOrderId, $userId) { - // TODO: Implement undo() method. + + try{ + + $config = config('wxpay'); + $app = Factory::payment($config); + $app['guzzle_handler'] = CoroutineHandler::class; + + // 已支付的,未退款的,使用微信支付的订单 + $orderMain = OrderMain::query() + ->whereIn('state', [OrderState::PAID, OrderState::DELIVERY, OrderState::COMPLETED, OrderState::EVALUATED, OrderState::REFUNDING]) + ->where(['global_order_id' => $globalOrderId, 'user_id' => $userId, 'pay_type' => Payment::WECHAT]) + ->whereRaw('refund_time is null') + ->first(); + + if (empty($orderMain)) { + throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE, '[支付订单号]'.$globalOrderId); + } + + $result = $app->refund->byOutTradeNumber( + $orderMain->global_order_id, + $orderMain->global_order_id, + bcmul($orderMain->money, 100, 0), + bcmul($orderMain->money, 100, 0), + [ + 'refund_desc' => '订单退款', + 'notify_url' => config('wechat.notify_url.refund'), + ] + ); + + } catch (\Exception $e) { + $this->log->event(LogLabel::ORDER_PAYMENT_LOG, ['payment_do_exception_msg' => $e->getMessage()]); + throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL, '[退款失败]'.$e->getMessage()); + } + } /** diff --git a/app/Service/v3/Implementations/SeparateAccountsService.php b/app/Service/v3/Implementations/SeparateAccountsService.php index 3cc9f7b..6f9178d 100644 --- a/app/Service/v3/Implementations/SeparateAccountsService.php +++ b/app/Service/v3/Implementations/SeparateAccountsService.php @@ -58,12 +58,12 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface /** * @inheritDoc */ - public function orderOnlinePaid($orderMainId) + public function orderOnlinePaid($globalOrderId) { try { // 线上订单支付完成 // 订单 - $orderMain = OrderMain::query()->find($orderMainId); + $orderMain = OrderMain::query()->where(['global_order_id' => $globalOrderId])->first(); if (empty($orderMain)) { return false; @@ -83,11 +83,11 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface /** * @inheritDoc */ - public function orderOnlineCompleted($orderMainId, $userId) + public function orderOnlineCompleted($globalOrderId, $userId) { // 线上订单完成(用户点击确认收货完成/管理后台点击完成/配送员点击完成/自动收货等),进行相关分账 // 订单 - $orderMain = $this->orderOnlineService->check($orderMainId, $userId,OrderState::FINISH); + $orderMain = $this->orderOnlineService->check($globalOrderId, $userId,OrderState::FINISH); $currentTime = time(); Db::beginTransaction(); @@ -96,7 +96,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface // =======商户订单收入流水 / Start======= // 查询子订单 $orders = Order::query() - ->where(['order_main_id' => $orderMain->id]) + ->where(['order_main_id' => $orderMain->global_order_id]) ->get()->toArray(); // 新商户流水 @@ -126,7 +126,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface } $award = $award->set_reward; // 平台新用户 - if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { + if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->global_order_id)) { $this->financialRecordService->communityAwardByPlatNewUser( $communityBind->source_id, $orderMain->global_order_id, @@ -160,12 +160,11 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface /** * @inheritDoc */ - public function orderOfflinePaid($orderMainId) + public function orderOfflinePaid($globalOrderId) { // 线下订单支付完成 // 订单 - $orderMain = OrderMain::query()->find($orderMainId); - $global_order_id = $orderMain->global_order_id; + $orderMain = OrderMain::query()->where(['global_order_id' => $globalOrderId]); if (empty($orderMain)) { return false; @@ -173,7 +172,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface // 查询子订单,当面付目前实际上只有一个子订单 $order = Order::query() - ->where(['order_main_id' => $orderMain->id]) + ->where(['order_main_id' => $orderMain->global_order_id]) ->first(); if (empty($order)) { @@ -185,7 +184,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface try { // =======用户支付流水 / Start======= - $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $global_order_id, $orderMain->money); + $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); // =======用户支付流水 / End======= // =======线下订单支付完成商户分账 / Start======= @@ -200,12 +199,12 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface $store = Store::find($order->store_id); // 新商户订单流水 - $this->financialRecordService->storeByOFLOrderComp($store->user_id, $global_order_id, $order->money); + $this->financialRecordService->storeByOFLOrderComp($store->user_id, $orderMain->global_order_id, $order->money); $needAward = false; $awardAmount = 0; // 新用户商户奖励 - if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { + if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->global_order_id)) { $awardAmount = 2; // 旧商户流水 TODO 直接移除或后续考虑移除 @@ -214,7 +213,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface 'note' => '新用户下单成功,平台奖励', ]; // 新商户流水 - $this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $global_order_id, $awardAmount); + $this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $orderMain->global_order_id, $awardAmount); $needAward = true; } else { @@ -236,7 +235,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface 'note' => '用户下单成功,平台奖励', ]; // 新商户流水 - $this->financialRecordService->storeAwardByTodayFirstOFLOrder($store->user_id, $global_order_id, $awardAmount); + $this->financialRecordService->storeAwardByTodayFirstOFLOrder($store->user_id, $orderMain->global_order_id, $awardAmount); $needAward = true; } diff --git a/app/Service/v3/Implementations/UserService.php b/app/Service/v3/Implementations/UserService.php index e02b9de..1c7ebf2 100644 --- a/app/Service/v3/Implementations/UserService.php +++ b/app/Service/v3/Implementations/UserService.php @@ -16,15 +16,15 @@ class UserService implements UserServiceInterface * 在很多奖励的地方会需要用到这个查询 * 判定条件: * 没有在平台下过单(包括线上和线下) - * @param $user_id - * @param $order_main_id + * @param $userId + * @param $globalOrderId * @return mixed|void */ - public function isPlatformNewUser($user_id, $order_main_id): bool + public function isPlatformNewUser($userId, $globalOrderId): bool { return !OrderMain::query() - ->where(['user_id' => $user_id]) - ->where('id', '!=', $order_main_id) + ->where(['user_id' => $userId]) + ->where('global_order_id', '!=', $globalOrderId) ->whereIn('state', OrderState::FINISH) ->exists(); } @@ -32,16 +32,16 @@ class UserService implements UserServiceInterface /** * @inheritDoc */ - public function isStoreFirstOrderToday($user_id, $store_id, $current_order_id, $limit_amount = 3) + public function isStoreFirstOrderToday($userId, $storeId, $currentOrderId, $limitAmount = 3) { return !Order::query() ->join('lanzu_order_main as main', 'main.id', '=', 'lanzu_order.order_main_id') - ->where(['main.user_id' => $user_id, 'lanzu_order.store_id' => $store_id, 'main.type' => OrderType::OFFLINE]) + ->where(['main.user_id' => $userId, 'lanzu_order.store_id' => $storeId, 'main.type' => OrderType::OFFLINE]) ->whereIn('main.state', OrderState::FINISH) ->where('lanzu_order.created_at', '>=', strtotime(date('Y-m-d 00:00:00'))) ->where('lanzu_order.created_at', '<=', strtotime(date('Y-m-d 23:59:59'))) - ->where('main.money', '>=', $limit_amount) - ->where('lanzu_order.id', '!=', $current_order_id) + ->where('main.money', '>=', $limitAmount) + ->where('lanzu_order.id', '!=', $currentOrderId) ->exists(); } diff --git a/app/Service/v3/Interfaces/CouponServiceInterface.php b/app/Service/v3/Interfaces/CouponServiceInterface.php index 0e58068..4482b4e 100644 --- a/app/Service/v3/Interfaces/CouponServiceInterface.php +++ b/app/Service/v3/Interfaces/CouponServiceInterface.php @@ -35,16 +35,16 @@ interface CouponServiceInterface /** * 订单使用优惠券 - * @param $orderMainId + * @param $globalOrderId * @param $couponRecs * @return mixed */ - public function orderUseCoupons($orderMainId, $couponRecs); + public function orderUseCoupons($globalOrderId, $couponRecs); /** * 订单退还优惠券 - * @param $orderMainId + * @param $globalOrderId * @return mixed */ - public function orderRefundCoupons($orderMainId); + public function orderRefundCoupons($globalOrderId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/MiniprogramServiceInterface.php b/app/Service/v3/Interfaces/MiniprogramServiceInterface.php index 68e55c7..9112b83 100644 --- a/app/Service/v3/Interfaces/MiniprogramServiceInterface.php +++ b/app/Service/v3/Interfaces/MiniprogramServiceInterface.php @@ -6,17 +6,17 @@ interface MiniprogramServiceInterface { /** * 外卖线上订单模板消息 - * @param $order_main_id + * @param $globalOrderId * @return mixed */ - public function sendTemMsgForOnlineOrder($order_main_id); + public function sendTemMsgForOnlineOrder($globalOrderId); /** * 当面线下订单模板消息 - * @param $order_main_id + * @param $globalOrderId * @return mixed */ - public function sendTemMsgForOfflineOrder($order_main_id); + public function sendTemMsgForOfflineOrder($globalOrderId); /** * 奖励模板消息 diff --git a/app/Service/v3/Interfaces/OrderOfflineServiceInterface.php b/app/Service/v3/Interfaces/OrderOfflineServiceInterface.php index 7c10074..bbfd699 100644 --- a/app/Service/v3/Interfaces/OrderOfflineServiceInterface.php +++ b/app/Service/v3/Interfaces/OrderOfflineServiceInterface.php @@ -7,5 +7,5 @@ interface OrderOfflineServiceInterface public function do($storeId, $userId, $money, $plat=''); public function check(); public function undo(); - public function doPaid($orderMainId); + public function doPaid($globalOrderId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php b/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php index e17c3d1..d396b1a 100644 --- a/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php +++ b/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php @@ -10,56 +10,64 @@ interface OrderOnlineServiceInterface /** * 订单是否存在,有效 - * @param $orderMainId + * @param $globalOrderId * @param $userId * @param $state * @return mixed */ - public function check($orderMainId, $userId, $state): Model; + public function check($globalOrderId, $userId, $state): Model; /** * 取消订单 - * @param $orderMainId + * @param $globalOrderId * @param $userId * @return mixed */ - public function undo($orderMainId, $userId); + public function undo($globalOrderId, $userId); - public function detailByUser($orderMainId, $userId); + public function detailByUser($globalOrderId, $userId); /** * 线上订单支付完成(支付成功)后续处理 - * @param $orderMainId + * @param $globalOrderId * @return mixed */ - public function doByPaid($orderMainId); + public function doByPaid($globalOrderId); /** * 线上订单支付 - * @param $orderMainId + * @param $globalOrderId * @param $userId */ - public function doPay($orderMainId, $userId); + public function doPay($globalOrderId, $userId); /** * 删除订单 - * @param $orderMainId + * @param $globalOrderId * @param $userId */ - public function doDel($orderMainId, $userId); + public function doDel($globalOrderId, $userId); /** * 申请退款 - * @param $orderMainId + * @param $globalOrderId * @param $userId */ - public function doApplyRefund($orderMainId, $userId); + public function doApplyRefund($globalOrderId, $userId); /** * 确认收货等完成订单 - * @param $orderMainId + * @param $globalOrderId * @param $userId * @return mixed */ - public function doComplete($orderMainId, $userId); + public function doComplete($globalOrderId, $userId); + + /** + * 整单退款 + * @param $globalOrderId + * @param $userId + * @return mixed + */ + public function doRefund($globalOrderId, $userId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/PaymentServiceInterface.php b/app/Service/v3/Interfaces/PaymentServiceInterface.php index 426a8e0..488c0bf 100644 --- a/app/Service/v3/Interfaces/PaymentServiceInterface.php +++ b/app/Service/v3/Interfaces/PaymentServiceInterface.php @@ -6,6 +6,6 @@ interface PaymentServiceInterface { public function do($globalOrderId, $money, $userId, $notifyUrl); public function check(); - public function undo(); + public function undo($globalOrderId, $userId); public function payToWx($money, $tradeNo, $openId, $userName, $desc = '', $checkName = 'NO_CHECK'); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/SeparateAccountsServiceInterface.php b/app/Service/v3/Interfaces/SeparateAccountsServiceInterface.php index c81cbdc..9b832a7 100644 --- a/app/Service/v3/Interfaces/SeparateAccountsServiceInterface.php +++ b/app/Service/v3/Interfaces/SeparateAccountsServiceInterface.php @@ -6,24 +6,24 @@ interface SeparateAccountsServiceInterface { /** * (线上)订单支付完成分账 - * @param $orderMainId + * @param $globalOrderId * @return mixed */ - public function orderOnlinePaid($orderMainId); + public function orderOnlinePaid($globalOrderId); /** * (线上)订单确认完成分账 * 用户确认或服务商(服务站确认) - * @param $orderMainId + * @param $globalOrderId * @param $userId * @return mixed */ - public function orderOnlineCompleted($orderMainId, $userId); + public function orderOnlineCompleted($globalOrderId, $userId); /** * (线下)订单支付完成分账 - * @param $orderMainId + * @param $globalOrderId * @return mixed */ - public function orderOfflinePaid($orderMainId); + public function orderOfflinePaid($globalOrderId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/UserServiceInterface.php b/app/Service/v3/Interfaces/UserServiceInterface.php index 0e6952f..6e68e6b 100644 --- a/app/Service/v3/Interfaces/UserServiceInterface.php +++ b/app/Service/v3/Interfaces/UserServiceInterface.php @@ -6,19 +6,19 @@ interface UserServiceInterface { /** * 是否平台新用户 - * @param $user_id - * @param $order_main_id + * @param $userId + * @param $globalOrderId * @return mixed */ - public function isPlatformNewUser($user_id, $order_main_id): bool; + public function isPlatformNewUser($userId, $globalOrderId): bool; /** * 是否店铺当日首单 - * @param $user_id - * @param $store_id - * @param $current_order_id - * @param int $limit_amount + * @param $userId + * @param $storeId + * @param $currentOrderId + * @param int $limitAmount * @return mixed */ - public function isStoreFirstOrderToday($user_id, $store_id, $current_order_id, $limit_amount = 3); + public function isStoreFirstOrderToday($userId, $storeId, $currentOrderId, $limitAmount = 3); } \ No newline at end of file diff --git a/config/autoload/wechat.php b/config/autoload/wechat.php index 653a5f4..cdf7b9b 100644 --- a/config/autoload/wechat.php +++ b/config/autoload/wechat.php @@ -14,6 +14,7 @@ return [ 'notify_url' => [ 'online' => env('SITE_HOST') . '/v3/wechat/notify/online', 'offline' => env('SITE_HOST') . '/v3/wechat/notify/offline', + 'refund' => env('SITE_HOST') . '/v3/wechat/notify/refund', ], 'withdrawal' => [ 'is_direct' => env('WITHDRAW_IS_DIRECT'), diff --git a/config/routes.php b/config/routes.php index 876a8f4..8bbf6d9 100644 --- a/config/routes.php +++ b/config/routes.php @@ -146,4 +146,5 @@ Router::addGroup('/v3/', function () { Router::addGroup('/v3/wechat/',function () { Router::post('notify/online', 'App\Controller\v3\NotifyController@wxminiOnline'); Router::post('notify/offline', 'App\Controller\v3\NotifyController@wxminiOffline'); + Router::post('notify/refund', 'App\Controller\v3\NotifyController@wxminiRefund'); }); \ No newline at end of file From 09d572e73e52f358eec69f7b2dd926460e17cff9 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 10 Sep 2020 12:02:35 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E9=85=8D=E9=80=81=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/OrderOnlineController.php | 2 +- app/Controller/v3/UserAddressController.php | 4 +- .../DistributionPriceService.php | 24 ++++++++++- .../v3/Implementations/UserAddressService.php | 42 +++++-------------- .../DistributionPriceServiceInterface.php | 2 +- .../UserAddressServiceInterface.php | 2 +- config/routes.php | 2 +- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 4ef6e3d..6e80d2e 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -93,7 +93,7 @@ class OrderOnlineController extends BaseController ]) ->select('id') ->first(); - $res['location'] = $this->userAddressService->getAddressAndDistributionRrice($address->id,$marketId); + $res['location'] = $this->userAddressService->getAddressAndDistributionPrice($address->id,$marketId); //返回预约送达时间 数组 $res['appointment_time'] = $this->appointmentTimeService->do(); // diff --git a/app/Controller/v3/UserAddressController.php b/app/Controller/v3/UserAddressController.php index 3687345..ba33f83 100644 --- a/app/Controller/v3/UserAddressController.php +++ b/app/Controller/v3/UserAddressController.php @@ -60,11 +60,11 @@ class UserAddressController extends BaseController return $this->success($res); } - public function getAddressAndDistributionRrice() + public function getAddressAndDistributionPrice() { $userAddressId = $this->request->input('user_address_id'); $marketId = $this->request->input('market_id'); - $res = $this->userAddressService->getAddressAndDistributionRrice($userAddressId,$marketId); + $res = $this->userAddressService->getAddressAndDistributionPrice($userAddressId,$marketId); return $this->success(['location' => $res]); } diff --git a/app/Service/v3/Implementations/DistributionPriceService.php b/app/Service/v3/Implementations/DistributionPriceService.php index edbf494..0e4fffe 100644 --- a/app/Service/v3/Implementations/DistributionPriceService.php +++ b/app/Service/v3/Implementations/DistributionPriceService.php @@ -8,9 +8,29 @@ use App\Service\v3\Interfaces\DistributionPriceServiceInterface; class DistributionPriceService implements DistributionPriceServiceInterface { - public function do() + public function do($distance) { - return '配送费'; + $km = ceil($distance/1000); + switch ($km){ + case ($km > 3 && $km < 5) : + $distributionRrice = bcmul(0.70,($km-3),2); + break; + case ($km >= 5 && $km < 7) : + $distributionRrice = bcmul(1.00,($km-3),2); + break; + case ($km >= 7 && $km < 10) : + $distributionRrice = bcmul(1.50,($km-3),2); + break; + case ($km >= 10) : + $distributionRrice = bcmul(1.50,($km-3),2); + // throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); + break; + default: + $distributionRrice = 0; + break; + } + $distributionRrice = bcadd($distributionRrice,3.50,2); + return $distributionRrice; } public function check() diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index e84ce0d..e41f7c7 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -6,6 +6,7 @@ use App\Constants\v3\ErrorCode; use App\Exception\ErrorCodeException; use App\Model\v3\Market; use App\Model\v3\UserAddress; +use App\Service\v3\Interfaces\DistributionPriceServiceInterface; use App\Service\v3\Interfaces\LocationServiceInterface; use App\Service\v3\Interfaces\UserAddressServiceInterface; use Hyperf\Di\Annotation\Inject; @@ -18,6 +19,12 @@ class UserAddressService implements UserAddressServiceInterface */ protected $locationService; + /** + * @Inject + * @var DistributionPriceServiceInterface + */ + protected $distributionPriceService; + public function do($userAddressId,$user_id,$user_name,$address,$doorplate,$gender,$lat,$lng,$tel,$tags) { $userAddress = UserAddress::updateOrCreate(['id' => $userAddressId], @@ -71,43 +78,16 @@ class UserAddressService implements UserAddressServiceInterface * @param $marketId * @return false|float */ - public function getAddressAndDistributionRrice($userAddressId,$marketId) + public function getAddressAndDistributionPrice($userAddressId,$marketId) { $address = $this->get($userAddressId); $market = Market::query()->select('lng','lat')->find($marketId); $distance = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat); - $distributionRrice = $this->calculateDistributionRrice($distance); + $distributionPrice = $this->distributionPriceService->do($distance); $res['address'] = $address; - $res['distribution_price'] = $distributionRrice; + $res['distribution_price'] = $distributionPrice; return $res; } - /** - * @param $distance - * @return false|float - */ - function calculateDistributionRrice($distance) - { - $km = ceil($distance/1000); - switch ($km){ - case ($km > 3 && $km < 5) : - $distributionRrice = bcmul(0.70,($km-3),2); - break; - case ($km >= 5 && $km < 7) : - $distributionRrice = bcmul(1.00,($km-3),2); - break; - case ($km >= 7 && $km < 10) : - $distributionRrice = bcmul(1.50,($km-3),2); - break; - case ($km >= 10) : - $distributionRrice = bcmul(1.50,($km-3),2); - // throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); - break; - default: - $distributionRrice = 0; - break; - } - $distributionRrice = bcadd($distributionRrice,3.50,2); - return $distributionRrice; - } + } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/DistributionPriceServiceInterface.php b/app/Service/v3/Interfaces/DistributionPriceServiceInterface.php index 4d6ec8f..5c9d12f 100644 --- a/app/Service/v3/Interfaces/DistributionPriceServiceInterface.php +++ b/app/Service/v3/Interfaces/DistributionPriceServiceInterface.php @@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces; interface DistributionPriceServiceInterface { - public function do(); + public function do($distance); public function check(); diff --git a/app/Service/v3/Interfaces/UserAddressServiceInterface.php b/app/Service/v3/Interfaces/UserAddressServiceInterface.php index 4b2b5dc..f9b6253 100644 --- a/app/Service/v3/Interfaces/UserAddressServiceInterface.php +++ b/app/Service/v3/Interfaces/UserAddressServiceInterface.php @@ -12,5 +12,5 @@ interface UserAddressServiceInterface public function get($userAddressId); public function getList($userId); public function setDefault($userId,$userAddressId); - public function getAddressAndDistributionRrice($userAddressId,$marketId); + public function getAddressAndDistributionPrice($userAddressId,$marketId); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 876a8f4..5fe3632 100644 --- a/config/routes.php +++ b/config/routes.php @@ -138,7 +138,7 @@ Router::addGroup('/v3/', function () { Router::post('user/oflOrders', 'App\Controller\v3\OrderListController@offlineForUser'); Router::post('shopCart/delete', 'App\Controller\v3\ShopCartUpdateController@delete'); Router::post('withdraw/pageByStore', 'App\Controller\v3\WithdrawController@pageByStore'); - Router::post('userAddress/getAddressAndDistributionRrice', 'App\Controller\v3\UserAddressController@getAddressAndDistributionRrice'); + Router::post('userAddress/getAddressAndDistributionPrice', 'App\Controller\v3\UserAddressController@getAddressAndDistributionPrice'); Router::post('withdraw/applyByStore', 'App\Controller\v3\WithdrawController@applyByStore'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); From 37c76e85f6dcee493c4b8c4ea397b8b638386dac Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 10 Sep 2020 12:09:15 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E6=92=92=E5=A4=A7=E8=8B=8F=E6=89=93?= =?UTF-8?q?=E6=92=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/ShopCartUpdateController.php | 10 ++--- .../v3/Implementations/ActivityService.php | 2 +- .../Implementations/ShopCartUpdateService.php | 38 +++++++++++++++---- .../ShopCartUpdateServiceInterface.php | 2 +- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/app/Controller/v3/ShopCartUpdateController.php b/app/Controller/v3/ShopCartUpdateController.php index c6dc577..fae561c 100644 --- a/app/Controller/v3/ShopCartUpdateController.php +++ b/app/Controller/v3/ShopCartUpdateController.php @@ -15,11 +15,11 @@ class ShopCartUpdateController extends BaseController protected $shopCarServiceUpdate; public function update(ShopCartUpdateRequest $request) { - $user_id = $this->request->input('user_id',0); - $goods_id = $this->request->input('goods_id',0); - $num = $this->request->input('num',''); - $activity_type = $this->request->input('activity_type',1); - $res = $this->shopCarServiceUpdate->do($user_id,$goods_id,$num,$activity_type); + $userId = $this->request->input('user_id',0); + $goodsId = $this->request->input('goods_id',0); + $num = $this->request->input('num',0); + $activityType = $this->request->input('activity_type',1); + $res = $this->shopCarServiceUpdate->do($userId,$goodsId,$num,$activityType); return $this->success($res); } diff --git a/app/Service/v3/Implementations/ActivityService.php b/app/Service/v3/Implementations/ActivityService.php index 15cbc6e..3f3cfc4 100644 --- a/app/Service/v3/Implementations/ActivityService.php +++ b/app/Service/v3/Implementations/ActivityService.php @@ -31,7 +31,7 @@ class ActivityService implements ActivityServiceInterface ->where(['type' => $type]); if ($marketId != -1) { - $builder = $builder->whereJsonContains('market_ids', [(string)$marketId]); + $builder = $builder->where('market_id', $marketId); } return $builder->get()->toArray(); diff --git a/app/Service/v3/Implementations/ShopCartUpdateService.php b/app/Service/v3/Implementations/ShopCartUpdateService.php index b927d11..1ec6eb7 100644 --- a/app/Service/v3/Implementations/ShopCartUpdateService.php +++ b/app/Service/v3/Implementations/ShopCartUpdateService.php @@ -4,33 +4,57 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\ErrorCode; use App\Exception\ErrorCodeException; +use App\Service\v3\Interfaces\GoodsActivityServiceInterface; +use App\Service\v3\Interfaces\GoodsServiceInterface; use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface; use App\Model\v3\ShoppingCart; use App\Model\v3\Goods; use App\Model\v3\GoodsActivity; use App\Constants\v3\Goods as GoodsConstants; +use Hyperf\Di\Annotation\Inject; class ShopCartUpdateService implements ShopCartUpdateServiceInterface { - public function do($user_id,$goods_id,$num,$activity_type) + /** + * @Inject + * @var GoodsServiceInterface + */ + protected $goodsService; + + /** + * @Inject + * @var GoodsActivityServiceInterface + */ + protected $goodsActivityService; + + public function do($userId,$goodsId,$num,$activityType) { $goodsType = ''; //判断是普通商品还是特价商品 - if($activity_type == GoodsConstants::IS_ACTIVITY){ + if($activityType == GoodsConstants::IS_ACTIVITY){ $builder = GoodsActivity::query(); $goodsType = GoodsActivity::class; - }else{ + $goodsModel = $builder->find($goodsId); + $goodsCheck = $this->goodsActivityService->check($goodsModel,$num,$userId); + }else{ $builder = Goods::query(); $goodsType = Goods::class; + $goodsModel = $builder->find($goodsId); + $goodsCheck = $this->goodsService->check($goodsModel,$num); } - $goods = $builder->select('market_id','store_id')->find($goods_id); if(empty($goods)){ throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); } + + if($goodsCheck !== true) + { + throw new ErrorCodeException($goodsCheck); + } + return ShoppingCart::query()->updateOrCreate( [ - 'user_id' => $user_id, - 'goods_id' => $goods_id, - 'activity_type' => $activity_type + 'user_id' => $userId, + 'goods_id' => $goodsId, + 'activity_type' => $activityType ], [ 'market_id' => $goods->market_id, diff --git a/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php b/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php index 8400f2f..bc66830 100644 --- a/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php +++ b/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php @@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces; interface ShopCartUpdateServiceInterface { - public function do($user_id,$goods_id,$num,$activity_type); + public function do($userId,$goodsId,$num,$activityType); public function check(); From a01d8f7e1dcc04af2052b88da75c6c17c5dba03c Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 10 Sep 2020 12:10:34 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/OrderOnlineController.php | 2 +- app/Request/v3/OrderOnlineDetailRequest.php | 2 +- app/Service/v3/Implementations/OrderOnlineService.php | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 797afa0..0468bc5 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -128,7 +128,7 @@ class OrderOnlineController extends BaseController public function detailByUser(OrderOnlineDetailRequest $request) { $params = $request->validated(); - return $this->success(['detail' => $this->orderOnlineService->detailByUser($params['order_id'], $params['user_id'])]); + return $this->success(['detail' => $this->orderOnlineService->detailByUser($params['global_order_id'], $params['user_id'])]); } /** diff --git a/app/Request/v3/OrderOnlineDetailRequest.php b/app/Request/v3/OrderOnlineDetailRequest.php index 92dacbd..9da42ce 100644 --- a/app/Request/v3/OrderOnlineDetailRequest.php +++ b/app/Request/v3/OrderOnlineDetailRequest.php @@ -15,7 +15,7 @@ class OrderOnlineDetailRequest extends BaseFormRequest public function rules(): array { return [ - 'order_id' => 'required|nonempty|integer', + 'global_order_id' => 'required|nonempty|integer', 'user_id' => 'required|nonempty|integer', ]; } diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index 7ce5089..e301f3c 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -24,6 +24,7 @@ use App\Model\v3\UserAddress; use App\Service\v3\Interfaces\CouponRecServiceInterface; use App\Service\v3\Interfaces\CouponServiceInterface; use App\Service\v3\Interfaces\DeliveryMoneyServiceInterface; +use App\Service\v3\Interfaces\DistributionPriceServiceInterface; use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\GoodsServiceInterface; use App\Service\v3\Interfaces\PaymentServiceInterface; @@ -48,7 +49,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface /** * @Inject - * @var DeliveryMoneyServiceInterface + * @var DistributionPriceServiceInterface */ protected $deliveryService; From 9f487ee890c158bf7ac01fc9d7b251c877a42d5f Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 10 Sep 2020 14:04:52 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E4=BD=BF=E7=94=A8=E6=A0=A1=E9=AA=8C=E3=80=81=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E8=AE=A2=E5=8D=95=E6=93=8D=E4=BD=9C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/TestController.php | 113 +++++++++++++----- app/Middleware/Auth/UserMiddleware.php | 2 - app/Model/v3/Goods.php | 3 +- app/Model/v3/GoodsActivity.php | 3 +- app/Model/v3/Order.php | 2 +- .../Implementations/DeliveryMoneyService.php | 24 ---- .../Implementations/GoodsActivityService.php | 4 +- .../v3/Implementations/MiniprogramService.php | 4 +- .../v3/Implementations/MqttService.php | 4 +- .../v3/Implementations/OrderOnlineService.php | 91 ++++++-------- .../DeliveryMoneyServiceInterface.php | 10 -- 11 files changed, 132 insertions(+), 128 deletions(-) delete mode 100644 app/Service/v3/Implementations/DeliveryMoneyService.php delete mode 100644 app/Service/v3/Interfaces/DeliveryMoneyServiceInterface.php diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php index a4135b5..7542347 100644 --- a/app/Controller/TestController.php +++ b/app/Controller/TestController.php @@ -7,16 +7,23 @@ namespace App\Controller; use App\Constants\v3\LogLabel; use App\Constants\v3\OrderState; use App\Constants\v3\OrderType; +use App\Constants\v3\SsdbKeys; use App\Libs\FeiePrintClient; +use App\Model\v3\Order; +use App\Model\v3\OrderGoods; use App\Model\v3\OrderMain; use App\Service\v3\Interfaces\CouponRebateServiceInterface; +use App\Service\v3\Interfaces\CouponServiceInterface; use App\Service\v3\Interfaces\DeviceServiceInterface; use App\Service\v3\Interfaces\FeiePrintServiceInterface; +use App\Service\v3\Interfaces\FinancialRecordServiceInterface; +use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\MiniprogramServiceInterface; use App\Service\v3\Interfaces\MqttServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; use App\Service\v3\Interfaces\UserServiceInterface; +use Hyperf\DbConnection\Db; use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\HttpServer\Annotation\AutoController; use Hyperf\Utils\Coroutine; @@ -74,6 +81,12 @@ class TestController extends AbstractController */ protected $couponRebateService; + /** + * @Inject + * @var CouponServiceInterface + */ + protected $couponService; + /** * @Inject * @var OrderOnlineServiceInterface @@ -86,6 +99,18 @@ class TestController extends AbstractController */ protected $separateAccountsService; + /** + * @Inject + * @var GoodsActivityServiceInterface + */ + protected $goodsActivityService; + + /** + * @Inject + * @var FinancialRecordServiceInterface + */ + protected $financialService; + public function index1(RequestInterface $request) { // $container = ApplicationContext::getContainer(); @@ -128,13 +153,13 @@ class TestController extends AbstractController // return $result; // } - $orderMainId = $this->request->input('order_main_id'); + $globalOrderId = $this->request->input('order_main_id'); // 查询订单 $orderMain = OrderMain::query() ->where([ - 'id' => $orderMainId, + 'global_order_id' => $globalOrderId, 'type' => OrderType::ONLINE, - 'state' => OrderState::UNPAID + 'state' => OrderState::REFUNDING ]) ->first(); @@ -142,48 +167,82 @@ class TestController extends AbstractController if (empty($orderMain)) { $this->log->event( LogLabel::ORDER_OFFLINE_PAY_NOTIFY_LOG, - ['global_order_id_fail' => $orderMainId] + ['global_order_id_fail' => $globalOrderId] ); return true; } - // $orderPaid = $this->orderOfflineService->doPaid($orderMainId); + + // 线下回调 + // $orderPaid = $this->orderOfflineService->doPaid($globalOrderId); // var_dump('orderOfflineService', $orderPaid); - // $separate = $this->separateAccountsService->orderOfflinePaid($orderMainId); + // $separate = $this->separateAccountsService->orderOfflinePaid($globalOrderId); // var_dump('separateAccountsService', $separate); // // // 喇叭通知,兼容旧音响,MQTT+IOT - // $res = $this->mqttService->speakToStore($orderMainId); + // $res = $this->mqttService->speakToStore($globalOrderId); // var_dump('mqttService', $res); - // $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMainId); + // $res = $this->deviceService->pubMsgToStoreByOrderMainId($globalOrderId); // var_dump('deviceService', $res); // // // 公众号模板消息 - // $res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMainId); + // $res = $this->miniprogramService->sendTemMsgForOfflineOrder($globalOrderId); // var_dump('miniprogramService', $res); + // 线上回调 + // $res = $this->orderOnlineService->doByPaid($globalOrderId); + // var_dump('orderOnlineService', $res); + // $res = $this->separateAccountsService->orderOnlinePaid($globalOrderId); + // var_dump('separateAccountsService', $res); + // + // // 优惠券返券 + // $res = $this->couponRebateService->couponRebateInTask($globalOrderId); + // var_dump('couponRebateService', $res); + // + // // 喇叭通知,兼容旧音响,MQTT+IOT + // $res = $this->mqttService->speakToStore($globalOrderId); + // var_dump('mqttService', $res); + // $res = $this->deviceService->pubMsgToStoreByOrderMainId($globalOrderId); + // var_dump('deviceService', $res); + // + // // 公众号模板消息 + // $res = $this->miniprogramService->sendTemMsgForOnlineOrder($globalOrderId); + // var_dump('miniprogramService', $res); + // + // // 打印订单,自动打印 + // $res = $this->feiePrintService->feiePrint($globalOrderId); + // var_dump('feiePrintService', $res); - $res = $this->orderOnlineService->doByPaid($orderMainId); - var_dump('orderOnlineService', $res); - $res = $this->separateAccountsService->orderOnlinePaid($orderMainId); - var_dump('separateAccountsService', $res); + // 退款回调 + // 添加退款时间 + $orderMain->refund_time = time(); + $orderMain->state = OrderState::REFUNDED; + $res = $orderMain->save(); + var_dump('$orderMain', $res); + + // 退款返还优惠券 + $res = $this->couponService->orderRefundCoupons($orderMain->global_order_id); + var_dump('couponService', $res); + + // 处理特价商品缓存 + $orderChildren = Order::query()->where(['order_main_id' => $orderMain->global_order_id])->get()->toArray(); + $orderGoods = OrderGoods::query() + ->where(['activity_type' => 2]) + ->whereIn('order_id', array_values(array_column($orderChildren, 'id')))->get(); + foreach ($orderGoods as $key => &$item) { + $this->goodsActivityService->clearCacheRecord($item['goods_id'], $item['number'], $orderMain->userId); + } - // 优惠券返券 - $res = $this->couponRebateService->couponRebateInTask($orderMainId); - var_dump('couponRebateService', $res); + var_dump('$orderChildren', $orderChildren); - // 喇叭通知,兼容旧音响,MQTT+IOT - $res = $this->mqttService->speakToStore($orderMainId); - var_dump('mqttService', $res); - $res = $this->deviceService->pubMsgToStoreByOrderMainId($orderMainId); - var_dump('deviceService', $res); + // 添加用户的流水 + $res = $this->financialService->userByOLOrderRefund($orderMain->user_id, $orderMain->global_order_id, $orderMain->money); + var_dump('financialService', $res); - // 公众号模板消息 - $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMainId); - var_dump('miniprogramService', $res); + // 记录badge + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + $res = $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'refund', 1); + var_dump('$ssdb', $res); - // 打印订单,自动打印 - $res = $this->feiePrintService->feiePrint($orderMainId); - var_dump('feiePrintService', $res); } public function index2(RequestInterface $request) diff --git a/app/Middleware/Auth/UserMiddleware.php b/app/Middleware/Auth/UserMiddleware.php index ab0abc1..d727cd7 100644 --- a/app/Middleware/Auth/UserMiddleware.php +++ b/app/Middleware/Auth/UserMiddleware.php @@ -2,8 +2,6 @@ namespace App\Middleware\Auth; -use App\Model\v3\User; -use App\TaskWorker\SSDBTask; use Hashids\Hashids; use Hyperf\HttpServer\Contract\RequestInterface as HttpRequest; use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse; diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index 1c90965..c0718cb 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -100,7 +100,8 @@ class Goods extends Model public function getCartNumAttribute() { - return (integer)$this->shopCartService->check($this->request->user->id, $this->id); + $userId = $this->request->user->id ?? 0; + return $userId ? (integer)$this->shopCartService->check($userId, $this->id) : 0; } public function getIsEffectiveAttribute() diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index 9e59936..7ff6a34 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -67,7 +67,8 @@ class GoodsActivity extends Model public function getCartNumAttribute() { - return (integer)$this->shopCartService->check($this->request->user->id, $this->id); + $userId = $this->request->user->id ?? 0; + return $userId ? (integer)$this->shopCartService->check($userId, $this->id) : 0; } public function getIsEffectiveAttribute() diff --git a/app/Model/v3/Order.php b/app/Model/v3/Order.php index 99bf36b..44eae8e 100644 --- a/app/Model/v3/Order.php +++ b/app/Model/v3/Order.php @@ -46,7 +46,7 @@ class Order extends Model public function orderMain() { - return $this->belongsTo(OrderMain::class, 'order_main_id', 'id'); + return $this->belongsTo(OrderMain::class, 'order_main_id', 'global_order_id'); } public function user() diff --git a/app/Service/v3/Implementations/DeliveryMoneyService.php b/app/Service/v3/Implementations/DeliveryMoneyService.php deleted file mode 100644 index fc97aed..0000000 --- a/app/Service/v3/Implementations/DeliveryMoneyService.php +++ /dev/null @@ -1,24 +0,0 @@ -on_sale == Goods::ON_SALE_NO || !is_null($goods->deleted_at)){ + if($goods->on_sale == 0 || !is_null($goods->deleted_at)){ return ErrorCode::GOODS_ACTIVITY_ON_SALE_NO; } // 商品库存不足 - if($goods->is_infinite != Goods::IS_INVENTORY && $goods->inventory < $num){ + if($goods->is_infinite != 1 && $goods->inventory < $num){ return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; } diff --git a/app/Service/v3/Implementations/MiniprogramService.php b/app/Service/v3/Implementations/MiniprogramService.php index 27d2476..4996a93 100644 --- a/app/Service/v3/Implementations/MiniprogramService.php +++ b/app/Service/v3/Implementations/MiniprogramService.php @@ -44,8 +44,8 @@ class MiniprogramService implements MiniprogramServiceInterface $goods_temp = []; foreach ($order_goods as $k => &$goods) { - array_push($goods_temp, $goods['name']."*".$goods['number']."/".($goods['spec']?:$goods['goods_unit'])); - array_push($goods_temp_all, $goods['name']."*".$goods['number']."/".($goods['spec']?:$goods['goods_unit'])); + array_push($goods_temp, $goods['name']."*".$goods['number']."/".($goods['goods_unit'])); + array_push($goods_temp_all, $goods['name']."*".$goods['number']."/".($goods['goods_unit'])); } // 商户/门店的openid diff --git a/app/Service/v3/Implementations/MqttService.php b/app/Service/v3/Implementations/MqttService.php index 4a508a3..e3fab9a 100644 --- a/app/Service/v3/Implementations/MqttService.php +++ b/app/Service/v3/Implementations/MqttService.php @@ -24,7 +24,7 @@ class MqttService implements MqttServiceInterface if ($isMain) { $orders = $orders->where(['order_main_id' => $globalOrderId])->get(); } else { - $orders = $orders->where(['global_order_id' => $globalOrderId])->get(); + $orders = $orders->where(['id' => $globalOrderId])->get(); } if(empty($orders)) return; @@ -37,6 +37,8 @@ class MqttService implements MqttServiceInterface // 发布订阅消息 $this->publish($template, config('mqtt.topic'), $to_client_id); } + + return true; } /** diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index e301f3c..c953aa9 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -23,12 +23,11 @@ use App\Model\v3\Store; use App\Model\v3\UserAddress; use App\Service\v3\Interfaces\CouponRecServiceInterface; use App\Service\v3\Interfaces\CouponServiceInterface; -use App\Service\v3\Interfaces\DeliveryMoneyServiceInterface; -use App\Service\v3\Interfaces\DistributionPriceServiceInterface; use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\GoodsServiceInterface; use App\Service\v3\Interfaces\PaymentServiceInterface; use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface; +use App\Service\v3\Interfaces\UserAddressServiceInterface; use App\TaskWorker\SSDBTask; use Exception; use Hyperf\Database\Model\Model; @@ -49,9 +48,9 @@ class OrderOnlineService implements OrderOnlineServiceInterface /** * @Inject - * @var DistributionPriceServiceInterface + * @var UserAddressServiceInterface */ - protected $deliveryService; + protected $userAddressService; /** * @Inject @@ -110,11 +109,17 @@ class OrderOnlineService implements OrderOnlineServiceInterface $currentTime = time(); bcscale(6); // 用户收货地址 - $userAddr = UserAddress::query()->find($userAddrId); // 获取配送费用 - $deliveryAmount = $this->deliveryService->do($userAddr->lat, $userAddr->lng); - // 优惠券数据 - $couponRec = CouponRec::query()->lockForUpdate()->whereIn('id', $receiveCouponIds)->get()->toArray(); + $userAddrAndDPrice = $this->userAddressService->getAddressAndDistributionPrice($userAddrId, $marketId); + $userAddr = $userAddrAndDPrice['address']; + $deliveryAmount = $userAddrAndDPrice['distribution_price']; + // 优惠券数据,当前订单可用个优惠券 + $couponRecs = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId); + $canRealUseCoupons = $couponRecs['available']; + $canRealUseCouponRecIds = array_values(array_column($canRealUseCoupons, 'id')); + if (!empty(array_diff($receiveCouponIds, $canRealUseCouponRecIds))) { + throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[优惠券不可用]'.$receiveCouponIds.'_'.$canRealUseCouponRecIds); + } // 处理购物车数据,计算订单金额、子订单数据处理等 $totalAmount = 0; # 实付金额 @@ -146,49 +151,27 @@ class OrderOnlineService implements OrderOnlineServiceInterface $carts = ShoppingCart::query()->whereIn('id', $cartIds)->where(['market_id' => $marketId, 'user_id' => $userId])->get(); foreach ($carts as $k => &$cart) { - // 查个商品 + // 查个商品,做商品有效的判断检查 $goods = []; if ($cart->activity_type == 1) { - $goods = Goods::query()->lockForUpdate()->find($cart->goods_id); + $goods = Goods::query()->lockForUpdate()->with('store')->find($cart->goods_id); + if (empty($goods)) { + throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE, '[商品失效1]'.$cart->goods_id); + } $check = $this->goodsService->check($goods, $cart->num); if (true !== $check) { - throw new ErrorCodeException($check, '[商品失效1]'.$cart->goods_id); + throw new ErrorCodeException($check, '[商品失效2]'.$cart->goods_id); } } elseif ($cart->activity_type == 2) { - $goods = GoodsActivity::query()->lockForUpdate()->find($cart->goods_id); + $goods = GoodsActivity::query()->lockForUpdate()->with('store')->find($cart->goods_id); + if (empty($goods)) { + throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE, '[商品失效3]'.$cart->goods_id); + } $check = $this->goodsActivityService->check($goods, $cart->num, $userId); if (true !== $check) { - throw new ErrorCodeException($check, '[商品失效2]'.$cart->goods_id); - } - - // 活动商品不可用优惠券 - if ($goods->can_use_coupon!=1 && $receiveCouponIds) { - throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[商品失效]'.$cart->goods_id); + throw new ErrorCodeException($check, '[商品失效4]'.$cart->goods_id); } - // 活动商品可用优惠券,再校验这些优惠券是不是可以在当前活动类型可用 - // receiveCouponIds中是不是有当前活动不可用的优惠券 - $couponIds = array_values(array_column($couponRec, 'coupon_id')); - $couponsActivityAvailable = Coupon::query() - ->select(['id']) - ->whereJsonContains('activity_available', [(string)$goods->type]) - ->whereJsonContains('market_ids', [(string)$goods->market_id]) - ->whereIn('id', $couponIds) - ->get()->toArray(); - $couponsActivityAvailableIds = array_values(array_column($couponsActivityAvailable, 'id')); - if (!empty(array_diff($couponIds, $couponsActivityAvailableIds))) { - throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[商品失效]'.json_encode($couponsActivityAvailableIds)); - } - - } - - if (empty($goods)) { - throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE); - } - - // 库存判断 - if ($goods->is_infinite !=1 && $goods->inventory < $cart->num) { - throw new ErrorCodeException(ErrorCode::ORDER_GOODS_INVENTORY_LIMIT); } // 算金额 @@ -228,31 +211,25 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 优惠券的使用 $couponMoney = 0; - if (!empty($couponRec)) { - $couponsCanUse = $this->couponRecService->allForOrderOlAvailable($totalAmount, $userId, $marketId, 2, $storeTypeIds); - $couponCanUseIds = array_column($couponsCanUse, 'id'); - $couponCanUseIds = array_intersect($couponCanUseIds, $receiveCouponIds); - $couponCannotUseIds = array_diff($receiveCouponIds, $couponCanUseIds); - - if (empty($couponCanUseIds)||!empty($couponCannotUseIds)) { - throw new ErrorCodeException(ErrorCode::COUPON_NOT_AVAILABLE); - } + if (!empty($receiveCouponIds)) { // 计算红包折扣金额 - foreach ($couponsCanUse as $key => $coupon) { - if (!in_array($coupon->id, $receiveCouponIds)) { + foreach ($canRealUseCoupons as $key => &$coupon) { + if (!in_array($coupon['id'], $receiveCouponIds)) { + unset($coupon); continue; } - if ($coupon->discount_type == Coupon::DISCOUNT_TYPE_CASH) { - $couponMoney = bcadd($couponMoney, $coupon->discounts, 2); - } elseif ($coupon->discount_type == Coupon::DISCOUNT_TYPE_RATE) { - $discountRate = bcdiv($coupon->discounts,10); + if ($coupon['coupon']['discount_type'] == Coupon::DISCOUNT_TYPE_CASH) { + $couponMoney = bcadd($couponMoney, $coupon['coupon']['discounts'], 2); + } elseif ($coupon['coupon']['discount_type'] == Coupon::DISCOUNT_TYPE_RATE) { + $discountRate = bcdiv($coupon['coupon']['discounts'],10); $discountRate = bcsub(1,$discountRate); $discountMoney = bcmul($orderAmount, $discountRate); $couponMoney = bcadd($couponMoney, $discountMoney, 2); } } + } // 获取分布式全局ID @@ -324,7 +301,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface } // 优惠券红包使用记录 - $this->couponService->orderUseCoupons($globalOrderId, $couponRec); + $this->couponService->orderUseCoupons($globalOrderId, $canRealUseCoupons); Db::commit(); diff --git a/app/Service/v3/Interfaces/DeliveryMoneyServiceInterface.php b/app/Service/v3/Interfaces/DeliveryMoneyServiceInterface.php deleted file mode 100644 index 046a4df..0000000 --- a/app/Service/v3/Interfaces/DeliveryMoneyServiceInterface.php +++ /dev/null @@ -1,10 +0,0 @@ -