Order.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 crmeb\services\SpreadsheetExcelService;
  16. use think\App;
  17. use think\facade\Db;
  18. class Order extends BaseController
  19. {
  20. protected $repository;
  21. public function __construct(App $app, repository $repository)
  22. {
  23. parent::__construct($app);
  24. $this->repository = $repository;
  25. }
  26. public function lst($id)
  27. {
  28. [$page, $limit] = $this->getPage();
  29. $where = $this->request->params(['date','order_sn','order_type','keywords','username']);
  30. $where['reconciliation_type'] = $this->request->param('status', 1);
  31. $where['mer_id'] = $id;
  32. return app('json')->success($this->repository->adminGetList($where, $page, $limit));
  33. }
  34. public function markForm($id)
  35. {
  36. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  37. return app('json')->fail('数据不存在');
  38. return app('json')->success(formToData($this->repository->adminMarkForm($id)));
  39. }
  40. public function mark($id)
  41. {
  42. if (!$this->repository->getWhereCount([$this->repository->getPk() => $id]))
  43. return app('json')->fail('数据不存在');
  44. $data = $this->request->params(['admin_mark']);
  45. $this->repository->update($id, $data);
  46. return app('json')->success('备注成功');
  47. }
  48. /**
  49. * TODO
  50. * @return mixed
  51. * @author Qinii
  52. * @day 2020-06-25
  53. */
  54. public function getAllList()
  55. {
  56. [$page, $limit] = $this->getPage();
  57. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn','order_ids','paid', 'zero_line_uid']);
  58. $pay_type=$this->request->param('pay_type');
  59. if($pay_type==1 || $pay_type==4){
  60. $where['pay_type']=$pay_type;
  61. }
  62. if($pay_type==6){
  63. //一壶茶红积分兑换的
  64. $where['mer_id']=496;
  65. $where['pay_type']=5;
  66. }
  67. // 导出
  68. $is_excel = request()->param('is_excel', 0);
  69. $result = $this->repository->merchantGetList($where, $page, $limit);
  70. if ($is_excel == 1) {
  71. $data = $result['list'];
  72. $arr = [];
  73. foreach ($data as $item) {
  74. $arr[] = [
  75. $item['order_sn'], // 订单编号
  76. $item['order_type'] == 0 ? "普通订单" : "核销订单", // 订单类型
  77. $item['user']['nickname'] ?? '', // 用户昵称
  78. $item['user']['phone'] ?? '', // 用户手机号
  79. $item['real_name'], // 收货人
  80. $item['merchant']['mer_name'] ?? '', // 商户名称
  81. // $item['orderProduct'][0]['cart_info']['product']['image'],
  82. $item['orderProduct'][0]['cart_info']['product']['store_name'] . ' | ' . $item['orderProduct'][0]['cart_info']['productAttr']['sku'],
  83. $item['orderProduct'][0]['cart_info']['productAttr']['price'],
  84. $item['orderProduct'][0]['product_num'],
  85. $item['pay_price'], // 订单金额
  86. $item['fzone_pay_note'], // 支付方式
  87. $item['paid'] == 0 ? "未支付" : "已支付", // 支付状态
  88. $item['is_del'] == 0 ? ($item['status'] == 5 ? '待付款' : ($item['status'] == 0 ? '待发货' : ($item['status'] == 1 ? '待收货' : ($item['status'] == 2 ? '待评价' : ($item['status'] == 3 ? '已完成' : ($item['status'] == 4 ? '已申请退款' : ($item['status'] == -1 ? '已退款' : ($item['status'] == 6 ? '已取消' : '')))))))) : '已删除', // 订单状态
  89. $item['create_time'], // 下单时间
  90. ];
  91. }
  92. return app('json')->success($this->getStatisticsExcel([
  93. '订单编号',
  94. '订单类型',
  95. '用户昵称',
  96. '用户手机号',
  97. '收货人',
  98. '商户名称',
  99. '商品图片',
  100. // '商品名称',
  101. '商品单价',
  102. '商品数量',
  103. '订单金额',
  104. '支付方式',
  105. '支付状态',
  106. '订单状态',
  107. '下单时间'
  108. ], $arr, '订单明细'));
  109. }
  110. return app('json')->success($result);
  111. }
  112. /**
  113. * 获取统计导出
  114. */
  115. public function getStatisticsExcel($header,$arr,$title)
  116. {
  117. $filename = $title.'_'.date('YmdHis').'_'.rand(10000,99999);
  118. $name = $filename;
  119. $info = '生成时间:' . date('Y-m-d H:i:s',time());
  120. $suffix='xlsx';
  121. $path='extract';
  122. unset($_instance);
  123. $_instance = SpreadsheetExcelService::instance_xin();
  124. $_path =$_instance
  125. ->createOrActive()
  126. ->setExcelHeader($header)
  127. ->setExcelTile($title, $name, $info)
  128. ->setExcelContent($arr)
  129. ->excelSave($filename, $suffix, $path);
  130. $domain = request()->domain();
  131. $data= [
  132. 'name' => $filename.'.'.$suffix,
  133. 'status' => 1,
  134. 'path' => $domain.'/'.$_path
  135. ];
  136. return $data;
  137. }
  138. /**
  139. * TODO 自提订单列表
  140. * @return mixed
  141. * @author Qinii
  142. * @day 2020-08-17
  143. */
  144. public function getTakeList()
  145. {
  146. [$page, $limit] = $this->getPage();
  147. $where = $this->request->params(['date','order_sn','keywords','username']);
  148. $where['take_order'] = 1;
  149. $where['status'] = -1;
  150. $where['verify_date'] = $where['date'];
  151. unset($where['date']);
  152. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  153. }
  154. /**
  155. * TODO
  156. * @return mixed
  157. * @author Qinii
  158. * @day 2020-08-17
  159. */
  160. public function chart()
  161. {
  162. $where = $this->request->params(['type', 'date', 'mer_id','keywords','username','order_sn','order_ids','paid']);
  163. return app('json')->success($this->repository->adminOrderNumber(-1, $where));
  164. }
  165. /**
  166. * TODO 自提订单头部统计
  167. * @return mixed
  168. * @author Qinii
  169. * @day 2020-08-17
  170. */
  171. public function takeChart()
  172. {
  173. return app('json')->success($this->repository->adminOrderNumber(1));
  174. }
  175. /**
  176. * TODO 订单类型
  177. * @return mixed
  178. * @author Qinii
  179. * @day 2020-08-15
  180. */
  181. public function orderType()
  182. {
  183. return app('json')->success($this->repository->orderType([]));
  184. }
  185. public function detail($id)
  186. {
  187. $data = $this->repository->getOne($id, null);
  188. if (!$data)
  189. return app('json')->fail('数据不存在');
  190. return app('json')->success($data);
  191. }
  192. /**
  193. * TODO 快递查询
  194. * @param $id
  195. * @return mixed
  196. * @author Qinii
  197. * @day 2020-06-25
  198. */
  199. public function express($id)
  200. {
  201. if (!$this->repository->getWhereCount(['order_id' => $id, 'delivery_type' => 1]))
  202. return app('json')->fail('订单信息或状态错误');
  203. return app('json')->success($this->repository->express($id));
  204. }
  205. public function reList($id)
  206. {
  207. [$page, $limit] = $this->getPage();
  208. $where = ['reconciliation_id' => $id, 'type' => 0];
  209. return app('json')->success($this->repository->reconList($where, $page, $limit));
  210. }
  211. /**
  212. * TODO 导出文件
  213. * @author Qinii
  214. * @day 2020-07-30
  215. */
  216. public function excel()
  217. {
  218. $where = $this->request->params(['type', 'date', 'mer_id','keywords','status','username','order_sn']);
  219. app()->make(ExcelRepository::class)->create($where, $this->request->adminId(), 'order',0);
  220. return app('json')->success('开始导出数据');
  221. }
  222. /**
  223. * 养老金打款凭证 列表
  224. * @return mixed
  225. * @throws \think\db\exception\DataNotFoundException
  226. * @throws \think\db\exception\DbException
  227. * @throws \think\db\exception\ModelNotFoundException
  228. */
  229. public function order_red_list()
  230. {
  231. [$page, $limit] = $this->getPage();
  232. $where = $this->request->params(['status', 'date']);
  233. // $where['mer_id'] = $this->request->merId();
  234. $query = Db::name('enterprise_red_order_voucher')->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  235. getModelTime($query, $where['date']);
  236. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  237. $query->where('status',$where['status']);
  238. });
  239. $data['count'] = $query->count();
  240. $data['list'] = $query->page($page, $limit)->order('id desc')->select();
  241. return app('json')->success('ok', $data);
  242. }
  243. /**
  244. * 养老金提交打款凭证 审核
  245. * @return mixed
  246. * @throws \think\db\exception\DataNotFoundException
  247. * @throws \think\db\exception\DbException
  248. * @throws \think\db\exception\ModelNotFoundException
  249. */
  250. public function order_red_status()
  251. {
  252. $post= $this->request->params(['id', 'status', 'refund_message']);
  253. $voucher=Db::name('enterprise_red_order_voucher')->find($post['id']);
  254. if(!$voucher){
  255. return app('json')->fail('订单信息错误');
  256. }
  257. if($voucher['status']!=0){
  258. return app('json')->fail('请勿重复操作');
  259. }
  260. if($post['status']==2){
  261. $update['status']=2;
  262. $update['refund_message']=$post['refund_message'];
  263. if($post['refund_message']==''){
  264. return app('json')->fail('请输入不通过原因');
  265. }
  266. $is_red_ylj=0;
  267. }else{
  268. $update['status']=1;
  269. $is_red_ylj=2;
  270. }
  271. $update['status_time']=date('Y-m-d H:i:s');
  272. $re=Db::name('enterprise_red_order_voucher')->where('id',$post['id'])->update($update);
  273. Db::name('store_order')->whereIn('order_id',$voucher['order_ids'])->where('is_red_ylj',1)->update(['is_red_ylj'=>$is_red_ylj]);
  274. $where['o.paid'] = 1;
  275. // $where['o.pay_type'] = 5;
  276. $where['u.commission_type'] = 5;
  277. $where['u.gzc'] = 3;
  278. $where['u.status'] = 0;
  279. $bill_id = Db::name('store_order')
  280. ->alias('o')
  281. ->join('user_bill u', 'u.order_sn=o.order_sn')
  282. ->where($where)
  283. ->whereIN('o.pay_type',[0,5])
  284. ->whereIn('o.order_id', $voucher['order_ids'])
  285. ->column('u.bill_id');
  286. Db::name('user_bill')->whereIn('bill_id',$bill_id)->update(['status'=>1,'gzc'=>0]);
  287. if($re){
  288. return app('json')->success('操作成功');
  289. }
  290. return app('json')->fail('操作失败');
  291. }
  292. }