StoreIntegralOrder.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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\adminapi\controller\v1\marketing\integral;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\serve\ServeServices;
  14. use app\services\activity\integral\{
  15. StoreIntegralOrderServices,
  16. StoreIntegralOrderStatusServices
  17. };
  18. use app\services\order\StoreOrderDeliveryServices;
  19. use app\services\shipping\ExpressServices;
  20. use app\services\user\UserServices;
  21. use think\facade\App;
  22. /**
  23. * 订单管理
  24. * Class StoreOrder
  25. * @package app\controller\admin\v1\order
  26. */
  27. class StoreIntegralOrder extends AuthController
  28. {
  29. /**
  30. * StoreIntegralOrder constructor.
  31. * @param App $app
  32. * @param StoreIntegralOrderServices $service
  33. * @method temp
  34. */
  35. public function __construct(App $app, StoreIntegralOrderServices $service)
  36. {
  37. parent::__construct($app);
  38. $this->services = $service;
  39. }
  40. /**
  41. * 获取订单类型数量
  42. * @return mixed
  43. */
  44. public function chart()
  45. {
  46. $where = $this->request->getMore([
  47. ['data', '', '', 'time'],
  48. ['product_id', '']
  49. ]);
  50. $data = $this->services->orderCount($where);
  51. return app('json')->success($data);
  52. }
  53. /**
  54. * 获取订单列表
  55. * @return mixed
  56. */
  57. public function lst()
  58. {
  59. $where = $this->request->getMore([
  60. ['status', ''],
  61. ['real_name', ''],
  62. ['data', '', '', 'time'],
  63. ['order', ''],
  64. ['field_key', ''],
  65. ['product_id', '']
  66. ]);
  67. $where['is_system_del'] = 0;
  68. return app('json')->success($this->services->getOrderList($where, ['*']));
  69. }
  70. /**
  71. * 获取快递公司
  72. * @return mixed
  73. */
  74. public function express(ExpressServices $services)
  75. {
  76. [$status] = $this->request->getMore([
  77. ['status', ''],
  78. ], true);
  79. if ($status != '') $data['status'] = $status;
  80. $data['is_show'] = 1;
  81. return app('json')->success($services->express($data));
  82. }
  83. /**
  84. * 批量删除用户已经删除的订单
  85. * @return mixed
  86. */
  87. public function del_orders()
  88. {
  89. [$ids, $all, $where] = $this->request->postMore([
  90. ['ids', []],
  91. ['where', []],
  92. ], true);
  93. if ($this->services->delOrders($ids)) {
  94. return app('json')->success(100002);
  95. } else {
  96. return app('json')->fail(100008);
  97. }
  98. }
  99. /**
  100. * 删除订单
  101. * @param $id
  102. * @return mixed
  103. */
  104. public function del($id)
  105. {
  106. if ($this->services->delOrder($id)) {
  107. return app('json')->success(100002);
  108. } else {
  109. return app('json')->fail(100008);
  110. }
  111. }
  112. /**
  113. * 订单发送货
  114. * @param $id
  115. * @return mixed
  116. */
  117. public function update_delivery($id)
  118. {
  119. $data = $this->request->postMore([
  120. ['type', 1],
  121. ['delivery_name', ''],//快递公司名称
  122. ['delivery_id', ''],//快递单号
  123. ['delivery_code', ''],//快递公司编码
  124. ['express_record_type', 2],//发货记录类型
  125. ['express_temp_id', ""],//电子面单模板
  126. ['to_name', ''],//寄件人姓名
  127. ['to_tel', ''],//寄件人电话
  128. ['to_addr', ''],//寄件人地址
  129. ['sh_delivery_name', ''],//送货人姓名
  130. ['sh_delivery_id', ''],//送货人电话
  131. ['sh_delivery_uid', ''],//送货人ID
  132. ['fictitious_content', '']//虚拟发货内容
  133. ]);
  134. $this->services->delivery((int)$id, $data);
  135. return app('json')->success(100010);
  136. }
  137. /**
  138. * 确认收货
  139. * @param $id
  140. * @return mixed
  141. */
  142. public function take_delivery($id)
  143. {
  144. if (!$id) return app('json')->fail(100100);
  145. $order = $this->services->get($id);
  146. if (!$order)
  147. return app('json')->fail(100026);
  148. if ($order['status'] == 3)
  149. return app('json')->fail(400114);
  150. if ($order['status'] == 2)
  151. $data['status'] = 3;
  152. else
  153. return app('json')->fail(400115);
  154. if (!$this->services->update($id, $data)) {
  155. return app('json')->fail(400116);
  156. } else {
  157. //增加收货订单状态
  158. /** @var StoreIntegralOrderStatusServices $statusService */
  159. $statusService = app()->make(StoreIntegralOrderStatusServices::class);
  160. $statusService->save([
  161. 'oid' => $order['id'],
  162. 'change_type' => 'take_delivery',
  163. 'change_message' => '已收货',
  164. 'change_time' => time()
  165. ]);
  166. return app('json')->success(400117);
  167. }
  168. }
  169. /**
  170. * 订单详情
  171. * @param $id 订单id
  172. * @return mixed
  173. */
  174. public function order_info($id)
  175. {
  176. if (!$id || !($orderInfo = $this->services->get($id))) {
  177. return app('json')->fail(400118);
  178. }
  179. /** @var UserServices $services */
  180. $services = app()->make(UserServices::class);
  181. $userInfo = $services->get($orderInfo['uid']);
  182. if (!$userInfo) return app('json')->fail(400119);
  183. $userInfo = $userInfo->hidden(['pwd', 'add_ip', 'last_ip', 'login_type']);
  184. $orderInfo = $this->services->tidyOrder($orderInfo->toArray());
  185. $userInfo = $userInfo->toArray();
  186. return app('json')->success(compact('orderInfo', 'userInfo'));
  187. }
  188. /**
  189. * 查询物流信息
  190. * @param $id 订单id
  191. * @return mixed
  192. */
  193. public function get_express($id, ExpressServices $services)
  194. {
  195. if (!$id || !($orderInfo = $this->services->get($id)))
  196. return app('json')->fail(400118);
  197. if ($orderInfo['delivery_type'] != 'express' || !$orderInfo['delivery_id'])
  198. return app('json')->fail(400120);
  199. $cacheName = 'integral' . $orderInfo['order_id'] . $orderInfo['delivery_id'];
  200. $data['delivery_name'] = $orderInfo['delivery_name'];
  201. $data['delivery_id'] = $orderInfo['delivery_id'];
  202. $data['result'] = $services->query($cacheName, $orderInfo['delivery_id'], $orderInfo['delivery_code'] ?? null, $orderInfo['user_phone']);
  203. return app('json')->success($data);
  204. }
  205. /**
  206. * 获取修改配送信息表单结构
  207. * @param $id 订单id
  208. * @return mixed
  209. * @throws \FormBuilder\Exception\FormBuilderException
  210. */
  211. public function distribution($id)
  212. {
  213. if (!$id) {
  214. return app('json')->fail(400118);
  215. }
  216. return app('json')->success($this->services->distributionForm((int)$id));
  217. }
  218. /**
  219. * 修改配送信息
  220. * @param $id 订单id
  221. * @return mixed
  222. */
  223. public function update_distribution($id)
  224. {
  225. $data = $this->request->postMore([['delivery_name', ''], ['delivery_code', ''], ['delivery_id', '']]);
  226. if (!$id) return app('json')->fail(100100);
  227. $this->services->updateDistribution($id, $data);
  228. return app('json')->success(100001);
  229. }
  230. /**
  231. * 修改备注
  232. * @param $id
  233. * @return mixed
  234. */
  235. public function remark($id)
  236. {
  237. $data = $this->request->postMore([['remark', '']]);
  238. if ($this->services->remark($id, $data['remark'])) {
  239. return app('json')->success(100024);
  240. } else {
  241. return app('json')->fail(100025);
  242. }
  243. }
  244. /**
  245. * 获取订单状态列表并分页
  246. * @param $id
  247. * @return mixed
  248. */
  249. public function status(StoreIntegralOrderStatusServices $services, $id)
  250. {
  251. if (!$id) return app('json')->fail(100100);
  252. return app('json')->success($services->getStatusList(['oid' => $id])['list']);
  253. }
  254. /**
  255. * 易联云打印机打印
  256. * @param $id
  257. * @return mixed
  258. */
  259. public function order_print($id)
  260. {
  261. if (!$id) return app('json')->fail(100100);
  262. $order = $this->services->get($id);
  263. if (!$order) {
  264. return app('json')->fail(400118);
  265. }
  266. $res = $this->services->orderPrint($order);
  267. if ($res) {
  268. return app('json')->success(400121);
  269. } else {
  270. return app('json')->fail(400122);
  271. }
  272. }
  273. /**
  274. * 电子面单模板
  275. * @param $com
  276. * @return mixed
  277. */
  278. public function expr_temp(ServeServices $services, $com)
  279. {
  280. if (!$com) {
  281. return app('json')->fail(400123);
  282. }
  283. $list = $services->express()->temp($com);
  284. return app('json')->success($list);
  285. }
  286. /**
  287. * 获取模板
  288. */
  289. public function express_temp(ServeServices $services)
  290. {
  291. $data = $this->request->getMore([['com', '']]);
  292. $tpd = $services->express()->temp($data['com']);
  293. return app('json')->success($tpd['data']);
  294. }
  295. /**
  296. * 订单发货后打印电子面单
  297. * @param $order_id
  298. * @param StoreOrderDeliveryServices $storeOrderDeliveryServices
  299. * @return mixed
  300. */
  301. public function order_dump($order_id, StoreOrderDeliveryServices $storeOrderDeliveryServices)
  302. {
  303. return app('json')->success($storeOrderDeliveryServices->orderDump($order_id));
  304. }
  305. /**
  306. * 获取配置信息
  307. * @return mixed
  308. */
  309. public function getDeliveryInfo()
  310. {
  311. return app('json')->success([
  312. 'express_temp_id' => sys_config('config_export_temp_id'),
  313. 'id' => sys_config('config_export_id'),
  314. 'to_name' => sys_config('config_export_to_name'),
  315. 'to_tel' => sys_config('config_export_to_tel'),
  316. 'to_add' => sys_config('config_export_to_address'),
  317. 'export_open' => (bool)((int)sys_config('config_export_open'))
  318. ]);
  319. }
  320. }