StoreOrderInvoiceController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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\api\controller\v2\order;
  12. use app\services\order\StoreOrderInvoiceServices;
  13. use app\services\order\StoreOrderServices;
  14. use app\services\other\PosterServices;
  15. use app\services\system\attachment\SystemAttachmentServices;
  16. use app\services\system\store\SystemStoreServices;
  17. use think\Request;
  18. /**
  19. * Class StoreOrderInvoiceController
  20. * @package app\api\controller\v2\order
  21. */
  22. class StoreOrderInvoiceController
  23. {
  24. /**
  25. * @var StoreOrderInvoiceServices
  26. */
  27. protected $services;
  28. /**
  29. * StoreOrderInvoiceController constructor.
  30. * @param StoreOrderInvoiceServices $services
  31. */
  32. public function __construct(StoreOrderInvoiceServices $services)
  33. {
  34. $this->services = $services;
  35. }
  36. /**
  37. * 订单开票
  38. * @param Request $request
  39. * @return mixed
  40. */
  41. public function makeUp(Request $request)
  42. {
  43. [$order_id, $invoice_id] = $request->postMore([
  44. ['order_id', 0],
  45. ['invoice_id', 0]
  46. ], true);
  47. $uid = (int)$request->uid;
  48. return app('json')->success($this->services->makeUp($uid, $order_id, (int)$invoice_id));
  49. }
  50. /**
  51. * 开票记录
  52. * @param Request $request
  53. * @return mixed
  54. */
  55. public function list(Request $request)
  56. {
  57. $uid = (int)$request->uid();
  58. return app('json')->success($this->services->getOrderInvoiceList(['uid' => $uid]));
  59. }
  60. /**
  61. * 订单详情
  62. * @param \app\Request $request
  63. * @param $uni
  64. * @return mixed
  65. */
  66. public function detail(StoreOrderServices $services, Request $request, $uni)
  67. {
  68. if (!strlen(trim($uni))) return app('json')->fail(100100);
  69. $order = $services->getUserOrderDetail($uni, (int)$request->uid(), []);
  70. if (!$order) return app('json')->fail(410173);
  71. $order = $order->toArray();
  72. $orderInvoice = $this->services->getOne(['order_id' => $order['id']]);
  73. $order['invoice'] = $orderInvoice;
  74. //是否开启门店自提
  75. $store_self_mention = sys_config('store_self_mention');
  76. //关闭门店自提后 订单隐藏门店信息
  77. if ($store_self_mention == 0) $order['shipping_type'] = 1;
  78. if ($order['verify_code']) {
  79. $verify_code = $order['verify_code'];
  80. $verify[] = substr($verify_code, 0, 4);
  81. $verify[] = substr($verify_code, 4, 4);
  82. $verify[] = substr($verify_code, 8);
  83. $order['_verify_code'] = implode(' ', $verify);
  84. }
  85. $order['add_time_y'] = date('Y-m-d', $order['add_time']);
  86. $order['add_time_h'] = date('H:i:s', $order['add_time']);
  87. /** @var SystemStoreServices $storeServices */
  88. $storeServices = app()->make(SystemStoreServices::class);
  89. $order['system_store'] = $storeServices->getStoreDispose($order['store_id']);
  90. if (($order['shipping_type'] === 2 || $order['delivery_uid'] != 0) && $order['verify_code']) {
  91. $name = $order['verify_code'] . '.jpg';
  92. /** @var SystemAttachmentServices $attachmentServices */
  93. $attachmentServices = app()->make(SystemAttachmentServices::class);
  94. $imageInfo = $attachmentServices->getInfo(['name' => $name]);
  95. $siteUrl = sys_config('site_url');
  96. if (!$imageInfo) {
  97. $imageInfo = PosterServices::getQRCodePath($order['verify_code'], $name);
  98. if (is_array($imageInfo)) {
  99. $attachmentServices->attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
  100. $url = $imageInfo['dir'];
  101. } else
  102. $url = '';
  103. } else $url = $imageInfo['att_dir'];
  104. if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url;
  105. $order['code'] = $url;
  106. }
  107. $order['mapKey'] = sys_config('tengxun_map_key');
  108. $order['yue_pay_status'] = (int)sys_config('balance_func_status') && (int)sys_config('yue_pay_status') == 1 ? (int)1 : (int)2;//余额支付 1 开启 2 关闭
  109. $order['pay_weixin_open'] = (int)sys_config('pay_weixin_open') ?? 0;//微信支付 1 开启 0 关闭
  110. $order['ali_pay_status'] = (bool)sys_config('ali_pay_status');//支付宝支付 1 开启 0 关闭
  111. return app('json')->success($services->tidyOrder($order, true, true));
  112. }
  113. }