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