StoreOrderSuccessServices.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. if ($other && isset($other['trade_no'])) {
  67. $updata['trade_no'] = $other['trade_no'];
  68. }
  69. /** @var StoreOrderCartInfoServices $orderInfoServices */
  70. $orderInfoServices = app()->make(StoreOrderCartInfoServices::class);
  71. $orderInfo['storeName'] = $orderInfoServices->getCarIdByProductTitle((int)$orderInfo['id']);
  72. $res1 = $this->dao->update($orderInfo['id'], $updata);
  73. $resPink = true;
  74. if ($orderInfo['combination_id'] && $res1 && !$orderInfo['refund_status']) {
  75. /** @var StorePinkServices $pinkServices */
  76. $pinkServices = app()->make(StorePinkServices::class);
  77. /** @var StoreOrderServices $orderServices */
  78. $orderServices = app()->make(StoreOrderServices::class);
  79. $resPink = $pinkServices->createPink($orderServices->tidyOrder($orderInfo, true));//创建拼团
  80. }
  81. //缓存抽奖次数 除过线下支付
  82. if (isset($orderInfo['pay_type']) && $orderInfo['pay_type'] != 'offline') {
  83. /** @var LuckLotteryServices $luckLotteryServices */
  84. $luckLotteryServices = app()->make(LuckLotteryServices::class);
  85. $luckLotteryServices->setCacheLotteryNum((int)$orderInfo['uid'], 'order');
  86. }
  87. $orderInfo['send_name'] = $orderInfo['real_name'];
  88. //订单支付成功后置事件
  89. event('order.orderPaySuccess', [$orderInfo]);
  90. //用户推送消息事件
  91. event('notice.notice', [$orderInfo, 'order_pay_success']);
  92. //支付成功给客服发送消息
  93. event('notice.notice', [$orderInfo, 'admin_pay_success_code']);
  94. // 推送订单
  95. event('out.outPush', ['order_pay_push', ['order_id' => (int)$orderInfo['id']]]);
  96. $res = $res1 && $resPink;
  97. return false !== $res;
  98. }
  99. }