123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use think\App;
- use think\facade\Db;
- class Data extends BaseController
- {
-
-
- public function todaySalesVolume()
- {
- $rs = Db::name('sale')
- ->field('count(id) orders_number,sum(total_price) money')
- ->where('is_del', 0)
- ->whereDay('addtime', 'today')
- ->find();
- $temp = [
- 'orders_number' => isset($rs['orders_number']) ? $rs['orders_number'] : 0,
- 'money' => isset($rs['money']) ? $rs['money'] : 0,
- ];
- return app_show(0, '请求成功', $temp);
- }
-
- public function todaySalesChampion()
- {
- $temp = Db::name('sale')
- ->field('count(id) orders,sum(total_price) money,apply_id')
- ->where('is_del', 0)
- ->whereDay('addtime', 'today')
- ->group('apply_id')
- ->order('money', 'desc')
- ->limit(1)
- ->buildSql();
- $rs = Db::table($temp)
- ->alias('t')
- ->field('t.apply_id,t.orders,t.money,u.itemid company_id, c.`name` company, u.nickname')
- ->leftJoin('depart_user u', 'u.uid=t.apply_id AND u.is_del=0')
- ->leftJoin('company_item c', 'c.id=u.itemid AND c.is_del=0')
- ->select()
- ->toArray();
- return app_show(0, '请求成功', empty($rs[0]) ? [] : $rs[0]);
- }
-
- public function todayPurchase()
- {
- $rs = Db::name('purchease_order')
- ->field('count(id) orders_number,sum(good_num) good_num')
- ->where('is_del', 0)
- ->whereDay('addtime', 'today')
- ->find();
- $consult_info_total = Db::name('consult_info')
- ->where('is_del', 0)
- ->whereDay('addtime', 'today')
- ->count('id');
- $consult_bids_total = Db::name('consult_bids')
- ->where('is_del', 0)
- ->whereDay('addtime', 'today')
- ->count('id');
- $data = [
- 'orders_number' => isset($rs['orders_number']) ? $rs['orders_number'] : 0,
- 'good_num' => isset($rs['good_num']) ? $rs['good_num'] : 0,
- 'consult_info_total' => $consult_info_total,
- 'consult_bids_total' => $consult_bids_total,
- ];
- return app_show(0, '请求成功', $data);
- }
-
-
- public function totalZixunPurchease()
- {
-
- $zixun_total = Db::name('consult_info')
- ->where(['is_del' => 0, 'bargain_code' => ''])
- ->count('id');
-
- $zixun_bids = Db::name('consult_info')
- ->alias('ci')
- ->join('consult_bids cb','cb.infoNo=ci.infoNo')
- ->join('consult_order co', 'co.zxNo = cb.zxNo ')
- ->where(['cb.is_del'=>0,'ci.is_del'=>0,'bargain_code'=>''])
- ->where('co.endtime', '>=', date('Y-m-d H:i:s'))
- ->group('cb.infoNo')
- ->count('cb.id');
-
- $not_feedback = $zixun_total - $zixun_bids;
-
- $purchease_total = Db::name('purchease_order')
- ->where('is_del', 0)
- ->count('id');
-
- $purchease_wait_confirm = Db::name('purchease_order')
- ->where(['is_del' => 0, 'status' => 0])
- ->count('id');
-
- return app_show(0, '请求成功', [
- 'zixun_total' => $zixun_total,
- 'not_feedback' => $not_feedback,
- 'purchease_total' => $purchease_total,
- 'purchease_wait_confirm' => $purchease_wait_confirm,
- ]);
- }
-
- public function waitSendTotal()
- {
- $rs = Db::name('sale')
- ->field('count(id) order_num,sum(wsend_num) wsend_num')
- ->where(['is_del' => 0, 'status' => 1])
- ->find();
- return app_show(0, '请求成功', $rs);
- }
-
- public function todaySale()
- {
- $temp = Db::name('sale')
- ->alias('s')
- ->field('s.id,s.apply_id,s.total_price,u.nickname,u.itemid')
- ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
- ->where('s.is_del', 0)
- ->whereDay('s.addtime', 'today')
- ->buildSql();
- $rs = Db::table($temp)
- ->alias('t')
- ->field('itemid companyId,c.`name` companyName,SUM(t.total_price) total_price,COUNT(t.id) total_order')
- ->leftJoin('company_item c', 'c.id=t.itemid')
- ->group('t.itemid')
- ->order('total_price', 'desc')
- ->limit(3)
- ->select()
- ->toArray();
- return app_show(0, '请求成功', $rs);
- }
-
-
- public function monthFinishRate()
- {
-
- $sales_volume = Db::name('sale')
- ->alias('s')
- ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
- ->leftJoin('company_item c', 'c.id=u.itemid AND c.is_del=0')
- ->group('u.itemid')
- ->column('(sum(s.total_price) - sum(s.th_fee)) sales_volume,u.itemid,c.name', 'c.name');
-
-
- $sale_indicators = Db::connect('mysql3')
- ->table('cfp_depart_tips')
- ->field('id,total_tips,department')
- ->where(['year' => date('Y年'), 'month' => date('n月')])
- ->select()
- ->toArray();
-
- foreach ($sale_indicators as &$value) {
- $temp = isset($sales_volume[$value['department']]['sales_volume']) ? $sales_volume[$value['department']]['sales_volume'] : 0;
- $value['finish_rate'] = round(($temp / $value['total_tips']) * 100, 5);
- }
-
- usort($sale_indicators, function ($left, $right) {
- return ($left['finish_rate'] > $right['finish_rate']) ? -1 : 1;
- });
-
- $total_finish_rate = round((array_sum(array_column($sales_volume, 'sales_volume')) / array_sum(array_column($sale_indicators, 'total_tips'))) * 100, 2);
- return app_show(0, '请求成功', ['list' => $sale_indicators, 'total_finish_rate' => $total_finish_rate]);
- }
-
- public function orderTransferRateToday()
- {
- $consulting = Db::name('sale')
- ->alias('s')
- ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
- ->where(['s.order_type' => 2, 's.is_del' => 0])
- ->whereDay('s.addtime')
- ->group('u.itemid')
- ->column('count(s.id) consulting', 'u.itemid');
- $rs = Db::name('consult_order')
- ->alias('c')
- ->field('count(c.id) total,c.depart companyId,i.name companyName')
- ->leftJoin('company_item i', 'i.id=c.depart AND i.is_del=0')
- ->where(['c.is_del' => 0])
- ->whereDay('c.addtime')
- ->group('c.depart')
- ->append(['transfer_rate'])
- ->withAttr('transfer_rate', function ($val, $data) use ($consulting) {
- $consult = isset($consulting[$data['companyId']]) ? $consulting[$data['companyId']] : 0;
- return round(($consult / $data['total']) * 100, 2);
- })
- ->select()
- ->toArray();
- return app_show(0, '请求成功', $rs);
- }
-
- public function orderTransferRateMonth()
- {
- $consulting = Db::name('sale')
- ->alias('s')
- ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
- ->where(['s.order_type' => 2, 's.is_del' => 0])
- ->whereMonth('s.addtime')
- ->group('u.itemid')
- ->column('count(s.id) consulting', 'u.itemid');
- $rs = Db::name('consult_order')
- ->alias('c')
- ->field('count(c.id) total,c.depart companyId,i.name companyName')
- ->leftJoin('company_item i', 'i.id=c.depart AND i.is_del=0')
- ->where(['c.is_del' => 0])
- ->whereMonth('c.addtime')
- ->group('c.depart')
- ->append(['transfer_rate'])
- ->withAttr('transfer_rate', function ($val, $data) use ($consulting) {
- $consult = isset($consulting[$data['companyId']]) ? $consulting[$data['companyId']] : 0;
- return round(($consult / $data['total']) * 100, 2);
- })
- ->select()
- ->toArray();
- return app_show(0, '请求成功', $rs);
- }
-
- public function orderTransferRateYear()
- {
- $consulting = Db::name('sale')
- ->alias('s')
- ->leftJoin('depart_user u', 'u.uid=s.apply_id AND u.is_del=0')
- ->where(['s.order_type' => 2, 's.is_del' => 0])
- ->whereYear('s.addtime', date('Y'))
- ->group('u.itemid')
- ->column('count(s.id) consulting', 'u.itemid');
- $rs = Db::name('consult_order')
- ->alias('c')
- ->field('count(c.id) total,c.depart companyId,i.name companyName')
- ->leftJoin('company_item i', 'i.id=c.depart AND i.is_del=0')
- ->where(['c.is_del' => 0])
- ->whereYear('c.addtime', date('Y'))
- ->group('c.depart')
- ->append(['transfer_rate'])
- ->withAttr('transfer_rate', function ($val, $data) use ($consulting) {
- $consult = isset($consulting[$data['companyId']]) ? $consulting[$data['companyId']] : 0;
- return round(($consult / $data['total']) * 100, 2);
- })
- ->select()
- ->toArray();
- return app_show(0, '请求成功', $rs);
- }
- }
|