StoreOrderSuccessServices.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\jobs\integral\IntegralJob;
  14. use app\services\activity\lottery\LuckLotteryServices;
  15. use app\services\BaseServices;
  16. use app\services\pay\PayServices;
  17. use app\services\user\UserServices;
  18. use crmeb\traits\ServicesTrait;
  19. use think\exception\ValidateException;
  20. /**
  21. * Class StoreOrderSuccessServices
  22. * @package app\services\order
  23. * @mixin StoreOrderDao
  24. */
  25. class StoreOrderSuccessServices extends BaseServices
  26. {
  27. use ServicesTrait;
  28. /**
  29. *
  30. * StoreOrderSuccessServices constructor.
  31. * @param StoreOrderDao $dao
  32. */
  33. public function __construct(StoreOrderDao $dao)
  34. {
  35. $this->dao = $dao;
  36. }
  37. /**
  38. * 0元支付
  39. * @param array $orderInfo
  40. * @param int $uid
  41. * @return bool
  42. * @throws \think\Exception
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\ModelNotFoundException
  45. * @throws \think\exception\DbException
  46. */
  47. public function zeroYuanPayment(array $orderInfo, int $uid, string $payType = PayServices::YUE_PAY)
  48. {
  49. $id = $orderInfo['id'] ?? 0;
  50. if (!$orderInfo || !$id) {
  51. throw new ValidateException('订单不存在!');
  52. }
  53. //更新订单信息
  54. $orderInfo = $this->dao->get($id);
  55. if (!$orderInfo) {
  56. throw new ValidateException('订单不存在');
  57. }
  58. $orderInfo = $orderInfo->toArray();
  59. if ($orderInfo['paid']) {
  60. throw new ValidateException('该订单已支付!');
  61. }
  62. return $this->paySuccess($orderInfo, $payType);//余额支付成功
  63. }
  64. /**
  65. * 支付成功
  66. * @param array $orderInfo
  67. * @param string $paytype
  68. * @return bool
  69. */
  70. public function paySuccess(array $orderInfo, string $paytype = PayServices::WEIXIN_PAY, array $other = [])
  71. {
  72. $updata = ['paid' => 1, 'pay_type' => $paytype, 'pay_time' => time()];
  73. if ($other && isset($other['trade_no'])) {
  74. $updata['trade_no'] = $other['trade_no'];
  75. }
  76. $res1 = $this->dao->update($orderInfo['id'], $updata);
  77. $orderInfo['trade_no'] = $other['trade_no'] ?? '';
  78. $orderInfo['pay_time'] = time();
  79. $orderInfo['pay_type'] = $paytype;
  80. //缓存抽奖次数 除过线下支付
  81. if (isset($orderInfo['pay_type']) && $orderInfo['pay_type'] != 'offline') {
  82. /** @var LuckLotteryServices $luckLotteryServices */
  83. $luckLotteryServices = app()->make(LuckLotteryServices::class);
  84. $luckLotteryServices->setCacheLotteryNum((int)$orderInfo['uid'], 'order');
  85. }
  86. IntegralJob::dispatchDo('dealOrderIntegral', [$orderInfo]);
  87. //门店
  88. // if ($orderInfo['shipping_type'] == 4) {
  89. // //订单发货
  90. // OrderDeliveryJob::dispatch([$orderInfo, [], 4]);
  91. // //订单收货
  92. // OrderTakeJob::dispatch([$orderInfo]);
  93. // }
  94. //订单支付成功事件
  95. $userInfo = app()->make(UserServices::class)->get($orderInfo['uid']);
  96. event('order.pay', [$orderInfo, $userInfo]);
  97. $res = $res1;
  98. return false !== $res;
  99. }
  100. }