Browse Source

Merge branch 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf into phoenix

* 'phoenix' of http://120.24.33.109:11081/hyzjshwo/lanzu_api_hyperf:
  订单优惠券使用校验、用户订单操作调整
  用户订单详情
  撒大苏打撒
  配送费
  临时提交改用global_order_id
  确认订单
  增值服务text
  确认订单
master
Mike 6 years ago
parent
commit
fe61182050
  1. 6
      app/Constants/v3/ErrorCode.php
  2. 10
      app/Constants/v3/LogLabel.php
  3. 113
      app/Controller/TestController.php
  4. 149
      app/Controller/v3/NotifyController.php
  5. 25
      app/Controller/v3/OrderOnlineController.php
  6. 10
      app/Controller/v3/ShopCartUpdateController.php
  7. 4
      app/Controller/v3/UserAddressController.php
  8. 87
      app/JsonRpc/OrderOnlineService.php
  9. 8
      app/JsonRpc/OrderOnlineServiceInterface.php
  10. 83
      app/JsonRpc/OrderService.php
  11. 10
      app/JsonRpc/SeparateAccountsServiceInterface.php
  12. 28
      app/JsonRpc/SeparateaccountsService.php
  13. 2
      app/Middleware/Auth/UserMiddleware.php
  14. 3
      app/Model/v3/Goods.php
  15. 3
      app/Model/v3/GoodsActivity.php
  16. 2
      app/Model/v3/Order.php
  17. 2
      app/Request/v3/OrderOnlineDetailRequest.php
  18. 2
      app/Request/v3/OrderOnlineStateRequest.php
  19. 2
      app/Service/v3/Implementations/ActivityService.php
  20. 10
      app/Service/v3/Implementations/CouponRebateService.php
  21. 10
      app/Service/v3/Implementations/CouponService.php
  22. 24
      app/Service/v3/Implementations/DeliveryMoneyService.php
  23. 6
      app/Service/v3/Implementations/DeviceService.php
  24. 24
      app/Service/v3/Implementations/DistributionPriceService.php
  25. 4
      app/Service/v3/Implementations/FeiePrintService.php
  26. 4
      app/Service/v3/Implementations/GoodsActivityService.php
  27. 14
      app/Service/v3/Implementations/MiniprogramService.php
  28. 8
      app/Service/v3/Implementations/MqttService.php
  29. 7
      app/Service/v3/Implementations/OrderOfflineService.php
  30. 154
      app/Service/v3/Implementations/OrderOnlineService.php
  31. 59
      app/Service/v3/Implementations/PaymentService.php
  32. 29
      app/Service/v3/Implementations/SeparateAccountsService.php
  33. 38
      app/Service/v3/Implementations/ShopCartUpdateService.php
  34. 41
      app/Service/v3/Implementations/UserAddressService.php
  35. 18
      app/Service/v3/Implementations/UserService.php
  36. 8
      app/Service/v3/Interfaces/CouponServiceInterface.php
  37. 10
      app/Service/v3/Interfaces/DeliveryMoneyServiceInterface.php
  38. 2
      app/Service/v3/Interfaces/DistributionPriceServiceInterface.php
  39. 8
      app/Service/v3/Interfaces/MiniprogramServiceInterface.php
  40. 2
      app/Service/v3/Interfaces/OrderOfflineServiceInterface.php
  41. 38
      app/Service/v3/Interfaces/OrderOnlineServiceInterface.php
  42. 2
      app/Service/v3/Interfaces/PaymentServiceInterface.php
  43. 12
      app/Service/v3/Interfaces/SeparateAccountsServiceInterface.php
  44. 2
      app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php
  45. 2
      app/Service/v3/Interfaces/UserAddressServiceInterface.php
  46. 16
      app/Service/v3/Interfaces/UserServiceInterface.php
  47. 1
      config/autoload/wechat.php
  48. 3
      config/routes.php

6
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 */
/************************************/

10
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设备绑定")
*/

113
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)

149
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()));
}
}

25
app/Controller/v3/OrderOnlineController.php

@ -93,27 +93,26 @@ 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();
//
$res['store_list'] = $this->shopCartService->getGoodsByShopcartId($shopcartIds);
//获取用户优惠券
$res['coupon'] = $this->couponRecService->allForOnlineOrderAvailable($userId, $marketId);
//获取配送费
$res['distribution_price'] = '5.0';
//增值服务接口
$res['value_added_service'] = [
'text' => '买鸡买鸭,免费帮杀;买瓜买黇,包熟包甜',
'select' => 1,
'price' => 3.50
];
$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);
}
@ -128,7 +127,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'])]);
}
/**
@ -172,7 +171,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 +183,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 +195,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 +207,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 +222,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([]);

10
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);
}

4
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]);
}

87
app/JsonRpc/OrderOnlineService.php

@ -1,87 +0,0 @@
<?php
namespace App\JsonRpc;
use App\Commons\Log;
use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use Hyperf\DbConnection\Db;
use Hyperf\RpcServer\Annotation\RpcService;
use Hyperf\Di\Annotation\Inject;
use App\Constants\v3\LogLabel;
/**
* @RpcService(name="OrderOnlineService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="")
*/
class OrderOnlineService implements OrderOnlineServiceInterface
{
/**
* @Inject
* @var Log
*/
protected $log;
/**
* @Inject
* @var \App\Service\v3\Interfaces\OrderOnlineServiceInterface
*/
protected $orderOnlineService;
/**
* @Inject
* @var SeparateAccountsServiceInterface
*/
protected $separateAccountsService;
public function onlineComplete($orderMainId, $userId)
{
Db::beginTransaction();
try {
$this->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;
}
}

8
app/JsonRpc/OrderOnlineServiceInterface.php

@ -1,8 +0,0 @@
<?php
namespace App\JsonRpc;
interface OrderOnlineServiceInterface
{
public function onlineComplete($orderMainId, $userId);
}

83
app/JsonRpc/OrderService.php

@ -3,12 +3,15 @@
namespace App\JsonRpc;
use App\Commons\Log;
use App\Constants\ErrorCode;
use App\Service\SeparateAccountsServiceInterface;
use App\Constants\v3\ErrorCode;
use App\Constants\v3\LogLabel;
use App\Exception\ErrorCodeException;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use Hyperf\DbConnection\Db;
use Hyperf\RpcServer\Annotation\RpcService;
use Hyperf\Di\Annotation\Inject;
use App\Constants\LogLabel;
use function AlibabaCloud\Client\json;
/**
* @RpcService(name="OrderService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="")
@ -24,9 +27,9 @@ class OrderService implements OrderServiceInterface
/**
* @Inject
* @var \App\Service\OrderServiceInterface
* @var OrderOnlineServiceInterface
*/
protected $orderService;
protected $orderOnlineService;
/**
* @Inject
@ -34,58 +37,62 @@ class OrderService implements OrderServiceInterface
*/
protected $separateAccountsService;
public function onlineComplete($global_order_id)
/**
* 订单完成
* @param $global_order_id
* @param $user_id
* @return array
*/
public function onlineComplete($global_order_id, $user_id)
{
Db::beginTransaction();
try {
$this->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;
}
}

10
app/JsonRpc/SeparateAccountsServiceInterface.php

@ -1,10 +0,0 @@
<?php
namespace App\JsonRpc;
interface SeparateAccountsServiceInterface
{
public function orderOnlineCompleted($orderMainId, $userId);
}

28
app/JsonRpc/SeparateaccountsService.php

@ -1,28 +0,0 @@
<?php
namespace App\JsonRpc;
use Hyperf\RpcServer\Annotation\RpcService;
use Hyperf\Di\Annotation\Inject;
/**
* @RpcService(name="SeparateaccountsService", protocol="jsonrpc-http", server="jsonrpc-http", publishTo="")
* Class SeparateAccountsService
* @package App\JsonRpc
*/
class SeparateaccountsService implements SeparateAccountsServiceInterface
{
/**
* @Inject
* @var \App\Service\v3\Interfaces\SeparateAccountsServiceInterface
*/
private $separateaccountsService;
public function orderOnlineCompleted($orderMainId, $userId)
{
// TODO: Implement orderOnlineCompleted() method.
return $this->separateaccountsService->orderOnlineCompleted($orderMainId, $userId);
}
}

2
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;

3
app/Model/v3/Goods.php

@ -110,7 +110,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()

3
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()

2
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()

2
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',
];
}

2
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',
];
}

2
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();

10
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,

10
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)) {

24
app/Service/v3/Implementations/DeliveryMoneyService.php

@ -1,24 +0,0 @@
<?php
namespace App\Service\v3\Implementations;
use App\Service\v3\Interfaces\DeliveryMoneyServiceInterface;
class DeliveryMoneyService implements DeliveryMoneyServiceInterface
{
public function do($lat, $lng)
{
return 5.0;
}
public function check()
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
}

6
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;

24
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()

4
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()

4
app/Service/v3/Implementations/GoodsActivityService.php

@ -38,12 +38,12 @@ class GoodsActivityService implements GoodsActivityServiceInterface
}
// 商品下架或已删除
if($goods->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;
}

14
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 = [];
@ -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
@ -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();

8
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(['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;
}
/**

7
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)) {

154
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;
@ -24,11 +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\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 DeliveryMoneyServiceInterface
* @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
@ -293,11 +270,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 +301,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface
}
// 优惠券红包使用记录
$this->couponService->orderUseCoupons($orderMainId, $couponRec);
$this->couponService->orderUseCoupons($globalOrderId, $canRealUseCoupons);
Db::commit();
@ -345,10 +321,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 +342,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 +374,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 +392,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface
/**
* @inheritDoc
*/
public function doByPaid($orderMainId)
public function doByPaid($globalOrderId)
{
Db::beginTransaction();
try {
@ -425,7 +401,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 +412,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface
// 更新商品库存和销量
$orders = Order::query()
->where(['order_main_id' => $orderMain->id])
->where(['order_main_id' => $globalOrderId])
->get()
->toArray();
@ -508,10 +484,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 +500,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 +513,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 +531,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 +543,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);
}
}
}

59
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());
}
}
/**

29
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;
}

38
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,

41
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,42 +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) :
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE);
break;
default:
$distributionRrice = 0;
break;
}
$distributionRrice = bcadd($distributionRrice,3.50,2);
return $distributionRrice;
}
}

18
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();
}

8
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);
}

10
app/Service/v3/Interfaces/DeliveryMoneyServiceInterface.php

@ -1,10 +0,0 @@
<?php
namespace App\Service\v3\Interfaces;
interface DeliveryMoneyServiceInterface
{
public function do($lat, $lng);
public function check();
public function undo();
}

2
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();

8
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);
/**
* 奖励模板消息

2
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);
}

38
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);
}

2
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');
}

12
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);
}

2
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();

2
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);
}

16
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);
}

1
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'),

3
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]]);
@ -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');
});
Loading…
Cancel
Save