Order.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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\store\order;
  12. use app\controller\store\AuthController;
  13. use app\Request;
  14. use app\services\other\export\ExportServices;
  15. use app\services\order\OtherOrderServices;
  16. use app\services\order\store\WriteOffOrderServices;
  17. use app\services\order\StoreOrderDeliveryServices;
  18. use app\services\order\StoreOrderServices;
  19. use app\services\store\DeliveryServiceServices;
  20. use app\services\store\SystemStoreServices;
  21. use app\services\user\UserRechargeServices;
  22. use crmeb\services\SystemConfigService;
  23. use think\facade\App;
  24. use \app\common\controller\Order as CommonOrder;
  25. /**
  26. * Class Order
  27. * @package app\controller\store\order
  28. * @property Request $request
  29. */
  30. class Order extends AuthController
  31. {
  32. use CommonOrder;
  33. /**
  34. * @var StoreOrderServices
  35. */
  36. protected $services;
  37. /**
  38. * Order constructor.
  39. * @param App $app
  40. * @param StoreOrderServices $services
  41. */
  42. public function __construct(App $app, StoreOrderServices $services)
  43. {
  44. parent::__construct($app);
  45. $this->services = $services;
  46. }
  47. /**
  48. * 订单列表
  49. * @return mixed
  50. */
  51. public function index()
  52. {
  53. $where = $this->request->getMore([
  54. ['order_type', ''],
  55. ['type', ''],
  56. ['pay_type', ''],
  57. ['status', ''],
  58. ['time', ''],
  59. ['staff_id', ''],
  60. ['real_name', '']
  61. ]);
  62. $where['is_system_del'] = 0;
  63. $where['store_id'] = $this->storeId;
  64. if (!$where['real_name'] && !in_array($where['status'], [-1, -2, -3])) {
  65. $where['pid'] = 0;
  66. }
  67. return $this->success($this->services->getOrderList($where, ['*'], ['split' => function ($query) {
  68. $query->field('id,pid');
  69. }, 'pink', 'invoice', 'storeStaff']));
  70. }
  71. /**
  72. * 获取订单类型数量
  73. * @return mixed
  74. */
  75. public function chart()
  76. {
  77. $where = $this->request->getMore([
  78. ['data', '', '', 'time'],
  79. [['type', 'd'], 0],
  80. ['order_type', ''],
  81. ['pay_type', ''],
  82. ]);
  83. $where['store_id'] = $this->storeId;
  84. $data = $this->services->orderStoreCount($where);
  85. return $this->success($data);
  86. }
  87. /**
  88. * 获取头部统计数据
  89. * @param UserRechargeServices $services
  90. * @param OtherOrderServices $orderServices
  91. * @return mixed
  92. */
  93. public function header(UserRechargeServices $services, OtherOrderServices $orderServices)
  94. {
  95. $data = $this->services->getStoreOrderHeader($this->storeId);
  96. $data['recharg'] = $services->getRechargeCount($this->storeId);
  97. $data['vip'] = $orderServices->getvipOrderCount($this->storeId);
  98. return $this->success($data);
  99. }
  100. /**
  101. * 获取配置信息
  102. * @return mixed
  103. */
  104. public function getDeliveryInfo(SystemStoreServices $storeServices)
  105. {
  106. $storeId = (int)$this->storeId;
  107. $storeInfo = [];
  108. if ($storeId) {
  109. $storeInfo = $storeServices->getStoreInfo($storeId);
  110. }
  111. $data = SystemConfigService::more([
  112. 'city_delivery_status',
  113. 'self_delivery_status',
  114. 'dada_delivery_status',
  115. 'uu_delivery_status'
  116. ]);
  117. return $this->success([
  118. 'express_temp_id' => store_config($this->storeId, 'store_config_export_temp_id'),
  119. 'id' => store_config($this->storeId, 'store_config_export_id'),
  120. 'to_name' => store_config($this->storeId, 'store_config_export_to_name'),
  121. 'to_tel' => store_config($this->storeId, 'store_config_export_to_tel'),
  122. 'to_add' => store_config($this->storeId, 'store_config_export_to_address'),
  123. 'export_open' => (bool)((int)store_config($this->storeId, 'store_config_export_open')),
  124. 'city_delivery_status' => $data['city_delivery_status'] && ($data['self_delivery_status'] || $data['dada_delivery_status'] || $data['uu_delivery_status']),
  125. 'self_delivery_status' => $data['city_delivery_status'] && $data['self_delivery_status'],
  126. 'dada_delivery_status' => $data['city_delivery_status'] && $data['dada_delivery_status'],
  127. 'uu_delivery_status' => $data['city_delivery_status'] && $data['uu_delivery_status'],
  128. ]);
  129. }
  130. /**
  131. * 订单导出
  132. * @param UserRechargeServices $services
  133. * @param ExportServices $exportServices
  134. * @param OtherOrderServices $otherOrderServices
  135. * @param $type
  136. * @return mixed
  137. * @throws \think\db\exception\DataNotFoundException
  138. * @throws \think\db\exception\DbException
  139. * @throws \think\db\exception\ModelNotFoundException
  140. */
  141. public function export(UserRechargeServices $services, ExportServices $exportServices, OtherOrderServices $otherOrderServices, $type)
  142. {
  143. switch ((int)$type) {
  144. case 1:
  145. $where_tmp = $this->request->postMore([
  146. ['status', ''],
  147. ['real_name', ''],
  148. ['time', ''],
  149. ['type', ''],
  150. ['orderType', ''],
  151. ['ids', '']
  152. ]);
  153. $orderType = $where_tmp['orderType'];
  154. unset($where_tmp['orderType']);
  155. $where['status'] = $where_tmp['status'];
  156. $where['real_name'] = $where_tmp['real_name'];
  157. $where['time'] = $where_tmp['time'];
  158. $where['type'] = $orderType;
  159. $with = [];
  160. if ($where_tmp['ids']) {
  161. $where['id'] = explode(',', $where_tmp['ids']);
  162. }
  163. $where['is_system_del'] = 0;
  164. if ($orderType == 7 || $orderType == 5) $where['pid'] = 0;
  165. $where['store_id'] = $this->storeId;
  166. $data = $this->services->getExportList($where, $with, $exportServices->limit);
  167. return $this->success($exportServices->storeOrder($data, ''));
  168. case 2:
  169. $where = $this->request->postMore([
  170. ['data', ''],
  171. ['paid', 1],
  172. ['nickname', ''],
  173. ['excel', '1'],
  174. ['staff_id', ''],
  175. ]);
  176. $where['store_id'] = $this->storeId;
  177. $data = $services->getRechargeList($where, '*', $exportServices->limit);
  178. return $this->success($exportServices->userRecharge($data['list'] ?? []));
  179. case 3:
  180. $where = $this->request->postMore([
  181. ['name', ""],
  182. ['add_time', ""],
  183. ['member_type', ""],
  184. ['pay_type', ""],
  185. ['staff_id', ''],
  186. ]);
  187. $where['store_id'] = $this->storeId;
  188. $data = $otherOrderServices->getMemberRecord($where, $exportServices->limit);
  189. return $this->success($exportServices->vipOrder($data['list'] ?? []));
  190. default:
  191. return $this->fail('导出类型错误');
  192. }
  193. }
  194. /**
  195. * @param DeliveryServiceServices $services
  196. * @return mixed
  197. * @throws \think\db\exception\DataNotFoundException
  198. * @throws \think\db\exception\DbException
  199. * @throws \think\db\exception\ModelNotFoundException
  200. */
  201. public function getDeliveryList(DeliveryServiceServices $services)
  202. {
  203. return $this->success($services->getDeliveryList(1, $this->storeId));
  204. }
  205. /**
  206. * 获取核销订单商品列表
  207. * @param Request $request
  208. * @param WriteOffOrderServices $writeOffOrderServices
  209. * @return mixed
  210. * @throws \think\db\exception\DataNotFoundException
  211. * @throws \think\db\exception\DbException
  212. * @throws \think\db\exception\ModelNotFoundException
  213. */
  214. public function orderCartInfo(Request $request, WriteOffOrderServices $writeOffOrderServices)
  215. {
  216. [$oid] = $request->postMore([
  217. ['oid', '']
  218. ], true);
  219. return app('json')->success($writeOffOrderServices->getOrderCartInfo(0, (int)$oid, 1, (int)$this->storeStaffId));
  220. }
  221. /**
  222. * 核销订单
  223. * @param Request $request
  224. * @param WriteOffOrderServices $writeOffOrderServices
  225. * @param $order_id
  226. * @return mixed
  227. * @throws \think\db\exception\DataNotFoundException
  228. * @throws \think\db\exception\DbException
  229. * @throws \think\db\exception\ModelNotFoundException
  230. */
  231. public function wirteoff(Request $request, WriteOffOrderServices $writeOffOrderServices, $order_id)
  232. {
  233. $orderInfo = $this->services->getOne(['order_id' => $order_id, 'is_del' => 0], '*', ['pink']);
  234. if (!$orderInfo) {
  235. return $this->fail('核销订单未查到!');
  236. }
  237. [$cart_ids] = $request->postMore([
  238. ['cart_ids', []]
  239. ], true);
  240. if ($cart_ids) {
  241. foreach ($cart_ids as $cart) {
  242. if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num'] || $cart['cart_num'] <= 0) {
  243. return $this->fail('请重新选择发货商品,或发货件数');
  244. }
  245. }
  246. }
  247. return app('json')->success('核销成功', $writeOffOrderServices->writeoffOrder(0, $orderInfo->toArray(), $cart_ids, 1, (int)$this->storeStaffId));
  248. }
  249. /**
  250. * 订单发送货
  251. * @param $id 订单id
  252. * @return mixed
  253. */
  254. public function update_delivery($id, StoreOrderDeliveryServices $services)
  255. {
  256. $data = $this->request->postMore([
  257. ['type', 1],
  258. ['delivery_name', ''],//快递公司名称
  259. ['delivery_id', ''],//快递单号
  260. ['delivery_code', ''],//快递公司编码
  261. ['express_record_type', 2],//发货记录类型
  262. ['express_temp_id', ""],//电子面单模板
  263. ['to_name', ''],//寄件人姓名
  264. ['to_tel', ''],//寄件人电话
  265. ['to_addr', ''],//寄件人地址
  266. ['sh_delivery_name', ''],//送货人姓名
  267. ['sh_delivery_id', ''],//送货人电话
  268. ['sh_delivery_uid', ''],//送货人ID
  269. ['delivery_type', 1],//送货类型
  270. ['station_type', 1],//送货类型
  271. ['cargo_weight', 0],//重量
  272. ['mark', '', '', 'remark'],//管理员备注
  273. ['remark', '', '', 'delivery_remark'],//第三方配送备注
  274. ['fictitious_content', '']//虚拟发货内容
  275. ]);
  276. if (!$id) {
  277. return $this->fail('缺少发货ID');
  278. }
  279. return $this->success('SUCCESS', $services->delivery((int)$id, $data, (int)$this->storeStaffId));
  280. }
  281. /**
  282. * 订单拆单发送货
  283. * @param $id 订单id
  284. * @return mixed
  285. */
  286. public function split_delivery($id, StoreOrderDeliveryServices $services)
  287. {
  288. $data = $this->request->postMore([
  289. ['type', 1],
  290. ['delivery_name', ''],//快递公司名称
  291. ['delivery_id', ''],//快递单号
  292. ['delivery_code', ''],//快递公司编码
  293. ['express_record_type', 2],//发货记录类型
  294. ['express_temp_id', ""],//电子面单模板
  295. ['to_name', ''],//寄件人姓名
  296. ['to_tel', ''],//寄件人电话
  297. ['to_addr', ''],//寄件人地址
  298. ['sh_delivery_name', ''],//送货人姓名
  299. ['sh_delivery_id', ''],//送货人电话
  300. ['sh_delivery_uid', ''],//送货人ID
  301. ['delivery_type', 1],//送货类型
  302. ['station_type', 1],//送货类型
  303. ['cargo_weight', 0],//重量
  304. ['mark', ''],//备注
  305. ['remark', ''],//配送备注
  306. ['fictitious_content', ''],//虚拟发货内容
  307. ['cart_ids', []]
  308. ]);
  309. if (!$id) {
  310. return $this->fail('缺少发货ID');
  311. }
  312. if (!$data['cart_ids']) {
  313. return $this->fail('请选择发货商品');
  314. }
  315. foreach ($data['cart_ids'] as $cart) {
  316. if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num']) {
  317. return $this->fail('请重新选择发货商品,或发货件数');
  318. }
  319. }
  320. $services->splitDelivery((int)$id, $data, (int)$this->storeStaffId);
  321. return $this->success('SUCCESS');
  322. }
  323. /**
  324. * 获取次卡商品核销表单
  325. * @param WriteOffOrderServices $writeOffOrderServices
  326. * @param $id
  327. * @return mixed
  328. * @throws \think\db\exception\DataNotFoundException
  329. * @throws \think\db\exception\DbException
  330. * @throws \think\db\exception\ModelNotFoundException
  331. */
  332. public function writeOrderFrom(WriteOffOrderServices $writeOffOrderServices, $id)
  333. {
  334. if (!$id) {
  335. return $this->fail('缺少核销订单ID');
  336. }
  337. [$cart_num] = $this->request->getMore([
  338. ['cart_num', 1]
  339. ], true);
  340. return $this->success($writeOffOrderServices->writeOrderFrom((int)$id, (int)$this->storeStaffId, (int)$cart_num));
  341. }
  342. /**
  343. * 次卡商品核销表单提交
  344. * @param WriteOffOrderServices $writeOffOrderServices
  345. * @param $id
  346. * @return \think\Response
  347. * @throws \think\db\exception\DataNotFoundException
  348. * @throws \think\db\exception\DbException
  349. * @throws \think\db\exception\ModelNotFoundException
  350. */
  351. public function writeoffFrom(WriteOffOrderServices $writeOffOrderServices, $id)
  352. {
  353. if (!$id) {
  354. return $this->fail('缺少核销订单ID');
  355. }
  356. $orderInfo = $this->services->getOne(['id' => $id, 'is_del' => 0], '*', ['pink']);
  357. if (!$orderInfo) {
  358. return $this->fail('核销订单未查到!');
  359. }
  360. $data = $this->request->postMore([
  361. ['cart_id', ''],//核销订单商品cart_id
  362. ['cart_num', 0]
  363. ]);
  364. $cart_ids[] = $data;
  365. if ($cart_ids) {
  366. foreach ($cart_ids as $cart) {
  367. if (!isset($cart['cart_id']) || !$cart['cart_id'] || !isset($cart['cart_num']) || !$cart['cart_num'] || $cart['cart_num'] <= 0) {
  368. return $this->fail('请重新选择发货商品,或发货件数');
  369. }
  370. }
  371. }
  372. return app('json')->success('核销成功', $writeOffOrderServices->writeoffOrder(0, $orderInfo->toArray(), $cart_ids, 1, (int)$this->storeStaffId));
  373. }
  374. /**
  375. * 易联云打印机打印
  376. * @param $id
  377. * @return mixed
  378. */
  379. public function order_print($id)
  380. {
  381. if (!$id) return app('json')->fail('缺少参数');
  382. $order = $this->services->get($id);
  383. if (!$order) {
  384. return app('json')->fail('订单没有查到,无法打印!');
  385. }
  386. $res = $this->services->orderPrint((int)$id, 1, (int)$this->storeId);
  387. if ($res) {
  388. return app('json')->success('打印成功');
  389. } else {
  390. return app('json')->fail('打印失败');
  391. }
  392. }
  393. }