Order.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-15
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\order;
  11. use crmeb\basic\BaseController;
  12. use app\common\repositories\store\ExcelRepository;
  13. use app\common\repositories\system\merchant\MerchantRepository;
  14. use app\common\repositories\store\order\StoreOrderRepository as repository;
  15. use think\App;
  16. use think\facade\Db;
  17. class Order extends BaseController
  18. {
  19. protected $repository;
  20. public function __construct(App $app, repository $repository)
  21. {
  22. parent::__construct($app);
  23. $this->repository = $repository;
  24. }
  25. public function lst($id)
  26. {
  27. [$page, $limit] = $this->getPage();
  28. $where = $this->request->params(['date','order_sn','order_type','keywords','username']);
  29. $where['reconciliation_type'] = $this->request->param('status', 1);
  30. $where['mer_id'] = $id;
  31. return app('json')->success($this->repository->adminGetList($where, $page, $limit));
  32. }
  33. public function markForm($id)
  34. {
  35. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  36. return app('json')->fail('数据不存在');
  37. return app('json')->success(formToData($this->repository->adminMarkForm($id)));
  38. }
  39. public function mark($id)
  40. {
  41. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  42. return app('json')->fail('数据不存在');
  43. $data = $this->request->params(['admin_mark']);
  44. $this->repository->update($id, $data);
  45. return app('json')->success('备注成功');
  46. }
  47. /**
  48. * TODO
  49. * @return mixed
  50. * @author Qinii
  51. * @day 2020-06-25
  52. */
  53. public function getAllList()
  54. {
  55. [$page, $limit] = $this->getPage();
  56. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn','order_ids']);
  57. $pay_type=$this->request->param('pay_type');
  58. if($pay_type==1 || $pay_type==4){
  59. $where['pay_type']=$pay_type;
  60. }
  61. if($pay_type==6){
  62. //一壶茶红积分兑换的
  63. $where['mer_id']=496;
  64. $where['pay_type']=5;
  65. }
  66. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  67. }
  68. /**
  69. * TODO 自提订单列表
  70. * @return mixed
  71. * @author Qinii
  72. * @day 2020-08-17
  73. */
  74. public function getTakeList()
  75. {
  76. [$page, $limit] = $this->getPage();
  77. $where = $this->request->params(['date','order_sn','keywords','username']);
  78. $where['take_order'] = 1;
  79. $where['status'] = -1;
  80. $where['verify_date'] = $where['date'];
  81. unset($where['date']);
  82. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  83. }
  84. /**
  85. * TODO
  86. * @return mixed
  87. * @author Qinii
  88. * @day 2020-08-17
  89. */
  90. public function chart()
  91. {
  92. return app('json')->success($this->repository->adminOrderNumber());
  93. }
  94. /**
  95. * TODO 自提订单头部统计
  96. * @return mixed
  97. * @author Qinii
  98. * @day 2020-08-17
  99. */
  100. public function takeChart()
  101. {
  102. return app('json')->success($this->repository->adminOrderNumber(1));
  103. }
  104. /**
  105. * TODO 订单类型
  106. * @return mixed
  107. * @author Qinii
  108. * @day 2020-08-15
  109. */
  110. public function orderType()
  111. {
  112. return app('json')->success($this->repository->orderType([]));
  113. }
  114. public function detail($id)
  115. {
  116. $data = $this->repository->getOne($id, null);
  117. if (!$data)
  118. return app('json')->fail('数据不存在');
  119. return app('json')->success($data);
  120. }
  121. /**
  122. * TODO 快递查询
  123. * @param $id
  124. * @return mixed
  125. * @author Qinii
  126. * @day 2020-06-25
  127. */
  128. public function express($id)
  129. {
  130. if (!$this->repository->getWhereCount(['order_id' => $id, 'delivery_type' => 1]))
  131. return app('json')->fail('订单信息或状态错误');
  132. return app('json')->success($this->repository->express($id));
  133. }
  134. public function reList($id)
  135. {
  136. [$page, $limit] = $this->getPage();
  137. $where = ['reconciliation_id' => $id, 'type' => 0];
  138. return app('json')->success($this->repository->reconList($where, $page, $limit));
  139. }
  140. /**
  141. * TODO 导出文件
  142. * @author Qinii
  143. * @day 2020-07-30
  144. */
  145. public function excel()
  146. {
  147. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn']);
  148. app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'order',0);
  149. return app('json')->success('开始导出数据');
  150. }
  151. /**
  152. * 养老金打款凭证 列表
  153. * @return mixed
  154. * @throws \think\db\exception\DataNotFoundException
  155. * @throws \think\db\exception\DbException
  156. * @throws \think\db\exception\ModelNotFoundException
  157. */
  158. public function order_red_list()
  159. {
  160. [$page, $limit] = $this->getPage();
  161. $where = $this->request->params(['status', 'date']);
  162. // $where['mer_id'] = $this->request->merId();
  163. $query = Db::name('enterprise_red_order_voucher')->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  164. getModelTime($query, $where['date']);
  165. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  166. $query->where('status',$where['status']);
  167. });
  168. $data['count'] = $query->count();
  169. $data['list'] = $query->page($page, $limit)->order('id desc')->select();
  170. return app('json')->success('ok', $data);
  171. }
  172. /**
  173. * 养老金提交打款凭证 审核
  174. * @return mixed
  175. * @throws \think\db\exception\DataNotFoundException
  176. * @throws \think\db\exception\DbException
  177. * @throws \think\db\exception\ModelNotFoundException
  178. */
  179. public function order_red_status()
  180. {
  181. $post= $this->request->params(['id', 'status', 'refund_message']);
  182. $voucher=Db::name('enterprise_red_order_voucher')->find($post['id']);
  183. if(!$voucher){
  184. return app('json')->fail('订单信息错误');
  185. }
  186. if($voucher['status']!=0){
  187. return app('json')->fail('请勿重复操作');
  188. }
  189. if($post['status']==2){
  190. $update['status']=2;
  191. $update['refund_message']=$post['refund_message'];
  192. if($post['refund_message']==''){
  193. return app('json')->fail('请输入不通过原因');
  194. }
  195. $is_red_ylj=0;
  196. }else{
  197. $update['status']=1;
  198. $is_red_ylj=2;
  199. }
  200. $update['status_time']=date('Y-m-d H:i:s');
  201. $re=Db::name('enterprise_red_order_voucher')->where('id',$post['id'])->update($update);
  202. Db::name('store_order')->whereIn('order_id',$voucher['order_ids'])->where('is_red_ylj',1)->update(['is_red_ylj'=>$is_red_ylj]);
  203. $where['o.paid'] = 1;
  204. // $where['o.pay_type'] = 5;
  205. $where['u.commission_type'] = 5;
  206. $where['u.gzc'] = 3;
  207. $where['u.status'] = 0;
  208. $bill_id = Db::name('store_order')
  209. ->alias('o')
  210. ->join('user_bill u', 'u.order_sn=o.order_sn')
  211. ->where($where)
  212. ->whereIN('o.pay_type',[0,5])
  213. ->whereIn('o.order_id', $voucher['order_ids'])
  214. ->column('u.bill_id');
  215. Db::name('user_bill')->whereIn('bill_id',$bill_id)->update(['status'=>1,'gzc'=>0]);
  216. if($re){
  217. return app('json')->success('操作成功');
  218. }
  219. return app('json')->fail('操作失败');
  220. }
  221. }