Order.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-10
  7. *
  8. *
  9. */
  10. namespace app\controller\merchant\store\order;
  11. use app\common\repositories\store\ExcelRepository;
  12. use app\common\repositories\store\order\MerchantReconciliationRepository;
  13. use app\common\repositories\store\order\StoreGroupOrderRepository;
  14. use app\common\repositories\store\order\StoreOrderRepository;
  15. use crmeb\exceptions\UploadException;
  16. use crmeb\services\ExcelService;
  17. use crmeb\services\SpreadsheetExcelService;
  18. use think\App;
  19. use crmeb\basic\BaseController;
  20. use app\common\repositories\store\order\StoreOrderRepository as repository;
  21. use think\facade\Db;
  22. class Order extends BaseController
  23. {
  24. protected $repository;
  25. /**
  26. * Product constructor.
  27. * @param App $app
  28. * @param repository $repository
  29. */
  30. public function __construct(App $app, repository $repository)
  31. {
  32. parent::__construct($app);
  33. $this->repository = $repository;
  34. }
  35. /**
  36. * 订单列表
  37. * @return mixed
  38. * @author Qinii
  39. */
  40. public function lst()
  41. {
  42. [$page, $limit] = $this->getPage();
  43. $where = $this->request->params(['status', 'date', 'order_sn', 'username', 'order_type', 'distribution_mode', 'keywords', 'pay_type', 'paid', 'order_ids', 'is_red_ylj', 'gzc', 'ylj_status']);
  44. $where['mer_id'] = $this->request->merId();
  45. return app('json')->success($this->repository->merchantGetListYhc($where, $page, $limit));
  46. }
  47. /**
  48. * @return mixed
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @author xaboy
  53. * @day 2020/6/10
  54. */
  55. public function userLst()
  56. {
  57. [$page, $limit] = $this->getPage();
  58. $where = [
  59. 'status' => (int)$this->request->get('status', 0),
  60. 'mer_id' => $this->request->merId()
  61. ];
  62. if (input('uid')) {
  63. $where['uid'] = input('uid');
  64. }
  65. return app('json')->success($this->repository->getList($where, $page, $limit));
  66. }
  67. /**
  68. * TODO 自提订单列表
  69. * @return mixed
  70. * @author Qinii
  71. * @day 2020-08-17
  72. */
  73. public function takeLst()
  74. {
  75. [$page, $limit] = $this->getPage();
  76. $where = $this->request->params(['date', 'order_sn', 'username']);
  77. $where['take_order'] = 1;
  78. $where['status'] = -1;
  79. $where['verify_date'] = $where['date'];
  80. unset($where['date']);
  81. $where['mer_id'] = $this->request->merId();
  82. return app('json')->success($this->repository->merchantGetList($where, $page, $limit));
  83. }
  84. /**
  85. * 订单头部统计
  86. * @return mixed
  87. * @author Qinii
  88. */
  89. public function chart()
  90. {
  91. return app('json')->success($this->repository->merchantOrderNumber($this->request->merId()));
  92. }
  93. /**
  94. * TODO 自提订单头部统计
  95. * @return mixed
  96. * @author Qinii
  97. * @day 2020-08-17
  98. */
  99. public function takeChart()
  100. {
  101. return app('json')->success($this->repository->merchantOrderNumber($this->request->merId(),1));
  102. }
  103. /**
  104. * TODO 订单类型
  105. * @return mixed
  106. * @author Qinii
  107. * @day 2020-08-15
  108. */
  109. public function orderType()
  110. {
  111. $where['mer_id'] = $this->request->merId();
  112. return app('json')->success($this->repository->orderType($where));
  113. }
  114. /**
  115. * @param $id
  116. * @return mixed
  117. * @author Qinii
  118. */
  119. public function deliveryForm($id)
  120. {
  121. if(!$this->repository->merDeliveryExists($id,$this->request->merId()))
  122. return app('json')->fail('订单信息或状态错误');
  123. return app('json')->success(formToData($this->repository->sendProductForm($id)));
  124. }
  125. /**
  126. * @param $id
  127. * @return mixed
  128. * @author Qinii
  129. */
  130. public function delivery($id)
  131. {
  132. if(!$this->repository->merDeliveryExists($id,$this->request->merId()))
  133. return app('json')->fail('订单信息或状态错误');
  134. $data = $this->request->params(['delivery_type','delivery_name','delivery_id']);
  135. if(preg_match('/([\x81-\xfe][\x40-\xfe])/',$data['delivery_id'])) return app('json')->fail('请输入正确的单号/电话');
  136. $this->repository->delivery($id,$data);
  137. return app('json')->success('发货成功');
  138. }
  139. /**
  140. * @param $id
  141. * @return mixed
  142. * @author Qinii
  143. * @day 2020-06-11
  144. */
  145. public function updateForm($id)
  146. {
  147. if(!$this->repository->merStatusExists($id,$this->request->merId()))
  148. return app('json')->fail('订单信息或状态错误');
  149. return app('json')->success(formToData($this->repository->form($id)));
  150. }
  151. /**
  152. * @param $id
  153. * @return mixed
  154. * @author Qinii
  155. * @day 2020-06-11
  156. */
  157. public function update($id)
  158. {
  159. $data = $this->request->params(['total_price','pay_price','total_postage','pay_postage']);
  160. if($data['total_price'] < 0 || $data['pay_price'] < 0 || $data['total_postage'] < 0 || $data['pay_postage'] < 0 )
  161. return app('json')->fail('金额不可未负数');
  162. if(!$this->repository->merStatusExists($id,$this->request->merId()))
  163. return app('json')->fail('订单信息或状态错误');
  164. $this->repository->eidt($id,$data);
  165. return app('json')->success('修改成功');
  166. }
  167. /**
  168. * @param $id
  169. * @return mixed
  170. * @author Qinii
  171. * @day 2020-06-11
  172. */
  173. public function detail($id)
  174. {
  175. $data = $this->repository->getOne($id,$this->request->merId());
  176. if(!$data)
  177. return app('json')->fail('数据不存在');
  178. return app('json')->success($data);
  179. }
  180. /**
  181. * @param $id
  182. * @return mixed
  183. * @author Qinii
  184. * @day 2020-06-11
  185. */
  186. public function status($id)
  187. {
  188. [$page, $limit] = $this->getPage();
  189. if(!$this->repository->getOne($id,$this->request->merId()))
  190. return app('json')->fail('数据不存在');
  191. return app('json')->success($this->repository->getOrderStatus($id,$page, $limit));
  192. }
  193. /**
  194. * @param $id
  195. * @return mixed
  196. * @author Qinii
  197. * @day 2020-06-11
  198. */
  199. public function remarkForm($id)
  200. {
  201. return app('json')->success(formToData($this->repository->remarkForm($id)));
  202. }
  203. /**
  204. * @param $id
  205. * @return mixed
  206. * @author Qinii
  207. * @day 2020-06-11
  208. */
  209. public function remark($id)
  210. {
  211. if(!$this->repository->getOne($id,$this->request->merId()))
  212. return app('json')->fail('数据不存在');
  213. $data = $this->request->params(['remark']);
  214. $this->repository->update($id,$data);
  215. return app('json')->success('备注成功');
  216. }
  217. /**
  218. * 核销
  219. * @param $code
  220. * @author xaboy
  221. * @day 2020/8/15
  222. */
  223. public function verify($code)
  224. {
  225. $this->repository->verifyOrder($code, $this->request->merId(), 0);
  226. return app('json')->success('订单核销成功');
  227. }
  228. /**
  229. * 自提
  230. * @param $code
  231. * @author xaboy
  232. * @day 2020/8/15
  233. */
  234. public function carry($code)
  235. {
  236. $order_id= input('order_id');
  237. $this->repository->carryOrder($code, $this->request->merId(), 0,$order_id);
  238. return app('json')->success('订单核销成功');
  239. }
  240. /**
  241. * @param $id
  242. * @return mixed
  243. * @author Qinii
  244. * @day 2020-06-11
  245. */
  246. public function delete($id)
  247. {
  248. if(!$this->repository->userDelExists($id,$this->request->merId()))
  249. return app('json')->fail('订单信息或状态错误');
  250. $data['is_system_del'] = 1;
  251. $this->repository->update($id,$data);
  252. return app('json')->success('删除成功');
  253. }
  254. /**
  255. * TODO 快递查询
  256. * @param $id
  257. * @return mixed
  258. * @author Qinii
  259. * @day 2020-06-25
  260. */
  261. public function express($id)
  262. {
  263. if(!$this->repository->getWhereCount(['order_id' => $id,'mer_id' => $this->request->merId(),'delivery_type' =>1]))
  264. return app('json')->fail('订单信息或状态错误');
  265. return app('json')->success($this->repository->express($id));
  266. }
  267. /**
  268. * TODO
  269. * @param $id
  270. * @return mixed
  271. * @author Qinii
  272. * @day 2020-07-30
  273. */
  274. public function reList($id)
  275. {
  276. [$page,$limit] = $this->getPage();
  277. $make = app()->make(MerchantReconciliationRepository::class);
  278. if(!$make->getWhereCount(['mer_id' => $this->request->merId(),'reconciliation_id' => $id]))
  279. return app('json')->fail('数据不存在');
  280. $where = ['reconciliation_id' => $id,'type' => 0];
  281. return app('json')->success($this->repository->reconList($where,$page,$limit));
  282. }
  283. /**
  284. * TODO 导出文件
  285. * @author Qinii
  286. * @day 2020-07-30
  287. */
  288. public function excel()
  289. {
  290. $where = $this->request->params(['status', 'date', 'order_sn', 'username', 'order_type', 'keywords', 'pay_type', 'paid', 'order_ids', 'is_red_ylj', 'ylj_status']);
  291. $where['mer_id'] = $this->request->merId();
  292. $data=$this->repository->merchantGetListYhc($where, 1, 10000);
  293. if($data['count']<1){
  294. return app('json')->fail('没有数据');
  295. }
  296. $list=$this->orderList2($data['list']->toArray());
  297. // var_dump($list);die;
  298. app()->make(ExcelRepository::class)->create($list, $this->request->adminId(), 'order', $this->request->merId());
  299. return app('json')->success('开始导出数据');
  300. }
  301. public function orderList2(array $data){
  302. $result = [];
  303. if(empty($data)) return $result;
  304. $i = 1;
  305. // '序号','订单编号','收货人','商品信息','实际支付', '支付类型','支付方式','支付状态',订单状态'下单时间','养老金','养老金状态',
  306. foreach ($data as $item){
  307. if($item['status']==5){
  308. $item['pay_price']='0';
  309. }
  310. $item['leixing']='';
  311. $item['ddzt']='';
  312. $item['is_red_ylj_text']='未结算';
  313. if($item['paid']==1){
  314. if($item['pay_type']==0){
  315. $item['leixing']='虚拟支付';
  316. }else if ($item['pay_type']==1){
  317. $item['leixing']='微信支付';
  318. }else if ($item['pay_type']==5){
  319. $item['leixing']='红积分兑换';
  320. }
  321. }
  322. if($item['status'] == 5) $item['ddzt']='待付款';
  323. if($item['status'] == 0) $item['ddzt']='待发货';
  324. if($item['status'] == 1) $item['ddzt']='待收货';
  325. if($item['status'] == 2) $item['ddzt']='待评价';
  326. if($item['status'] == 3) $item['ddzt']='已完成';
  327. if($item['status'] == 4) $item['ddzt']='已申请退款';
  328. if($item['status'] == -1) $item['ddzt']='已退款';
  329. if($item['status'] == 6) $item['ddzt']='已取消';
  330. if($item['is_red_ylj']==1){
  331. $item['is_red_ylj_text']='待审核';
  332. }
  333. if($item['is_red_ylj']==2){
  334. $item['is_red_ylj_text']='已结算';
  335. }
  336. $item['sp']='';
  337. $item['sp_num']='';
  338. // <div v-for="(val, i ) in scope.row.orderProduct" :key="i" class="tabBox acea-row row-middle">
  339. // <div class="demo-image__preview">
  340. // <el-image :src="val.cart_info.product.image" :preview-src-list="[val.cart_info.product.image]" />
  341. // </div>
  342. // <span class="tabBox_tit">{{ val.cart_info.product.store_name + ' | ' }}{{ val.cart_info.productAttr.sku }}</span>
  343. // <span class="tabBox_pice">
  344. // {{ '¥'+ val.cart_info.productAttr.price + ' x '+ val.product_num }}
  345. // <em v-if="val.refund_num < val.product_num && val.refund_num > 0" style="color: red;font-style: normal;">(-{{ val.product_num - val.refund_num }})</em>
  346. // </span>
  347. // </div>
  348. foreach ($item['orderProduct'] as $vv){
  349. $item['sp'].=$vv['cart_info']['product']['store_name'].' ';
  350. $item['sp_num'].=$vv['cart_info']['productAttr']['price'].' x' . $vv['product_num'].' ';
  351. }
  352. $result[] = [
  353. $i,
  354. $item['order_sn'],
  355. $item['real_name'],
  356. $item['user_phone'],
  357. $item['sp'],
  358. $item['sp_num'],
  359. $item['pay_price'],
  360. $item['leixing'],
  361. $item['paid'] ? '已支付':'未支付',
  362. $item['ddzt'],
  363. $item['create_time'] ,
  364. $item['ylj'] ,
  365. $item['is_red_ylj_text'] ,
  366. ];
  367. $i++;
  368. }
  369. return $result;
  370. }
  371. /**
  372. * TODO 打印小票
  373. * @param $id
  374. * @return mixed
  375. * @author Qinii
  376. * @day 2020-07-30
  377. */
  378. public function printer($id)
  379. {
  380. $merId = $this->request->merId();
  381. if(!merchantConfig($merId,'printing_status'))
  382. return app('json')->fail('未开启打印机设置');
  383. if(!$this->repository->getOne($id,$merId))
  384. return app('json')->fail('数据不存在');
  385. $this->repository->printer($id,$merId);
  386. return app('json')->success('打印成功');
  387. }
  388. /**
  389. * @param $id
  390. * @param StoreGroupOrderRepository $groupOrderRepository
  391. * @return mixed
  392. * @author xaboy
  393. * @day 2020/6/10
  394. */
  395. public function cancelGroupOrder($id, StoreGroupOrderRepository $groupOrderRepository, StoreOrderRepository $orderRepository)
  396. {
  397. $data = $this->request->params(['change_message','remark']);
  398. $merId = $this->request->merId();
  399. $order = $orderRepository->getWhere(['group_order_id' => $id]);
  400. if ($order['mer_id'] != $merId)
  401. return app('json')->fail('数据不存在');
  402. $groupOrderRepository->cancel((int)$id, 0, $data['change_message'], $data['remark']);
  403. return app('json')->success('取消成功');
  404. }
  405. //设置成支付成功
  406. public function order_zhifu($id)
  407. {
  408. $admin_id = $this->request->adminId();
  409. $admin_info = Db::name('merchant_admin')->where('merchant_admin_id',$admin_id)->find();
  410. if(!$admin_info){
  411. return app('json')->fail('没有权限');
  412. }
  413. if($admin_info['roles'] && !in_array('53',explode(',',$admin_info['roles']))){
  414. return app('json')->fail('没有权限');
  415. }
  416. $domain = $this->request->domain();
  417. $order=Db::name('store_order')->find($id);
  418. if(!$order){
  419. return app('json')->fail('数据不存在');
  420. }
  421. if($order['paid']!=0 || $order['status']!=5){
  422. return app('json')->fail('订单不是待支付状态');
  423. }
  424. // $pay_type=5;
  425. $group_order=Db::name('store_group_order') -> where('group_order_id',$order['group_order_id']) -> find();
  426. Db::name('store_group_order') -> where('group_order_id',$order['group_order_id']) -> update(['rand'=>mt_rand(1000,9999)]);
  427. $orderSn = $group_order['group_order_sn'];
  428. $groupOrder = app()->make(StoreGroupOrderRepository::class)->getWhere(['group_order_sn' => $orderSn]);
  429. if (!$groupOrder || $groupOrder->paid == 1) return;
  430. $total_price=$order['total_price']+$order['youhui_price'];
  431. $pay_price=$order['pay_price']+$order['youhui_price'];
  432. Db::name('store_order')->where('order_id',$id)->update(['total_price'=>$total_price,'pay_price'=>$pay_price,'youhui_price'=>0]);
  433. app()->make(StoreOrderRepository::class)->paySuccess($groupOrder);
  434. return app('json')->success('设置成功');
  435. // event('pay_success_order', ['order_sn' => $requestId[0],'pay_type'=>$pay_type]);
  436. // dump('成功');
  437. // dump($this->randomFromDev(20));
  438. }
  439. /**
  440. * 判断是不是红积分支付的订单
  441. * @return mixed
  442. */
  443. public function order_red_num()
  444. {
  445. $order_ids=input('order_ids','');
  446. $merId = $this->request->merId();
  447. $where['o.paid']=1;
  448. // $where['o.pay_type'] = 5;
  449. $where['o.is_red_ylj']=0;
  450. $where['o.mer_id']=$merId;
  451. $where['u.commission_type']=5;
  452. $where['u.gzc']=3;
  453. $where['u.status']=0;
  454. $order=Db::name('store_order')
  455. ->alias('o')
  456. ->join('user_bill u','u.order_sn=o.order_sn')
  457. ->where($where)
  458. ->whereIN('o.pay_type',[0,5])
  459. ->whereIn('o.order_id',$order_ids)
  460. ->column('o.order_id,o.order_sn,u.number,u.mark');
  461. if($order){
  462. $data['num']=count($order);
  463. $order_ids2=[];
  464. $ylj=0;
  465. foreach ($order as $v){
  466. $order_ids2[]=$v['order_id'];
  467. $ylj+=$v['number'];
  468. }
  469. $data['order_ids']=implode(',',$order_ids2);
  470. $data['ylj']=$ylj;
  471. $data['company_name']='北京天地博爱';
  472. $data['company_bank_name']='开户行开户行开户行开户行';
  473. $data['company_bank_card']='银行卡号银行卡号银行卡号银行卡号';
  474. return app('json')->success('ok',$data);
  475. }
  476. return app('json')->fail('只能结算红积分和虚拟支付类型的订单~');
  477. }
  478. /**
  479. * 养老金提交打款凭证
  480. * @return mixed
  481. */
  482. public function order_red_add()
  483. {
  484. $order_ids=input('order_ids','');
  485. $pics=input('pics','');
  486. if($order_ids==''){
  487. return app('json')->fail('只能结算红积分和虚拟支付类型的订单~');
  488. }
  489. if($pics==''){
  490. return app('json')->fail('请上传打款凭证');
  491. }
  492. $merId = $this->request->merId();
  493. $where['o.paid']=1;
  494. // $where['o.pay_type'] = 5;
  495. $where['o.is_red_ylj']=0;
  496. $where['o.mer_id']=$merId;
  497. $where['u.commission_type']=5;
  498. $where['u.gzc']=3;
  499. $where['u.status']=0;
  500. $order=Db::name('store_order')
  501. ->alias('o')
  502. ->join('user_bill u','u.order_sn=o.order_sn')
  503. ->where($where)
  504. ->whereIN('o.pay_type',[0,5])
  505. ->whereIn('o.order_id',$order_ids)
  506. ->column('o.order_id,o.order_sn,u.number,u.mark');
  507. if($order){
  508. $data['num']=count($order);
  509. $order_ids2=[];
  510. $ylj=0;
  511. foreach ($order as $v){
  512. $order_ids2[]=$v['order_id'];
  513. $ylj+=$v['number'];
  514. }
  515. $data['order_ids']=implode(',',$order_ids2);
  516. $data['ylj']=$ylj;
  517. $data['pics']=$pics;
  518. $data['mer_id']=$merId;
  519. $re=Db::name('enterprise_red_order_voucher')->insert($data);
  520. Db::name('store_order')->whereIn('order_id',$order_ids2)->where('is_red_ylj',0)->update(['is_red_ylj'=>1]);
  521. if($re){
  522. return app('json')->success('提交成功');
  523. }
  524. return app('json')->fail('提交失败');
  525. }
  526. return app('json')->fail('只能结算红积分和虚拟支付类型的订单~');
  527. }
  528. /**
  529. * 养老金打款凭证 列表
  530. * @return mixed
  531. * @throws \think\db\exception\DataNotFoundException
  532. * @throws \think\db\exception\DbException
  533. * @throws \think\db\exception\ModelNotFoundException
  534. */
  535. public function order_red_list()
  536. {
  537. [$page, $limit] = $this->getPage();
  538. $where = $this->request->params(['status', 'date']);
  539. $where['mer_id'] = $this->request->merId();
  540. $query =Db::name('enterprise_red_order_voucher')->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  541. getModelTime($query, $where['date']);
  542. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  543. $query->where('status',$where['status']);
  544. });
  545. $data['count'] = $query->count();
  546. $data['list'] = $query->page($page, $limit)->order('id desc')->select();
  547. return app('json')->success('ok',$data);
  548. }
  549. public function reward_list()
  550. {
  551. [$page, $limit] = $this->getPage();
  552. $where = $this->request->params(['type', 'account', 'date','identity']);
  553. $where['b.mer_id'] = $this->request->merId();
  554. $query =Db::name('enterprise_user_bill')->alias('b')->join('user u','u.uid=b.uid')->join('enterprise_user eu','eu.uid=b.uid')->field('b.*,u.nickname,u.account,eu.identity')
  555. ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  556. getModelTime($query, $where['date'],'b.create_time');
  557. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  558. $query->where('b.type',$where['type']);
  559. })->when(isset($where['identity']) && $where['identity'] !== '', function ($query) use ($where) {
  560. $query->where('eu.identity',$where['identity']);
  561. })->when(isset($where['account']) && $where['account'] !== '', function ($query) use ($where) {
  562. $query->whereLike('u.account','%'.$where['account'].'%');
  563. });
  564. $query->where('type','<>',8);
  565. $data['count'] = $query->count();
  566. $data['list'] = $query->page($page, $limit)->order('b.enterprise_user_bill desc')->select()->each(function ($v) use ($where){
  567. if($v['identity']==0){
  568. $identity_name='普通用户';
  569. }else if ($v['identity']==100){
  570. $identity_name='合伙人';
  571. }else{
  572. $identity_name=Db::name('enterprise_performance_divvy')->where('state',1)->where('mer_id', $where['b.mer_id'])->where('id',$v['identity'])->value('name');
  573. }
  574. $v['identity_name']=$identity_name?$identity_name:'普通用户';
  575. return $v;
  576. });
  577. $count = $query->whereIn('type', [1,2,3,4,6,7])->sum('money');
  578. $query_sql_1 = clone $query;
  579. $query_sql_2 = clone $query;
  580. $query_sql_3 = clone $query;
  581. $query_sql_4 = clone $query;
  582. $query_sql_6 = clone $query;
  583. $query_sql_7 = clone $query;
  584. //type 1-推荐奖 2-业绩奖 3-服务中心分红 4-推荐代理商收益 5- 消费增值
  585. $count1 = $query_sql_1->where('type', 1)->sum('money');
  586. $count2 = $query_sql_2->where('type', 2)->sum('money');
  587. $count3 = $query_sql_3->where('type', 3)->sum('money');
  588. $count4 = $query_sql_4->where('type', 4)->sum('money');
  589. $count6 = $query_sql_6->where('type', 6)->sum('money');
  590. $count7 = $query_sql_7->where('type', 7)->sum('money');
  591. $data['countmoyer']=[
  592. ['className' => 'el-icon-s-goods', 'count' => $count, 'field' => '元', 'name' => '奖励总额', 'info' => '奖励总额 = 分享奖+业绩奖+代理商分红+推荐代理商收益+运营中心收益+人工奖励佣金'],
  593. ['className' => 'el-icon-s-goods', 'count' => $count1, 'field' => '元', 'name' => '分享奖', 'info' => ''],
  594. ['className' => 'el-icon-s-goods', 'count' => $count2, 'field' => '元', 'name' => '业绩奖', 'info' => ''],
  595. ['className' => 'el-icon-s-goods', 'count' => $count3, 'field' => '元', 'name' => '代理商分红', 'info' => ''],
  596. ['className' => 'el-icon-s-goods', 'count' => $count4, 'field' => '元', 'name' => '推荐代理商收益', 'info' => ''],
  597. ['className' => 'el-icon-s-goods', 'count' => $count6, 'field' => '元', 'name' => '运营中心收益', 'info' => ''],
  598. ['className' => 'el-icon-s-goods', 'count' => $count7, 'field' => '元', 'name' => '人工奖励佣金', 'info' => ''],
  599. ];
  600. return app('json')->success('ok', $data);
  601. }
  602. //商户后台-奖励统计 导出功能
  603. public function reward_excel()
  604. {
  605. $where = $this->request->params(['type', 'account', 'date', 'identity']);
  606. $where['b.mer_id'] = $this->request->merId();
  607. $query = Db::name('enterprise_user_bill')->alias('b')->join('user u', 'u.uid=b.uid')->join('enterprise_user eu', 'eu.uid=b.uid')->field('b.*,u.nickname,u.account,eu.identity')
  608. ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  609. getModelTime($query, $where['date'], 'b.create_time');
  610. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  611. $query->where('b.type', $where['type']);
  612. })->when(isset($where['identity']) && $where['identity'] !== '', function ($query) use ($where) {
  613. $query->where('eu.identity', $where['identity']);
  614. })->when(isset($where['account']) && $where['account'] !== '', function ($query) use ($where) {
  615. $query->whereLike('u.account', '%' . $where['account'] . '%');
  616. });
  617. $list = $query->order('b.enterprise_user_bill desc')->select();
  618. foreach ($list as $k=>$v){
  619. $v['type_name']='';
  620. $v['identity_name']='';
  621. if($v['type'] == 1) $v['type_name']='分享奖';
  622. if($v['type'] == 2) $v['type_name']='业绩奖';
  623. if($v['type'] == 3) $v['type_name']='代理商分红';
  624. if($v['type'] == 4) $v['type_name']='推荐代理商收益';
  625. if($v['type'] == 5) $v['type_name']='消费增值系统佣金';
  626. if($v['identity'] == 0){
  627. $v['identity_name']='普通用户';
  628. }else if($v['identity'] == 100){
  629. $v['identity_name']='合伙人';
  630. }else{
  631. $identity_name=Db::name('enterprise_performance_divvy')->where('state',1)->where('mer_id', $where['b.mer_id'])->where('id',$v['identity'])->value('name');
  632. $v['identity_name']=$identity_name?$identity_name:'普通用户';
  633. }
  634. $arr[]=array(
  635. $v['enterprise_user_bill'],
  636. $v['create_time'],
  637. $v['nickname'],
  638. $v['account'],
  639. $v['type_name'],
  640. $v['money'],
  641. $v['identity_name'],
  642. $v['title'],
  643. );
  644. }
  645. $header = [
  646. 'ID','创建时间','用户昵称','用户账号(手机号)','佣金名称','金额(元)','当前身份','奖励来源'
  647. ];
  648. $filename = '奖励统计'.date('YmdHis').'_'.rand(10000,99999);
  649. $title = '奖励统计';
  650. $name = '奖励统计';
  651. $info = '生成时间:' . date('Y-m-d H:i:s',time());
  652. $suffix='xlsx';
  653. $path='extract';
  654. unset($_instance);
  655. $_instance = SpreadsheetExcelService::instance_xin();
  656. $_path =$_instance
  657. ->createOrActive()
  658. ->setExcelHeader($header)
  659. ->setExcelTile($title, $name, $info)
  660. ->setExcelContent($arr)
  661. ->excelSave($filename, $suffix, $path);
  662. $data= [
  663. 'name' => $filename.'.'.$suffix,
  664. 'status' => 1,
  665. 'path' => '/'.$_path
  666. ];
  667. return app('json')->success('ok',$data);
  668. }
  669. }