StoreOrderSuccessServices.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\StorePinkServices;
  14. use app\services\activity\StoreSeckillServices;
  15. use app\services\BaseServices;
  16. use app\services\pay\PayServices;
  17. use app\services\product\product\StoreProductCouponServices;
  18. use app\services\user\UserBillServices;
  19. use app\services\user\UserServices;
  20. use app\jobs\ProductLogJob;
  21. use think\exception\ValidateException;
  22. /**
  23. * Class StoreOrderSuccessServices
  24. * @package app\services\order
  25. * @method getOne(array $where, ?string $field = '*', array $with = []) 获取去一条数据
  26. */
  27. class StoreOrderSuccessServices extends BaseServices
  28. {
  29. /**
  30. *
  31. * StoreOrderSuccessServices constructor.
  32. * @param StoreOrderDao $dao
  33. */
  34. public function __construct(StoreOrderDao $dao)
  35. {
  36. $this->dao = $dao;
  37. }
  38. /**
  39. * 0元支付
  40. * @param array $orderInfo
  41. * @param int $uid
  42. * @return bool
  43. * @throws \think\Exception
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. * @throws \think\exception\DbException
  47. */
  48. public function zeroYuanPayment(array $orderInfo, int $uid, string $payType = PayServices::YUE_PAY)
  49. {
  50. if ($orderInfo['paid']) {
  51. throw new ValidateException('该订单已支付!');
  52. }
  53. /** @var UserServices $services */
  54. $services = app()->make(UserServices::class);
  55. $userInfo = $services->getUserInfo($uid);
  56. /** @var UserBillServices $userBillServices */
  57. $userBillServices = app()->make(UserBillServices::class);
  58. $res = $userBillServices->income('pay_product', $userInfo['uid'], $orderInfo['pay_price'], $userInfo['now_money'], $orderInfo['id']);
  59. $res = $res && $this->paySuccess($orderInfo, $payType);//余额支付成功
  60. return $res;
  61. }
  62. /**
  63. * 支付成功
  64. * @param array $orderInfo
  65. * @param string $paytype
  66. * @return bool
  67. */
  68. public function paySuccess(array $orderInfo, string $paytype = PayServices::WEIXIN_PAY, array $other = [])
  69. {
  70. $updata = ['paid' => 1, 'pay_type' => $paytype, 'pay_time' => time()];
  71. if ($other && isset($other['trade_no'])) {
  72. $updata['trade_no'] = $other['trade_no'];
  73. }
  74. $res1 = $this->dao->update($orderInfo['id'], $updata);
  75. $resPink = true;
  76. if ($orderInfo['combination_id'] && $res1 && !$orderInfo['refund_status']) {
  77. /** @var StorePinkServices $pinkServices */
  78. $pinkServices = app()->make(StorePinkServices::class);
  79. /** @var StoreOrderServices $orderServices */
  80. $orderServices = app()->make(StoreOrderServices::class);
  81. $resPink = $pinkServices->createPink($orderServices->tidyOrder($orderInfo, true));//创建拼团
  82. }
  83. //订单支付成功后置事件
  84. event('order.orderPaySuccess', [$orderInfo]);
  85. $res = $res1 && $resPink;
  86. return false !== $res;
  87. }
  88. }