OrderOfflineServices.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\pay;
  12. use app\services\BaseServices;
  13. use app\services\order\StoreOrderInvoiceServices;
  14. use app\services\order\StoreOrderServices;
  15. use app\services\order\StoreOrderStatusServices;
  16. use app\jobs\ProductLogJob;
  17. use think\exception\ValidateException;
  18. /**
  19. * 线下支付
  20. * Class OrderOfflineServices
  21. * @package app\services\pay
  22. */
  23. class OrderOfflineServices extends BaseServices
  24. {
  25. /**
  26. * 线下支付
  27. * @param int $id
  28. * @return mixed
  29. */
  30. public function orderOffline(int $id)
  31. {
  32. /** @var StoreOrderServices $orderSerives */
  33. $orderSerives = app()->make(StoreOrderServices::class);
  34. $orderInfo = $orderSerives->get($id);
  35. if (!$orderInfo) {
  36. throw new ValidateException('订单不存在');
  37. }
  38. if ($orderInfo->paid) {
  39. throw new ValidateException('订单已支付');
  40. }
  41. $orderInfo->paid = 1;
  42. $orderInfo->pay_time = time();
  43. /** @var StoreOrderStatusServices $statusService */
  44. $statusService = app()->make(StoreOrderStatusServices::class);
  45. $res = $statusService->save([
  46. 'oid' => $id,
  47. 'change_type' => 'offline',
  48. 'change_message' => '线下付款',
  49. 'change_time' => time()
  50. ]);
  51. //修改开票数据支付状态
  52. $orderInvoiceServices = app()->make(StoreOrderInvoiceServices::class);
  53. $orderInvoiceServices->update(['order_id' => $orderInfo['id']], ['is_pay' => 1]);
  54. //支付记录
  55. ProductLogJob::dispatch(['pay', ['uid' => $orderInfo['uid'], 'order_id' => $orderInfo['id']]]);
  56. return $res && $orderInfo->save();
  57. }
  58. }