Order.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. namespace app\controller\merchant\store\order;
  3. use app\common\repositories\store\ExcelRepository;
  4. use app\common\repositories\store\order\MerchantReconciliationRepository;
  5. use app\common\repositories\store\order\StoreOrderRepository;
  6. use ln\exceptions\UploadException;
  7. use ln\jobs\BatchDeliveryJob;
  8. use think\App;
  9. use ln\basic\BaseController;
  10. use app\common\repositories\store\order\StoreOrderRepository as repository;
  11. use think\facade\Queue;
  12. class Order extends BaseController
  13. {
  14. protected $repository;
  15. /**
  16. * Product constructor.
  17. * @param App $app
  18. * @param repository $repository
  19. */
  20. public function __construct(App $app, repository $repository)
  21. {
  22. parent::__construct($app);
  23. $this->repository = $repository;
  24. }
  25. public function title()
  26. {
  27. $where = $this->request->params(['status', 'date', 'order_sn','username','order_type','keywords','order_id','activity_type']);
  28. $where['mer_id'] = $this->request->merId();
  29. return app('json')->success($this->repository->getStat($where,$where['status']));
  30. }
  31. /**
  32. * 订单列表
  33. * @return mixed
  34. * @author Qinii
  35. */
  36. public function lst()
  37. {
  38. [$page, $limit] = $this->getPage();
  39. $where = $this->request->params(['status', 'date', 'order_sn','username','order_type','keywords','order_id','activity_type']);
  40. $where['mer_id'] = $this->request->merId();
  41. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  42. }
  43. public function takeTitle()
  44. {
  45. $where = $this->request->params(['date', 'order_sn', 'username','keywords']);
  46. $where['take_order'] = 1;
  47. $where['status'] = -1;
  48. $where['verify_date'] = $where['date'];
  49. unset($where['date']);
  50. $where['mer_id'] = $this->request->merId();
  51. return app('json')->success($this->repository->getStat($where,''));
  52. }
  53. /**
  54. * TODO 自提订单列表
  55. * @return mixed
  56. * @author Qinii
  57. * @day 2020-08-17
  58. */
  59. public function takeLst()
  60. {
  61. [$page, $limit] = $this->getPage();
  62. $where = $this->request->params(['date', 'order_sn', 'username','keywords']);
  63. $where['take_order'] = 1;
  64. $where['status'] = -1;
  65. $where['verify_date'] = $where['date'];
  66. unset($where['date']);
  67. $where['mer_id'] = $this->request->merId();
  68. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  69. }
  70. /**
  71. * 订单头部统计
  72. * @return mixed
  73. * @author Qinii
  74. */
  75. public function chart()
  76. {
  77. return app('json')->success($this->repository->OrderTitleNumber($this->request->merId(),null));
  78. }
  79. /**
  80. * TODO 自提订单头部统计
  81. * @return mixed
  82. * @author Qinii
  83. * @day 2020-08-17
  84. */
  85. public function takeChart()
  86. {
  87. return app('json')->success($this->repository->OrderTitleNumber($this->request->merId(),1));
  88. }
  89. /**
  90. * TODO 订单类型
  91. * @return mixed
  92. * @author Qinii
  93. * @day 2020-08-15
  94. */
  95. public function orderType()
  96. {
  97. $where['mer_id'] = $this->request->merId();
  98. return app('json')->success($this->repository->orderType($where));
  99. }
  100. /**
  101. * @param $id
  102. * @return mixed
  103. * @author Qinii
  104. */
  105. public function deliveryForm($id)
  106. {
  107. $data = $this->repository->getWhere(['order_id' => $id,'mer_id' => $this->request->merId(),'is_del' => 0]);
  108. if(!$data)return app('json')->fail('数据不存在');
  109. if(!$data['paid'])return app('json')->fail('订单未支付');
  110. if(!in_array($data['status'],[0,1])) return app('json')->fail('订单状态错误');
  111. return app('json')->success(formToData($this->repository->sendProductForm($id,$data)));
  112. }
  113. /**
  114. * TODO 发货
  115. * @param $id
  116. * @return mixed
  117. * @author Qinii
  118. */
  119. public function delivery($id)
  120. {
  121. $type = $this->request->param('delivery_type');
  122. if(!$this->repository->merDeliveryExists($id,$this->request->merId()))
  123. return app('json')->fail('订单信息或状态错误');
  124. if($type == 4){
  125. if(!systemConfig('crmeb_serve_dump')) return app('json')->fail('电子面单功能未开启');
  126. $params = $this->request->params([
  127. 'delivery_name',
  128. 'from_name',
  129. 'from_tel',
  130. 'from_addr',
  131. 'temp_id',
  132. ]);
  133. $this->repository->dump($id,$this->request->merId(),$params);
  134. } else {
  135. $data = $this->request->params([
  136. 'delivery_type',
  137. 'delivery_name',
  138. 'delivery_id',
  139. ]);
  140. if(preg_match('/([\x81-\xfe][\x40-\xfe])/',$data['delivery_id']))
  141. return app('json')->fail('请输入正确的单号/电话');
  142. $this->repository->delivery($id,$data);
  143. }
  144. return app('json')->success('发货成功');
  145. }
  146. /**
  147. * TODO
  148. * @return \think\response\Json
  149. * @author Qinii
  150. * @day 7/26/21
  151. */
  152. public function batchDelivery()
  153. {
  154. $params = $this->request->params([
  155. 'temp_id',
  156. 'order_id',
  157. 'from_tel',
  158. 'from_addr',
  159. 'from_name',
  160. 'delivery_id',
  161. 'delivery_type',
  162. 'delivery_name',
  163. ]);
  164. if(!in_array($params['delivery_type'],[2,3,4])) return app('json')->fail('发货类型错误');
  165. if(!$params['order_id']) return app('json')->fail('需要订单ID');
  166. $data = [
  167. 'mer_id' => $this->request->merId(),
  168. 'data' => $params
  169. ];
  170. if($params['delivery_type'] == 4 && !systemConfig('crmeb_serve_dump'))
  171. return app('json')->fail('电子面单功能未开启');
  172. // $this->repository->batchDelivery($data['mer_id'],$data['data']);
  173. Queue::push(BatchDeliveryJob::class,$data);
  174. return app('json')->success('开始批量发货');
  175. }
  176. /**
  177. * TODO 改价form
  178. * @param $id
  179. * @return mixed
  180. * @author Qinii
  181. * @day 2020-06-11
  182. */
  183. public function updateForm($id)
  184. {
  185. if(!$this->repository->merStatusExists($id,$this->request->merId()))
  186. return app('json')->fail('订单信息或状态错误');
  187. return app('json')->success(formToData($this->repository->form($id)));
  188. }
  189. /**
  190. * TODO 改价
  191. * @param $id
  192. * @return mixed
  193. * @author Qinii
  194. * @day 2020-06-11
  195. */
  196. public function update($id)
  197. {
  198. $data = $this->request->params(['total_price','pay_postage']);
  199. if($data['total_price'] < 0 || $data['pay_postage'] < 0)
  200. return app('json')->fail('金额不可未负数');
  201. if(!$this->repository->merStatusExists($id,$this->request->merId()))
  202. return app('json')->fail('订单信息或状态错误');
  203. $this->repository->eidt($id,$data);
  204. return app('json')->success('修改成功');
  205. }
  206. /**
  207. * @param $id
  208. * @return mixed
  209. * @author Qinii
  210. * @day 2020-06-11
  211. */
  212. public function detail($id)
  213. {
  214. $data = $this->repository->getOne($id,$this->request->merId());
  215. if(!$data) return app('json')->fail('数据不存在');
  216. return app('json')->success($data);
  217. }
  218. /**
  219. * @param $id
  220. * @return mixed
  221. * @author Qinii
  222. * @day 2020-06-11
  223. */
  224. public function status($id)
  225. {
  226. [$page, $limit] = $this->getPage();
  227. if(!$this->repository->getOne($id,$this->request->merId()))
  228. return app('json')->fail('数据不存在');
  229. return app('json')->success($this->repository->getOrderStatus($id,$page, $limit));
  230. }
  231. /**
  232. * @param $id
  233. * @return mixed
  234. * @author Qinii
  235. * @day 2020-06-11
  236. */
  237. public function remarkForm($id)
  238. {
  239. return app('json')->success(formToData($this->repository->remarkForm($id)));
  240. }
  241. /**
  242. * @param $id
  243. * @return mixed
  244. * @author Qinii
  245. * @day 2020-06-11
  246. */
  247. public function remark($id)
  248. {
  249. if(!$this->repository->getOne($id,$this->request->merId()))
  250. return app('json')->fail('数据不存在');
  251. $data = $this->request->params(['remark']);
  252. $this->repository->update($id,$data);
  253. return app('json')->success('备注成功');
  254. }
  255. /**
  256. * 核销
  257. * @param $code
  258. * @author xaboy
  259. * @day 2020/8/15
  260. */
  261. public function verify($code)
  262. {
  263. $this->repository->verifyOrder($code, $this->request->merId(), 0);
  264. return app('json')->success('订单核销成功');
  265. }
  266. /**
  267. * @param $id
  268. * @return mixed
  269. * @author Qinii
  270. * @day 2020-06-11
  271. */
  272. public function delete($id)
  273. {
  274. if(!$this->repository->userDelExists($id,$this->request->merId()))
  275. return app('json')->fail('订单信息或状态错误');
  276. $this->repository->merDelete($id);
  277. return app('json')->success('删除成功');
  278. }
  279. /**
  280. * TODO 快递查询
  281. * @param $id
  282. * @return mixed
  283. * @author Qinii
  284. * @day 2020-06-25
  285. */
  286. public function express($id)
  287. {
  288. return app('json')->success($this->repository->express($id,$this->request->merId()));
  289. }
  290. /**
  291. * TODO
  292. * @param $id
  293. * @return mixed
  294. * @author Qinii
  295. * @day 2020-07-30
  296. */
  297. public function reList($id)
  298. {
  299. [$page,$limit] = $this->getPage();
  300. $make = app()->make(MerchantReconciliationRepository::class);
  301. if(!$make->getWhereCount(['mer_id' => $this->request->merId(),'reconciliation_id' => $id]))
  302. return app('json')->fail('数据不存在');
  303. $where = ['reconciliation_id' => $id,'type' => 0];
  304. return app('json')->success($this->repository->reconList($where,$page,$limit));
  305. }
  306. /**
  307. * TODO 导出文件
  308. * @author Qinii
  309. * @day 2020-07-30
  310. */
  311. public function excel()
  312. {
  313. $where = $this->request->params(['status', 'date', 'order_sn','order_type','username','keywords','take_order']);
  314. if($where['take_order']){
  315. $where['status'] = -1;
  316. $where['verify_date'] = $where['date'];
  317. unset($where['date']);
  318. unset($where['order_type']);
  319. }
  320. $where['mer_id'] = $this->request->merId();
  321. app()->make(ExcelRepository::class)->create($where,$this->request->adminId(),'order',$this->request->merId());
  322. return app('json')->success('开始导出数据');
  323. }
  324. /**
  325. * TODO 打印小票
  326. * @param $id
  327. * @return mixed
  328. * @author Qinii
  329. * @day 2020-07-30
  330. */
  331. public function printer($id)
  332. {
  333. $merId = $this->request->merId();
  334. $this->repository->checkPrinterConfig($merId);
  335. if(!$this->repository->getOne($id,$merId))
  336. return app('json')->fail('数据不存在');
  337. $this->repository->printer($id,$merId);
  338. return app('json')->success('打印成功');
  339. }
  340. /**
  341. * TODO 导出发货单
  342. * @return \think\response\Json
  343. * @author Qinii
  344. * @day 3/13/21
  345. */
  346. public function deliveryExport()
  347. {
  348. $where = $this->request->params(['username', 'date', 'activity_type','order_type','username','keywords','id']);
  349. $where['mer_id'] = $this->request->merId();
  350. $where['status'] = 0;
  351. $where['paid'] = 1;
  352. $make = app()->make(StoreOrderRepository::class);
  353. if(is_array($where['id'])) $where['order_ids'] = $where['id'];
  354. $count = $make->search($where)->count();
  355. if(!$count) app('json')->fail('没有可导出数据');
  356. app()->make(ExcelRepository::class)->create($where,$this->request->adminId(),'delivery',$this->request->merId());
  357. return app('json')->success('开始导出数据');
  358. }
  359. }