StoreOrderSuccessServices.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\order;
  12. use app\dao\order\StoreOrderDao;
  13. use app\services\activity\lottery\LuckLotteryServices;
  14. use app\services\activity\combination\StorePinkServices;
  15. use app\services\BaseServices;
  16. use app\services\pay\PayServices;
  17. use crmeb\exceptions\ApiException;
  18. /**
  19. * Class StoreOrderSuccessServices
  20. * @package app\services\order
  21. * @method getOne(array $where, ?string $field = '*', array $with = []) 获取去一条数据
  22. */
  23. class StoreOrderSuccessServices extends BaseServices
  24. {
  25. /**
  26. *
  27. * StoreOrderSuccessServices constructor.
  28. * @param StoreOrderDao $dao
  29. */
  30. public function __construct(StoreOrderDao $dao)
  31. {
  32. $this->dao = $dao;
  33. }
  34. /**
  35. * 0元支付
  36. * @param array $orderInfo
  37. * @param int $uid
  38. * @return bool
  39. * @throws \think\Exception
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. * @throws \think\exception\DbException
  43. */
  44. public function zeroYuanPayment(array $orderInfo, int $uid, string $payType = PayServices::YUE_PAY)
  45. {
  46. if ($orderInfo['paid']) {
  47. throw new ApiException(410265);
  48. }
  49. return $this->paySuccess($orderInfo, $payType);//余额支付成功
  50. }
  51. /**
  52. * 支付成功
  53. * @param array $orderInfo
  54. * @param string $paytype
  55. * @param array $other
  56. * @return bool
  57. * @throws \Psr\SimpleCache\InvalidArgumentException
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function paySuccess(array $orderInfo, string $paytype = PayServices::WEIXIN_PAY, array $other = [])
  63. {
  64. $updata = ['paid' => 1, 'pay_type' => $paytype, 'pay_time' => time()];
  65. $orderInfo['pay_time'] = $updata['pay_time'];
  66. $orderInfo['pay_type'] = $paytype;
  67. if ($other && isset($other['trade_no'])) {
  68. $updata['trade_no'] = $other['trade_no'];
  69. }
  70. /** @var StoreOrderCartInfoServices $orderInfoServices */
  71. $orderInfoServices = app()->make(StoreOrderCartInfoServices::class);
  72. $orderInfo['storeName'] = $orderInfoServices->getCarIdByProductTitle((int)$orderInfo['id']);
  73. $res1 = $this->dao->update($orderInfo['id'], $updata);
  74. $resPink = true;
  75. if ($orderInfo['combination_id'] && $res1 && !$orderInfo['refund_status']) {
  76. /** @var StorePinkServices $pinkServices */
  77. $pinkServices = app()->make(StorePinkServices::class);
  78. /** @var StoreOrderServices $orderServices */
  79. $orderServices = app()->make(StoreOrderServices::class);
  80. $resPink = $pinkServices->createPink($orderServices->tidyOrder($orderInfo, true));//创建拼团
  81. }
  82. //缓存抽奖次数 除过线下支付
  83. if (isset($orderInfo['pay_type']) && $orderInfo['pay_type'] != 'offline') {
  84. /** @var LuckLotteryServices $luckLotteryServices */
  85. $luckLotteryServices = app()->make(LuckLotteryServices::class);
  86. $luckLotteryServices->setCacheLotteryNum((int)$orderInfo['uid'], 'order');
  87. }
  88. $orderInfo['send_name'] = $orderInfo['real_name'];
  89. //订单支付成功后置事件
  90. event('OrderPaySuccessListener', [$orderInfo]);
  91. //用户推送消息事件
  92. event('NoticeListener', [$orderInfo, 'order_pay_success']);
  93. //支付成功给客服发送消息
  94. event('NoticeListener', [$orderInfo, 'admin_pay_success_code']);
  95. // 推送订单
  96. event('OutPushListener', ['order_pay_push', ['order_id' => (int)$orderInfo['id']]]);
  97. // 小程序订单管理 (自提商品)
  98. if ($orderInfo['shipping_type'] == 2) {
  99. event('OrderShipping', ['product', $orderInfo, 4, '', '']);
  100. }
  101. $res = $res1 && $resPink;
  102. return false !== $res;
  103. }
  104. }