StoreOrderInvoiceController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\controller\api\v2\order;
  12. use app\services\order\StoreOrderInvoiceServices;
  13. use app\services\order\StoreOrderServices;
  14. use app\services\system\attachment\SystemAttachmentServices;
  15. use app\services\store\SystemStoreServices;
  16. use crmeb\services\UtilService;
  17. use think\Request;
  18. /**
  19. * Class StoreOrderInvoiceController
  20. * @package app\controller\api\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. if (!$order_id) return app('json')->fail('请选择要开票订单');
  48. if (!$invoice_id) return app('json')->fail('请选择发票');
  49. $uid = (int)$request->uid;
  50. return app('json')->successful($this->services->makeUp($uid, $order_id, (int)$invoice_id));
  51. }
  52. /**
  53. * 开票记录
  54. * @param Request $request
  55. * @return mixed
  56. */
  57. public function list(Request $request)
  58. {
  59. $uid = (int)$request->uid();
  60. return app('json')->successful($this->services->getOrderInvoiceList(['uid' => $uid]));
  61. }
  62. /**
  63. * 订单详情
  64. * @param \app\Request $request
  65. * @param $uni
  66. * @return mixed
  67. */
  68. public function detail(StoreOrderServices $services,Request $request, $uni)
  69. {
  70. if (!strlen(trim($uni))) return app('json')->fail('参数错误');
  71. $order = $services->getUserOrderDetail($uni, (int)$request->uid());
  72. if (!$order) return app('json')->fail('订单不存在');
  73. $order = $order->toArray();
  74. $orderInvoice = $this->services->getOne(['order_id'=>$order['id']]);
  75. $order['invoice'] = $orderInvoice;
  76. //门店是否开启 || 门店自提是否开启
  77. if (!sys_config('store_func_status', 1) || !sys_config('store_self_mention')) {
  78. //关闭门店自提后 订单隐藏门店信息
  79. $order['shipping_type'] = 1;
  80. }
  81. if ($order['verify_code']) {
  82. $verify_code = $order['verify_code'];
  83. $verify[] = substr($verify_code, 0, 4);
  84. $verify[] = substr($verify_code, 4, 4);
  85. $verify[] = substr($verify_code, 8);
  86. $order['_verify_code'] = implode(' ', $verify);
  87. }
  88. $order['add_time_y'] = date('Y-m-d', $order['add_time']);
  89. $order['add_time_h'] = date('H:i:s', $order['add_time']);
  90. /** @var SystemStoreServices $storeServices */
  91. $storeServices = app()->make(SystemStoreServices::class);
  92. $order['system_store'] = $storeServices->getStoreDispose($order['store_id']);
  93. if (($order['shipping_type'] === 2 || $order['delivery_uid'] != 0) && $order['verify_code']) {
  94. $name = $order['verify_code'] . '.jpg';
  95. /** @var SystemAttachmentServices $attachmentServices */
  96. $attachmentServices = app()->make(SystemAttachmentServices::class);
  97. $imageInfo = $attachmentServices->getInfo(['name' => $name]);
  98. $siteUrl = sys_config('site_url');
  99. if (!$imageInfo) {
  100. $imageInfo = UtilService::getQRCodePath($order['verify_code'], $name);
  101. if (is_array($imageInfo)) {
  102. $attachmentServices->attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
  103. $url = $imageInfo['dir'];
  104. } else
  105. $url = '';
  106. } else $url = $imageInfo['att_dir'];
  107. if (isset($imageInfo['image_type']) && $imageInfo['image_type'] == 1) $url = $siteUrl . $url;
  108. $order['code'] = $url;
  109. }
  110. $order['mapKey'] = sys_config('tengxun_map_key');
  111. $order['yue_pay_status'] = (int)sys_config('balance_func_status') && (int)sys_config('yue_pay_status') == 1 ? (int)1 : (int)2;//余额支付 1 开启 2 关闭
  112. $order['pay_weixin_open'] = (int)sys_config('pay_weixin_open') ?? 0;//微信支付 1 开启 0 关闭
  113. $order['ali_pay_status'] = (bool)sys_config('ali_pay_status');//支付包支付 1 开启 0 关闭
  114. return app('json')->successful('ok', $services->tidyOrder($order, true, true));
  115. }
  116. }