Order.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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. * 手动操作订单为 已自提 关单
  242. * @return mixed
  243. * @throws \think\db\exception\DataNotFoundException
  244. * @throws \think\db\exception\DbException
  245. * @throws \think\db\exception\ModelNotFoundException
  246. */
  247. public function carryByWithoutCode()
  248. {
  249. $order_id = input('order_id');
  250. $this->repository->carryOrder(null, $this->request->merId(), 0, $order_id);
  251. return app('json')->success('订单核销成功');
  252. }
  253. /**
  254. * @param $id
  255. * @return mixed
  256. * @author Qinii
  257. * @day 2020-06-11
  258. */
  259. public function delete($id)
  260. {
  261. if(!$this->repository->userDelExists($id,$this->request->merId()))
  262. return app('json')->fail('订单信息或状态错误');
  263. $data['is_system_del'] = 1;
  264. $this->repository->update($id,$data);
  265. return app('json')->success('删除成功');
  266. }
  267. /**
  268. * TODO 快递查询
  269. * @param $id
  270. * @return mixed
  271. * @author Qinii
  272. * @day 2020-06-25
  273. */
  274. public function express($id)
  275. {
  276. if(!$this->repository->getWhereCount(['order_id' => $id,'mer_id' => $this->request->merId(),'delivery_type' =>1]))
  277. return app('json')->fail('订单信息或状态错误');
  278. return app('json')->success($this->repository->express($id));
  279. }
  280. /**
  281. * TODO
  282. * @param $id
  283. * @return mixed
  284. * @author Qinii
  285. * @day 2020-07-30
  286. */
  287. public function reList($id)
  288. {
  289. [$page,$limit] = $this->getPage();
  290. $make = app()->make(MerchantReconciliationRepository::class);
  291. if(!$make->getWhereCount(['mer_id' => $this->request->merId(),'reconciliation_id' => $id]))
  292. return app('json')->fail('数据不存在');
  293. $where = ['reconciliation_id' => $id,'type' => 0];
  294. return app('json')->success($this->repository->reconList($where,$page,$limit));
  295. }
  296. /**
  297. * TODO 导出文件
  298. * @author Qinii
  299. * @day 2020-07-30
  300. */
  301. public function excel()
  302. {
  303. $where = $this->request->params(['status', 'date', 'order_sn', 'username', 'order_type', 'keywords', 'pay_type', 'paid', 'order_ids', 'is_red_ylj', 'ylj_status']);
  304. $where['mer_id'] = $this->request->merId();
  305. $data=$this->repository->merchantGetListYhc($where, 1, 10000);
  306. if($data['count']<1){
  307. return app('json')->fail('没有数据');
  308. }
  309. $list=$this->orderList2($data['list']->toArray());
  310. // var_dump($list);die;
  311. app()->make(ExcelRepository::class)->create($list, $this->request->adminId(), 'order', $this->request->merId());
  312. return app('json')->success('开始导出数据');
  313. }
  314. public function orderList2(array $data){
  315. $result = [];
  316. if(empty($data)) return $result;
  317. $i = 1;
  318. // '序号','订单编号','收货人','商品信息','实际支付', '支付类型','支付方式','支付状态',订单状态'下单时间','养老金','养老金状态',
  319. foreach ($data as $item){
  320. if($item['status']==5){
  321. $item['pay_price']='0';
  322. }
  323. $item['leixing']='';
  324. $item['ddzt']='';
  325. $item['is_red_ylj_text']='未结算';
  326. if($item['paid']==1){
  327. if($item['pay_type']==0){
  328. $item['leixing']='虚拟支付';
  329. }else if ($item['pay_type']==1){
  330. $item['leixing']='微信支付';
  331. }else if ($item['pay_type']==5){
  332. $item['leixing']='红积分兑换';
  333. }
  334. }
  335. if($item['status'] == 5) $item['ddzt']='待付款';
  336. if($item['status'] == 0) $item['ddzt']='待发货';
  337. if($item['status'] == 1) $item['ddzt']='待收货';
  338. if($item['status'] == 2) $item['ddzt']='待评价';
  339. if($item['status'] == 3) $item['ddzt']='已完成';
  340. if($item['status'] == 4) $item['ddzt']='已申请退款';
  341. if($item['status'] == -1) $item['ddzt']='已退款';
  342. if($item['status'] == 6) $item['ddzt']='已取消';
  343. if($item['is_red_ylj']==1){
  344. $item['is_red_ylj_text']='待审核';
  345. }
  346. if($item['is_red_ylj']==2){
  347. $item['is_red_ylj_text']='已结算';
  348. }
  349. $item['sp']='';
  350. $item['sp_num']='';
  351. // <div v-for="(val, i ) in scope.row.orderProduct" :key="i" class="tabBox acea-row row-middle">
  352. // <div class="demo-image__preview">
  353. // <el-image :src="val.cart_info.product.image" :preview-src-list="[val.cart_info.product.image]" />
  354. // </div>
  355. // <span class="tabBox_tit">{{ val.cart_info.product.store_name + ' | ' }}{{ val.cart_info.productAttr.sku }}</span>
  356. // <span class="tabBox_pice">
  357. // {{ '¥'+ val.cart_info.productAttr.price + ' x '+ val.product_num }}
  358. // <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>
  359. // </span>
  360. // </div>
  361. foreach ($item['orderProduct'] as $vv){
  362. $item['sp'].=$vv['cart_info']['product']['store_name'].' ';
  363. $item['sp_num'].=$vv['cart_info']['productAttr']['price'].' x' . $vv['product_num'].' ';
  364. }
  365. $result[] = [
  366. $i,
  367. $item['order_sn'],
  368. $item['real_name'],
  369. $item['user_phone'],
  370. $item['sp'],
  371. $item['sp_num'],
  372. $item['pay_price'],
  373. $item['leixing'],
  374. $item['paid'] ? '已支付':'未支付',
  375. $item['ddzt'],
  376. $item['create_time'] ,
  377. $item['ylj'] ,
  378. $item['is_red_ylj_text'] ,
  379. ];
  380. $i++;
  381. }
  382. return $result;
  383. }
  384. /**
  385. * TODO 打印小票
  386. * @param $id
  387. * @return mixed
  388. * @author Qinii
  389. * @day 2020-07-30
  390. */
  391. public function printer($id)
  392. {
  393. $merId = $this->request->merId();
  394. if(!merchantConfig($merId,'printing_status'))
  395. return app('json')->fail('未开启打印机设置');
  396. if(!$this->repository->getOne($id,$merId))
  397. return app('json')->fail('数据不存在');
  398. $this->repository->printer($id,$merId);
  399. return app('json')->success('打印成功');
  400. }
  401. /**
  402. * @param $id
  403. * @param StoreGroupOrderRepository $groupOrderRepository
  404. * @return mixed
  405. * @author xaboy
  406. * @day 2020/6/10
  407. */
  408. public function cancelGroupOrder($id, StoreGroupOrderRepository $groupOrderRepository, StoreOrderRepository $orderRepository)
  409. {
  410. $data = $this->request->params(['change_message','remark']);
  411. $merId = $this->request->merId();
  412. $order = $orderRepository->getWhere(['group_order_id' => $id]);
  413. if ($order['mer_id'] != $merId)
  414. return app('json')->fail('数据不存在');
  415. $groupOrderRepository->cancel((int)$id, 0, $data['change_message'], $data['remark']);
  416. return app('json')->success('取消成功');
  417. }
  418. //设置成支付成功
  419. public function order_zhifu($id)
  420. {
  421. $admin_id = $this->request->adminId();
  422. $admin_info = Db::name('merchant_admin')->where('merchant_admin_id',$admin_id)->find();
  423. if(!$admin_info){
  424. return app('json')->fail('没有权限');
  425. }
  426. if($admin_info['roles'] && !in_array('53',explode(',',$admin_info['roles']))){
  427. return app('json')->fail('没有权限');
  428. }
  429. $domain = $this->request->domain();
  430. $order=Db::name('store_order')->find($id);
  431. if(!$order){
  432. return app('json')->fail('数据不存在');
  433. }
  434. if($order['paid']!=0 || $order['status']!=5){
  435. return app('json')->fail('订单不是待支付状态');
  436. }
  437. // $pay_type=5;
  438. $group_order=Db::name('store_group_order') -> where('group_order_id',$order['group_order_id']) -> find();
  439. Db::name('store_group_order') -> where('group_order_id',$order['group_order_id']) -> update(['rand'=>mt_rand(1000,9999)]);
  440. $orderSn = $group_order['group_order_sn'];
  441. $groupOrder = app()->make(StoreGroupOrderRepository::class)->getWhere(['group_order_sn' => $orderSn]);
  442. if (!$groupOrder || $groupOrder->paid == 1) return;
  443. $total_price=$order['total_price']+$order['youhui_price'];
  444. $pay_price=$order['pay_price']+$order['youhui_price'];
  445. Db::name('store_order')->where('order_id',$id)->update(['total_price'=>$total_price,'pay_price'=>$pay_price,'youhui_price'=>0]);
  446. app()->make(StoreOrderRepository::class)->paySuccess($groupOrder);
  447. return app('json')->success('设置成功');
  448. // event('pay_success_order', ['order_sn' => $requestId[0],'pay_type'=>$pay_type]);
  449. // dump('成功');
  450. // dump($this->randomFromDev(20));
  451. }
  452. /**
  453. * 判断是不是红积分支付的订单
  454. * @return mixed
  455. */
  456. public function order_red_num()
  457. {
  458. $order_ids=input('order_ids','');
  459. $merId = $this->request->merId();
  460. $where['o.paid']=1;
  461. // $where['o.pay_type'] = 5;
  462. $where['o.is_red_ylj']=0;
  463. $where['o.mer_id']=$merId;
  464. $where['u.commission_type']=5;
  465. $where['u.gzc']=3;
  466. $where['u.status']=0;
  467. $order=Db::name('store_order')
  468. ->alias('o')
  469. ->join('user_bill u','u.order_sn=o.order_sn')
  470. ->where($where)
  471. ->whereIN('o.pay_type',[0,5])
  472. ->whereIn('o.order_id',$order_ids)
  473. ->column('o.order_id,o.order_sn,u.number,u.mark');
  474. if($order){
  475. $data['num']=count($order);
  476. $order_ids2=[];
  477. $ylj=0;
  478. foreach ($order as $v){
  479. $order_ids2[]=$v['order_id'];
  480. $ylj+=$v['number'];
  481. }
  482. $data['order_ids']=implode(',',$order_ids2);
  483. $data['ylj']=$ylj;
  484. $data['company_name']='北京天地博爱';
  485. $data['company_bank_name']='开户行开户行开户行开户行';
  486. $data['company_bank_card']='银行卡号银行卡号银行卡号银行卡号';
  487. return app('json')->success('ok',$data);
  488. }
  489. return app('json')->fail('只能结算红积分和虚拟支付类型的订单~');
  490. }
  491. /**
  492. * 养老金提交打款凭证
  493. * @return mixed
  494. */
  495. public function order_red_add()
  496. {
  497. $order_ids=input('order_ids','');
  498. $pics=input('pics','');
  499. if($order_ids==''){
  500. return app('json')->fail('只能结算红积分和虚拟支付类型的订单~');
  501. }
  502. if($pics==''){
  503. return app('json')->fail('请上传打款凭证');
  504. }
  505. $merId = $this->request->merId();
  506. $where['o.paid']=1;
  507. // $where['o.pay_type'] = 5;
  508. $where['o.is_red_ylj']=0;
  509. $where['o.mer_id']=$merId;
  510. $where['u.commission_type']=5;
  511. $where['u.gzc']=3;
  512. $where['u.status']=0;
  513. $order=Db::name('store_order')
  514. ->alias('o')
  515. ->join('user_bill u','u.order_sn=o.order_sn')
  516. ->where($where)
  517. ->whereIN('o.pay_type',[0,5])
  518. ->whereIn('o.order_id',$order_ids)
  519. ->column('o.order_id,o.order_sn,u.number,u.mark');
  520. if($order){
  521. $data['num']=count($order);
  522. $order_ids2=[];
  523. $ylj=0;
  524. foreach ($order as $v){
  525. $order_ids2[]=$v['order_id'];
  526. $ylj+=$v['number'];
  527. }
  528. $data['order_ids']=implode(',',$order_ids2);
  529. $data['ylj']=$ylj;
  530. $data['pics']=$pics;
  531. $data['mer_id']=$merId;
  532. $re=Db::name('enterprise_red_order_voucher')->insert($data);
  533. Db::name('store_order')->whereIn('order_id',$order_ids2)->where('is_red_ylj',0)->update(['is_red_ylj'=>1]);
  534. if($re){
  535. return app('json')->success('提交成功');
  536. }
  537. return app('json')->fail('提交失败');
  538. }
  539. return app('json')->fail('只能结算红积分和虚拟支付类型的订单~');
  540. }
  541. /**
  542. * 养老金打款凭证 列表
  543. * @return mixed
  544. * @throws \think\db\exception\DataNotFoundException
  545. * @throws \think\db\exception\DbException
  546. * @throws \think\db\exception\ModelNotFoundException
  547. */
  548. public function order_red_list()
  549. {
  550. [$page, $limit] = $this->getPage();
  551. $where = $this->request->params(['status', 'date']);
  552. $where['mer_id'] = $this->request->merId();
  553. $query =Db::name('enterprise_red_order_voucher')->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  554. getModelTime($query, $where['date']);
  555. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  556. $query->where('status',$where['status']);
  557. });
  558. $data['count'] = $query->count();
  559. $data['list'] = $query->page($page, $limit)->order('id desc')->select();
  560. return app('json')->success('ok',$data);
  561. }
  562. public function reward_list()
  563. {
  564. [$page, $limit] = $this->getPage();
  565. $where = $this->request->params(['type', 'account', 'date','identity']);
  566. $where['b.mer_id'] = $this->request->merId();
  567. $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')
  568. ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  569. getModelTime($query, $where['date'],'b.create_time');
  570. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  571. $query->where('b.type',$where['type']);
  572. })->when(isset($where['identity']) && $where['identity'] !== '', function ($query) use ($where) {
  573. $query->where('eu.identity',$where['identity']);
  574. })->when(isset($where['account']) && $where['account'] !== '', function ($query) use ($where) {
  575. $query->whereLike('u.account','%'.$where['account'].'%');
  576. });
  577. $query->where('type','<>',8);
  578. $data['count'] = $query->count();
  579. $data['list'] = $query->page($page, $limit)->order('b.enterprise_user_bill desc')->select()->each(function ($v) use ($where){
  580. if($v['identity']==0){
  581. $identity_name='普通用户';
  582. }else if ($v['identity']==100){
  583. $identity_name='合伙人';
  584. }else{
  585. $identity_name=Db::name('enterprise_performance_divvy')->where('state',1)->where('mer_id', $where['b.mer_id'])->where('id',$v['identity'])->value('name');
  586. }
  587. $v['identity_name']=$identity_name?$identity_name:'普通用户';
  588. return $v;
  589. });
  590. $count = $query->whereIn('type', [1,2,3,4,6,7])->sum('money');
  591. $query_sql_1 = clone $query;
  592. $query_sql_2 = clone $query;
  593. $query_sql_3 = clone $query;
  594. $query_sql_4 = clone $query;
  595. $query_sql_6 = clone $query;
  596. $query_sql_7 = clone $query;
  597. //type 1-推荐奖 2-业绩奖 3-服务中心分红 4-推荐代理商收益 5- 消费增值
  598. $count1 = $query_sql_1->where('type', 1)->sum('money');
  599. $count2 = $query_sql_2->where('type', 2)->sum('money');
  600. $count3 = $query_sql_3->where('type', 3)->sum('money');
  601. $count4 = $query_sql_4->where('type', 4)->sum('money');
  602. $count6 = $query_sql_6->where('type', 6)->sum('money');
  603. $count7 = $query_sql_7->where('type', 7)->sum('money');
  604. $data['countmoyer']=[
  605. ['className' => 'el-icon-s-goods', 'count' => $count, 'field' => '元', 'name' => '奖励总额', 'info' => '奖励总额 = 分享奖+业绩奖+代理商分红+推荐代理商收益+运营中心收益+人工奖励佣金'],
  606. ['className' => 'el-icon-s-goods', 'count' => $count1, 'field' => '元', 'name' => '分享奖', 'info' => ''],
  607. ['className' => 'el-icon-s-goods', 'count' => $count2, 'field' => '元', 'name' => '业绩奖', 'info' => ''],
  608. ['className' => 'el-icon-s-goods', 'count' => $count3, 'field' => '元', 'name' => '代理商分红', 'info' => ''],
  609. ['className' => 'el-icon-s-goods', 'count' => $count4, 'field' => '元', 'name' => '推荐代理商收益', 'info' => ''],
  610. ['className' => 'el-icon-s-goods', 'count' => $count6, 'field' => '元', 'name' => '运营中心收益', 'info' => ''],
  611. ['className' => 'el-icon-s-goods', 'count' => $count7, 'field' => '元', 'name' => '人工奖励佣金', 'info' => ''],
  612. ];
  613. return app('json')->success('ok', $data);
  614. }
  615. //商户后台-奖励统计 导出功能
  616. public function reward_excel()
  617. {
  618. $where = $this->request->params(['type', 'account', 'date', 'identity']);
  619. $where['b.mer_id'] = $this->request->merId();
  620. $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')
  621. ->when(isset($where['date']) && $where['date'] !== '', function ($query) use ($where) {
  622. getModelTime($query, $where['date'], 'b.create_time');
  623. })->when(isset($where['type']) && $where['type'] !== '', function ($query) use ($where) {
  624. $query->where('b.type', $where['type']);
  625. })->when(isset($where['identity']) && $where['identity'] !== '', function ($query) use ($where) {
  626. $query->where('eu.identity', $where['identity']);
  627. })->when(isset($where['account']) && $where['account'] !== '', function ($query) use ($where) {
  628. $query->whereLike('u.account', '%' . $where['account'] . '%');
  629. });
  630. $list = $query->order('b.enterprise_user_bill desc')->select();
  631. foreach ($list as $k=>$v){
  632. $v['type_name']='';
  633. $v['identity_name']='';
  634. if($v['type'] == 1) $v['type_name']='分享奖';
  635. if($v['type'] == 2) $v['type_name']='业绩奖';
  636. if($v['type'] == 3) $v['type_name']='代理商分红';
  637. if($v['type'] == 4) $v['type_name']='推荐代理商收益';
  638. if($v['type'] == 5) $v['type_name']='消费增值系统佣金';
  639. if($v['identity'] == 0){
  640. $v['identity_name']='普通用户';
  641. }else if($v['identity'] == 100){
  642. $v['identity_name']='合伙人';
  643. }else{
  644. $identity_name=Db::name('enterprise_performance_divvy')->where('state',1)->where('mer_id', $where['b.mer_id'])->where('id',$v['identity'])->value('name');
  645. $v['identity_name']=$identity_name?$identity_name:'普通用户';
  646. }
  647. $arr[]=array(
  648. $v['enterprise_user_bill'],
  649. $v['create_time'],
  650. $v['nickname'],
  651. $v['account'],
  652. $v['type_name'],
  653. $v['money'],
  654. $v['identity_name'],
  655. $v['title'],
  656. );
  657. }
  658. $header = [
  659. 'ID','创建时间','用户昵称','用户账号(手机号)','佣金名称','金额(元)','当前身份','奖励来源'
  660. ];
  661. $filename = '奖励统计'.date('YmdHis').'_'.rand(10000,99999);
  662. $title = '奖励统计';
  663. $name = '奖励统计';
  664. $info = '生成时间:' . date('Y-m-d H:i:s',time());
  665. $suffix='xlsx';
  666. $path='extract';
  667. unset($_instance);
  668. $_instance = SpreadsheetExcelService::instance_xin();
  669. $_path =$_instance
  670. ->createOrActive()
  671. ->setExcelHeader($header)
  672. ->setExcelTile($title, $name, $info)
  673. ->setExcelContent($arr)
  674. ->excelSave($filename, $suffix, $path);
  675. $data= [
  676. 'name' => $filename.'.'.$suffix,
  677. 'status' => 1,
  678. 'path' => '/'.$_path
  679. ];
  680. return app('json')->success('ok',$data);
  681. }
  682. }