Order.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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','paid']);
  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. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn','order_ids','paid']);
  93. return app('json')->success($this->repository->adminOrderNumber(-1, $where));
  94. }
  95. /**
  96. * TODO 自提订单头部统计
  97. * @return mixed
  98. * @author Qinii
  99. * @day 2020-08-17
  100. */
  101. public function takeChart()
  102. {
  103. return app('json')->success($this->repository->adminOrderNumber(1));
  104. }
  105. /**
  106. * TODO 订单类型
  107. * @return mixed
  108. * @author Qinii
  109. * @day 2020-08-15
  110. */
  111. public function orderType()
  112. {
  113. return app('json')->success($this->repository->orderType([]));
  114. }
  115. public function detail($id)
  116. {
  117. $data = $this->repository->getOne($id, null);
  118. if (!$data)
  119. return app('json')->fail('数据不存在');
  120. return app('json')->success($data);
  121. }
  122. /**
  123. * TODO 快递查询
  124. * @param $id
  125. * @return mixed
  126. * @author Qinii
  127. * @day 2020-06-25
  128. */
  129. public function express($id)
  130. {
  131. if (!$this->repository->getWhereCount(['order_id' => $id, 'delivery_type' => 1]))
  132. return app('json')->fail('订单信息或状态错误');
  133. return app('json')->success($this->repository->express($id));
  134. }
  135. public function reList($id)
  136. {
  137. [$page, $limit] = $this->getPage();
  138. $where = ['reconciliation_id' => $id, 'type' => 0];
  139. return app('json')->success($this->repository->reconList($where, $page, $limit));
  140. }
  141. /**
  142. * TODO 导出文件
  143. * @author Qinii
  144. * @day 2020-07-30
  145. */
  146. public function excel()
  147. {
  148. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn']);
  149. app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'order',0);
  150. return app('json')->success('开始导出数据');
  151. }
  152. /**
  153. * 养老金打款凭证 列表
  154. * @return mixed
  155. * @throws \think\db\exception\DataNotFoundException
  156. * @throws \think\db\exception\DbException
  157. * @throws \think\db\exception\ModelNotFoundException
  158. */
  159. public function order_red_list()
  160. {
  161. [$page, $limit] = $this->getPage();
  162. $where = $this->request->params(['status', 'date']);
  163. // $where['mer_id'] = $this->request->merId();
  164. $query = Db::name('enterprise_red_order_voucher')->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  165. getModelTime($query, $where['date']);
  166. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  167. $query->where('status',$where['status']);
  168. });
  169. $data['count'] = $query->count();
  170. $data['list'] = $query->page($page, $limit)->order('id desc')->select();
  171. return app('json')->success('ok', $data);
  172. }
  173. /**
  174. * 养老金提交打款凭证 审核
  175. * @return mixed
  176. * @throws \think\db\exception\DataNotFoundException
  177. * @throws \think\db\exception\DbException
  178. * @throws \think\db\exception\ModelNotFoundException
  179. */
  180. public function order_red_status()
  181. {
  182. $post= $this->request->params(['id', 'status', 'refund_message']);
  183. $voucher=Db::name('enterprise_red_order_voucher')->find($post['id']);
  184. if(!$voucher){
  185. return app('json')->fail('订单信息错误');
  186. }
  187. if($voucher['status']!=0){
  188. return app('json')->fail('请勿重复操作');
  189. }
  190. if($post['status']==2){
  191. $update['status']=2;
  192. $update['refund_message']=$post['refund_message'];
  193. if($post['refund_message']==''){
  194. return app('json')->fail('请输入不通过原因');
  195. }
  196. $is_red_ylj=0;
  197. }else{
  198. $update['status']=1;
  199. $is_red_ylj=2;
  200. }
  201. $update['status_time']=date('Y-m-d H:i:s');
  202. $re=Db::name('enterprise_red_order_voucher')->where('id',$post['id'])->update($update);
  203. Db::name('store_order')->whereIn('order_id',$voucher['order_ids'])->where('is_red_ylj',1)->update(['is_red_ylj'=>$is_red_ylj]);
  204. $where['o.paid'] = 1;
  205. // $where['o.pay_type'] = 5;
  206. $where['u.commission_type'] = 5;
  207. $where['u.gzc'] = 3;
  208. $where['u.status'] = 0;
  209. $bill_id = Db::name('store_order')
  210. ->alias('o')
  211. ->join('user_bill u', 'u.order_sn=o.order_sn')
  212. ->where($where)
  213. ->whereIN('o.pay_type',[0,5])
  214. ->whereIn('o.order_id', $voucher['order_ids'])
  215. ->column('u.bill_id');
  216. Db::name('user_bill')->whereIn('bill_id',$bill_id)->update(['status'=>1,'gzc'=>0]);
  217. if($re){
  218. return app('json')->success('操作成功');
  219. }
  220. return app('json')->fail('操作失败');
  221. }
  222. }