OrderOfflineServices.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\pay;
  12. use app\services\activity\combination\StorePinkServices;
  13. use app\services\BaseServices;
  14. use app\services\order\StoreOrderDeliveryServices;
  15. use app\services\order\StoreOrderInvoiceServices;
  16. use app\services\order\StoreOrderServices;
  17. use app\services\order\StoreOrderStatusServices;
  18. use app\jobs\ProductLogJob;
  19. use app\services\user\UserServices;
  20. use app\services\statistic\CapitalFlowServices;
  21. use crmeb\exceptions\ApiException;
  22. /**
  23. * 线下支付
  24. * Class OrderOfflineServices
  25. * @package app\services\pay
  26. */
  27. class OrderOfflineServices extends BaseServices
  28. {
  29. /**
  30. * 线下支付
  31. * @param int $id
  32. * @return mixed
  33. */
  34. public function orderOffline(int $id)
  35. {
  36. /** @var StoreOrderServices $orderSerives */
  37. $orderSerives = app()->make(StoreOrderServices::class);
  38. $orderInfo = $orderSerives->get($id);
  39. if (!$orderInfo) {
  40. throw new ApiException(410173);
  41. }
  42. if ($orderInfo->paid) {
  43. throw new ApiException(410174);
  44. }
  45. $orderInfo->paid = 1;
  46. $orderInfo->pay_time = time();
  47. /** @var StoreOrderStatusServices $statusService */
  48. $statusService = app()->make(StoreOrderStatusServices::class);
  49. $res = $statusService->save([
  50. 'oid' => $id,
  51. 'change_type' => 'offline',
  52. 'change_message' => '线下付款',
  53. 'change_time' => time()
  54. ]);
  55. //修改开票数据支付状态
  56. $orderInvoiceServices = app()->make(StoreOrderInvoiceServices::class);
  57. $orderInvoiceServices->update(['order_id' => $orderInfo['id']], ['is_pay' => 1]);
  58. /** @var CapitalFlowServices $capitalFlowServices */
  59. $capitalFlowServices = app()->make(CapitalFlowServices::class);
  60. /** @var UserServices $userServices */
  61. $userServices = app()->make(UserServices::class);
  62. $userInfo = $userServices->get($orderInfo['uid']);
  63. $orderInfo['nickname'] = $userInfo['nickname'];
  64. $orderInfo['phone'] = $userInfo['phone'];
  65. $capitalFlowServices->setFlow($orderInfo, 'order');
  66. // 拼团订单创建拼团
  67. if ($orderInfo['combination_id']) {
  68. $tidyOrder = app()->make(StoreOrderServices::class)->tidyOrder($orderInfo->toArray(), true);
  69. app()->make(StorePinkServices::class)->createPink($tidyOrder);
  70. }
  71. //虚拟商品自动发货
  72. if ($orderInfo['virtual_type'] > 0) {
  73. /** @var StoreOrderDeliveryServices $orderDeliveryServices */
  74. $orderDeliveryServices = app()->make(StoreOrderDeliveryServices::class);
  75. $orderDeliveryServices->virtualSend($orderInfo);
  76. }
  77. //支付记录
  78. ProductLogJob::dispatch(['pay', ['uid' => $orderInfo['uid'], 'order_id' => $orderInfo['id']]]);
  79. return $res && $orderInfo->save();
  80. }
  81. }