Order.php 27 KB

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