StoreOrderSuccessServices.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\activity\combination\StorePinkServices;
  15. use app\services\BaseServices;
  16. use app\services\pay\PayServices;
  17. use think\exception\ValidateException;
  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 ValidateException('该订单已支付!');
  48. }
  49. return $this->paySuccess($orderInfo, $payType);//余额支付成功
  50. }
  51. /**
  52. * 支付成功
  53. * @param array $orderInfo
  54. * @param string $paytype
  55. * @return bool
  56. */
  57. public function paySuccess(array $orderInfo, string $paytype = PayServices::WEIXIN_PAY, array $other = [])
  58. {
  59. $updata = ['paid' => 1, 'pay_type' => $paytype, 'pay_time' => time()];
  60. if ($other && isset($other['trade_no'])) {
  61. $updata['trade_no'] = $other['trade_no'];
  62. }
  63. $res1 = $this->dao->update($orderInfo['id'], $updata);
  64. $resPink = true;
  65. if ($orderInfo['combination_id'] && $res1 && !$orderInfo['refund_status']) {
  66. /** @var StorePinkServices $pinkServices */
  67. $pinkServices = app()->make(StorePinkServices::class);
  68. /** @var StoreOrderServices $orderServices */
  69. $orderServices = app()->make(StoreOrderServices::class);
  70. $resPink = $pinkServices->createPink($orderServices->tidyOrder($orderInfo, true));//创建拼团
  71. }
  72. //缓存抽奖次数 除过线下支付
  73. if (isset($orderInfo['pay_type']) && $orderInfo['pay_type'] != 'offline') {
  74. /** @var LuckLotteryServices $luckLotteryServices */
  75. $luckLotteryServices = app()->make(LuckLotteryServices::class);
  76. $luckLotteryServices->setCacheLotteryNum((int)$orderInfo['uid'], 'order');
  77. }
  78. //订单支付成功后置事件
  79. event('order.orderPaySuccess', [$orderInfo]);
  80. //用户推送消息事件
  81. event('notice.notice', [$orderInfo, 'order_pay_success']);
  82. //支付成功给客服发送消息
  83. event('notice.notice', [$orderInfo, 'admin_pay_success_code']);
  84. $res = $res1 && $resPink;
  85. return false !== $res;
  86. }
  87. }