StoreOrderSuccessServices.php 3.6 KB

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