Order.php 10 KB

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