StoreIntegralOrder.php 11 KB

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