From bc0e6ba1429106f4cc01dd99e8a077acb16624cb Mon Sep 17 00:00:00 2001 From: yaosen <741606767@qq.com> Date: Tue, 25 Jun 2024 14:40:30 +0800 Subject: [PATCH] a --- admin/src/router/index.js | 11 +- .../dashboard/admin/components/PanelGroup.vue | 64 +++++- admin/src/views/order/product.vue | 125 ++++++++++++ .../app/admin/controller/IndexController.php | 187 ++++++++++++------ service/app/model/Orders.php | 2 +- 5 files changed, 324 insertions(+), 65 deletions(-) create mode 100644 admin/src/views/order/product.vue diff --git a/admin/src/router/index.js b/admin/src/router/index.js index cb2bc929..d6e92d1d 100644 --- a/admin/src/router/index.js +++ b/admin/src/router/index.js @@ -161,7 +161,16 @@ export const asyncRoutes = [ title: '流转订单', roles: ['order_back', 'editor'] } - } + }, + { + path: 'product', + component: () => import('@/views/order/product'), + name: 'productNameList', + meta: { + title: '产品统计列表', + roles: ['order_pub', 'editor'] + } + }, ] }, { diff --git a/admin/src/views/dashboard/admin/components/PanelGroup.vue b/admin/src/views/dashboard/admin/components/PanelGroup.vue index 5e8cd9ed..ecef75dd 100644 --- a/admin/src/views/dashboard/admin/components/PanelGroup.vue +++ b/admin/src/views/dashboard/admin/components/PanelGroup.vue @@ -52,6 +52,58 @@ + +
+
+ +
+
+
+ 核销订单数 +
+ +
+
+
+ +
+
+ +
+
+
+ 核销订单金额 +
+ +
+
+
+ +
+
+ +
+
+
+ 退款订单数 +
+ +
+
+
+ +
+
+ +
+
+
+ 退款订单金额 +
+ +
+
+
@@ -67,7 +119,11 @@ export default { wait:0, doing:0, all:0, - total:0 + total:0, + asset:0, + asset_price:0, + refund:0, + refund_price:0 } }, mounted() { @@ -77,8 +133,12 @@ export default { this.doing = parseFloat(res.data.doing) this.all = parseFloat(res.data.all) this.total = parseFloat(res.data.total)/100 + this.asset = parseFloat(res.data.asset) + this.asset_price = parseFloat(res.data.asset_price)/100 + this.refund = parseFloat(res.data.refund) + this.refund_price = parseFloat(res.data.refund_price)/100 }).catch(err=>{ - console.log(err) + console.log(err) }) }) }, diff --git a/admin/src/views/order/product.vue b/admin/src/views/order/product.vue new file mode 100644 index 00000000..7b7a3341 --- /dev/null +++ b/admin/src/views/order/product.vue @@ -0,0 +1,125 @@ + + + + + diff --git a/service/app/admin/controller/IndexController.php b/service/app/admin/controller/IndexController.php index dde07b51..6c3ec714 100644 --- a/service/app/admin/controller/IndexController.php +++ b/service/app/admin/controller/IndexController.php @@ -1,4 +1,5 @@ admin->id); + $lastTime = Redis::get('CRM:USER:ONLINE:' . $request->admin->id); $end = Redis::hGet('CRM:USER:ONLINE:END', $request->admin->id); - if(!empty($lastTime) && time() - $lastTime <= 5 * 60) { - } elseif(empty($lastTime) && $end) { - $has = Onlines::where("admin_id", $request->admin->id)->order('id desc')->find(); - if($has && empty($has->end)) { - Onlines::where("id", $has->id)->update(['end' => $end]); - }else{ + if (!empty($lastTime) && time() - $lastTime <= 5 * 60) { + } elseif (empty($lastTime) && $end) { + $has = Onlines::where("admin_id", $request->admin->id)->order('id desc')->find(); + if ($has && empty($has->end)) { + Onlines::where("id", $has->id)->update(['end' => $end]); + } else { $start = Redis::hGet('CRM:USER:ONLINE', $request->admin->id); //创建一个新的 Onlines::create([ @@ -31,77 +34,105 @@ class IndexController extends base 'end' => $end ]); } - //创建一个新的 - Onlines::create([ - 'admin_id' => $request->admin->id, - 'start' => time(), - 'end' => 0 - ]); - } else { - //第一次,给建个新的 - Onlines::create([ - 'admin_id' => $request->admin->id, - 'start' => time(), - 'end' => 0 - ]); - } + //创建一个新的 + Onlines::create([ + 'admin_id' => $request->admin->id, + 'start' => time(), + 'end' => 0 + ]); + } else { + //第一次,给建个新的 + Onlines::create([ + 'admin_id' => $request->admin->id, + 'start' => time(), + 'end' => 0 + ]); + } - Redis::Set('CRM:USER:ONLINE:'.$request->admin->id, time(), 'ex', 10 *60); + Redis::Set('CRM:USER:ONLINE:' . $request->admin->id, time(), 'ex', 10 * 60); Redis::hSet('CRM:USER:ONLINE:END', $request->admin->id, time() + 60); - - $new = Redis::get('CRM:USER:ONLINE:NEW:'.$request->admin->id); - Redis::del('CRM:USER:ONLINE:NEW:'.$request->admin->id); - $back = Redis::set('CRM:USER:ONLINE:FOLLOW:LOCK:'. $request->admin->id, time(), 'EX', 60, 'nx'); + $new = Redis::get('CRM:USER:ONLINE:NEW:' . $request->admin->id); + Redis::del('CRM:USER:ONLINE:NEW:' . $request->admin->id); + $back = Redis::set('CRM:USER:ONLINE:FOLLOW:LOCK:' . $request->admin->id, time(), 'EX', 60, 'nx'); $follow = $backs = 0; - if($back) { - $follow = Orders::where('admin_id', $request->admin->id)->whereBetween('next_follow',[1,(time()-60)*1000])->count(); + if ($back) { + $follow = Orders::where('admin_id', $request->admin->id)->whereBetween('next_follow', [1, (time() - 60) * 1000])->count(); $backs = Backs::where('admin', $request->admin->id)->where('status', 0)->count(); } - return $this->success(['new'=> $new ??0, 'follow'=> $follow,'back' => $backs]); - } + return $this->success(['new' => $new ?? 0, 'follow' => $follow, 'back' => $backs]); + } - public function line() { + public function line() + { $time = strtotime(date('Y-m-d')); $data = []; - for($i=10; $i>0; $i--) { - $_time = $time - 3600*24*$i; - $d = Finances::whereBetween('create_time', [$_time, $_time + 24*3600-1]) - ->where('status',1) + for ($i = 10; $i > 0; $i--) { + $_time = $time - 3600 * 24 * $i; + $d = Finances::whereBetween('create_time', [$_time, $_time + 24 * 3600 - 1]) + ->where('status', 1) ->fieldRaw('SUM(IF(type=1,`total`,0))/100 as total, SUM(IF(type=2,`total`,0))/100 as refund') ->find(); $d->date = date("m-d", $_time); $data[] = $d; } $_data = []; - foreach($data as $d) { + foreach ($data as $d) { $_data['title'][] = trim($d->date); - $_data['total'][] = $d->total ??0; - $_data['refund'][] = abs($d->refund ??0); + $_data['total'][] = $d->total ?? 0; + $_data['refund'][] = abs($d->refund ?? 0); } return $this->success($_data); } - public function orders(Request $request) { - - $order = Orders::where('admin_id', $request->admin->id)->fieldRaw('SUM(IF(status=0,1,0)) as wait, SUM(IF(status=1,1,0)) as doing, SUM(total_price) as total,count(id) as `all`')->find(); + public function orders(Request $request) + { - return $this->success(['wait' => $order->wait ?? 0,'doing' => $order->doing ?? 0,'total' => $order->total ?? 0,'all' => $order->all ?? 0 ]); + $order = Orders::where('admin_id', $request->admin->id)->fieldRaw(' + SUM(IF(status=0,1,0)) as wait, + SUM(IF(status=1,1,0)) as doing, + SUM(total_price) as total, + count(id) as `all`, + SUM(IF(asset_price>0 AND status=2,1,0)) as asset, + SUM(IF(asset_price>0 AND status=2,asset_price,0)) as asset_price, + SUM(CASE + WHEN (os = 1 AND STATUS = 5) OR (os = 3 AND STATUS = 4) OR (os = 2 AND STATUS = 1) THEN 1 + ELSE 0 + END) AS refund, + SUM(CASE + WHEN (os = 1 AND STATUS = 5) OR (os = 3 AND STATUS = 4) OR (os = 2 AND STATUS = 1) THEN actual_price + ELSE 0 + END) AS refund_price + ')->find(); + +// Log::warning("=====",['sql'=>$order]); + + return $this->success([ + 'wait' => $order->wait ?? 0, + 'doing' => $order->doing ?? 0, + 'total' => $order->total ?? 0, + 'all' => $order->all ?? 0, + 'asset' => $order->asset ?? 0, + 'asset_price' => $order->asset_price ?? 0, + 'refund' => $order->refund ?? 0, + 'refund_price' => $order->refund_price ?? 0 + ]); } - public function pie() { + public function pie() + { $time = strtotime(date('Y-m-d')); - $_time = $time - 3600*24*10; + $_time = $time - 3600 * 24 * 10; $data = Orders::whereBetween('create_time', [$_time, time()])->fieldRaw('sum(total_price) as value, status')->group('status')->select(); $ddd = []; - foreach(Orders::StatusName as $k=>$d) { + foreach (Orders::StatusName as $k => $d) { $item['name'] = $d; $item['value'] = 0; - foreach($data as $dd) { - if($dd->status == $k) { - $item['value'] = $dd->value/100; + foreach ($data as $dd) { + if ($dd->status == $k) { + $item['value'] = $dd->value / 100; break; } } @@ -111,21 +142,23 @@ class IndexController extends base return $this->success($ddd); } - public function Info(Request $request) { + public function Info(Request $request) + { $info = Admins::where('id', $request->admin->id)->find(); return $this->success([ - 'roles'=> [$info->is_super ? 'admin': 'editor'], - 'avatar'=> $info->avatar ?? '/avatar.webp', - 'name'=> $info->name, - 'is_anchor'=> $info->is_anchor ?1:0, - 'oss'=> Orders::OSS + 'roles' => [$info->is_super ? 'admin' : 'editor'], + 'avatar' => $info->avatar ?? '/avatar.webp', + 'name' => $info->name, + 'is_anchor' => $info->is_anchor ? 1 : 0, + 'oss' => Orders::OSS ]); } - public function qiniu() { + public function qiniu() + { // 用于签名的公钥和私钥 $accessKey = config('qiniu.accessKey'); $secretKey = config('qiniu.secretKey'); @@ -134,20 +167,52 @@ class IndexController extends base $auth = new Auth($accessKey, $secretKey); $bucket = 'tt-api'; - $key = 'imgs/'.Date('Ym/d-His').'.jpg'; + $key = 'imgs/' . Date('Ym/d-His') . '.jpg'; // 生成上传Token $token = $auth->uploadToken($bucket); - return $this->success(['qiniu_key'=> $key, 'qiniu_token' => $token,'qiniu_url' => 'http://up-z2.qiniup.com']); + return $this->success(['qiniu_key' => $key, 'qiniu_token' => $token, 'qiniu_url' => 'http://up-z2.qiniup.com']); } - public function avatar(Request $request) { + public function avatar(Request $request) + { $file = $request->file("file"); - $filename = '/uploads/avatar/'.$request->admin->id.'.'.$file->getUploadExtension(); - $file->move(public_path().$filename); + $filename = '/uploads/avatar/' . $request->admin->id . '.' . $file->getUploadExtension(); + $file->move(public_path() . $filename); $item = Admins::where('id', $request->admin->id)->find(); $item->avatar = $filename; $item->save(); return $this->success($filename); } + + public function productNameList(Request $request) + { + $limit = $request->get('limit', 10); + $product_name = $request->get('product_name'); + $list = Orders::where('admin_id',$request->admin->id) + ->fieldRaw(' + os,product_name, + SUM(IF(status=0,1,0)) as wait, + SUM(IF(status=1,1,0)) as doing, + SUM(total_price) as total, + count(id) as `all`, + SUM(IF(asset_price>0 AND status=2,1,0)) as asset, + SUM(IF(asset_price>0 AND status=2,asset_price,0)) as asset_price, + SUM(CASE + WHEN (os = 1 AND STATUS = 5) OR (os = 3 AND STATUS = 4) OR (os = 2 AND STATUS = 1) THEN 1 + ELSE 0 + END) AS refund, + SUM(CASE + WHEN (os = 1 AND STATUS = 5) OR (os = 3 AND STATUS = 4) OR (os = 2 AND STATUS = 1) THEN actual_price + ELSE 0 + END) AS refund_price + ') + ->group('os,product_name') + ->order('total desc'); + if (!empty($product_name)){ + $list = $list->where('product_name','like','%'.$product_name.'%'); + } + $list = $list->paginate($limit); + return $this->success($list); + } } \ No newline at end of file diff --git a/service/app/model/Orders.php b/service/app/model/Orders.php index 86bc4bea..7b4faa84 100644 --- a/service/app/model/Orders.php +++ b/service/app/model/Orders.php @@ -104,7 +104,7 @@ class Orders extends base{ } public function backs() { - return $this->hasOne(Backs::class, 'order_id')->visible(['status']); + return $this->hasOne(Backs::class, 'order_id')->where('status',0)->visible(['status','admin_id']); } public function follow() {