Order.php 13 KB

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