合并本地

This commit is contained in:
liuxiaoquan 2023-03-17 18:16:04 +08:00
commit 69a82e7c1c
5 changed files with 1371 additions and 9 deletions

View File

@ -15,6 +15,7 @@ use app\admin\validate\AdminCheck;
use OSS\Core\OssException;
use OSS\OssClient;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Session;
@ -506,6 +507,495 @@ class Api extends BaseController
}
/**
* 后台首页获取支付等数据
* @return mixed
* @author xaboy
* @day 2020/6/25
*/
public function main()
{
$res = Cache::store('file')->remember(self::class . '@main', function () {
$today = $this->mainGroup('today');
$yesterday = $this->mainGroup('yesterday');
$lastWeek = $this->mainGroup(date('Y-m-d', strtotime('- 7day')));
$lastWeekRate = [];
foreach ($lastWeek as $k => $item) {
$lastWeekRate[$k] = $this->getRate($item, $today[$k], 4);
}
return compact('today', 'yesterday', 'lastWeekRate');
}, 2000 + random_int(600, 1200));
// $jyq=Db::connect('shop')->table('eb_product_order_log')->where('area_id',510502)->cache(true)->sum('product_price');
// $lmtq=Db::connect('shop')->table('eb_product_order_log')->where('area_id',510504)->cache(true)->sum('product_price');
// $region=[
// 'jyq'=>$jyq,
// 'lmtq'=>$lmtq,
// 'nxq'=>0,
// 'lx'=>0,
// 'hjx'=>0,
// 'xyx'=>0,
// 'glx'=>0,
// ];
// $jyq1=Db::connect('shop')->table('eb_product_order_log')->where('area_id',510502)->where('mer_type_id',4)->cache(true)->sum('product_price');
// $lmtq1=Db::connect('shop')->table('eb_product_order_log')->where('area_id',510504)->where('mer_type_id',4)->cache(true)->sum('product_price');
// $personal=[
// 'jyq'=>$jyq1,
// 'lmtq'=>$lmtq1,
// 'nxq'=>0,
// 'lx'=>0,
// 'hjx'=>0,
// 'xyx'=>0,
// 'glx'=>0,
// ];
// $res['region']=$region;
// $res['personal']=$personal;
$result = ['data' => $res];
return table_assign(0, '', $result);
}
/**
* @param $date
* @return array
* @author xaboy
* @day 2020/6/25
*/
protected function mainGroup($date,$merId=null)
{
$payPrice = getModelTime(Db::connect('shop')->table('eb_store_order')->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
}), $date, 'pay_time')->sum('pay_price');
$payUser = getModelTime(Db::connect('shop')->table('eb_store_order')->where('paid', 1)->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
}), $date, 'pay_time')->group('uid')->count();
$userNum = (float)Db::connect('shop')->table('eb_user')->when($date, function ($query, $date) {
getModelTime($query, $date, 'create_time');
})->count();
$storeNum = (float)Db::connect('shop')->table('eb_merchant')->where('is_del', 0)->when($date, function ($query, $date) {
getModelTime($query, $date);
})->count();
$visitUserNum = (float)Db::connect('shop')->table('eb_user_visit')->alias('A')->join('eb_store_product B', 'A.type_id = B.product_id')->when($date, function ($query, $date) {
getModelTime($query, $date, 'A.create_time');
})->when($merId, function ($query, $merId) {
$query->where('B.mer_id', $merId);
})->where('A.type', 'product')->group('uid')->count();
$visitNum = (float)Db::connect('shop')->table('eb_user_visit')->when($date, function ($query, $date) {
getModelTime($query, $date, 'create_time');
})->whereIn('type', ['page', 'smallProgram'])->count();
return compact('payPrice','userNum', 'storeNum', 'visitUserNum', 'visitNum','payUser');
}
/**
* @param $last
* @param $today
* @param int $scale
* @return int|string|null
* @author xaboy
* @day 2020/6/25
*/
protected function getRate($last, $today, $scale = 2)
{
if ($last == $today)
return 0;
else if ($last == 0)
return $today;
else if ($today == 0)
return -$last;
else
return (float)bcdiv(bcsub((string)$today, (string)$last, $scale), (string)$last, $scale);
}
/**
* @param 后台首页获取订单数据
* @return mixed
* @author xaboy
* @day 2020/6/25
*/
public function order()
{
$date = get_params('date') ??'lately7';
$merId = get_params('mer_id') ??'';
$res = Cache::remember(self::class . '@order' . $merId . $date, function () use ($merId, $date) {
if ($date == 'year') {
$m = date('m',time());
$time[] = $m;
do{
$time[] = '0'. ($m - 1);
$m--;
}while($m > 1);
$time = array_reverse($time);
} else {
$time = getDatesBetweenTwoDays(getStartModelTime($date), date('Y-m-d'));
}
$list = $this->orderGroupNum($date, $merId)->toArray();
$list = array_combine(array_column($list, 'day'), $list);
$data = [];
foreach ($time as $item) {
$data[] = [
'day' => $item,
'total' => $list[$item]['total'] ?? 0,
'user' => $list[$item]['user'] ?? 0,
'pay_price' => $list[$item]['pay_price'] ?? 0
];
}
return $data;
}, 2000 + random_int(600, 1200));
$result['day'] = array_column($res,'day');
$result['total'] = array_column($res,'total');
$result['user'] = array_column($res,'user');
$result['pay_price'] = array_column($res,'pay_price');
// halt($result);
$result = ['data' => $result];
return table_assign(0, '', $result);
}
public function orderGroupNum($date, $merId = null)
{
$field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m-%d\') as `day`');
if ($date == 'year'){
$field = Db::raw('sum(pay_price) as pay_price,count(*) as total,count(distinct uid) as user,pay_time,from_unixtime(unix_timestamp(pay_time),\'%m\') as `day`');
}
$query = Db::connect('shop')->table('eb_store_order')->field($field)
->where('paid', 1)->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
});
return $query->order('pay_time ASC')->group('day')->select();
}
/**
* @param 后台首页获取用户数据
* @return \think\response\Json
* @author xaboy
* @day 2020/9/24
*/
public function user()
{
$date = get_params('date') ?? 'today';
$merId = get_params('mer_id') ??'';
$res = Cache::store('file')->remember(self::class . '@user' .$merId . $date, function () use ($merId, $date) {
$visitUser = Db::connect('shop')->table('eb_user_visit')->alias('A')->join('eb_store_product B', 'A.type_id = B.product_id')->when($date, function ($query, $date) {
getModelTime($query, $date, 'A.create_time');
})->when($merId, function ($query, $merId) {
$query->where('B.mer_id', $merId);
})->where('A.type', 'product')->group('uid')->count();
$paid = 0;
$orderUser = Db::connect('shop')->table('eb_store_order')->when($paid, function ($query, $paid) {
$query->where('paid', $paid);
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) use ($paid) {
if (!$paid) {
getModelTime($query, $date);
// $query->where(function ($query) use ($date) {
// $query->where(function ($query) use ($date) {
// $query->where('paid', 1);
// getModelTime($query, $date, 'pay_time');
// })->whereOr(function ($query) use ($date) {
// $query->where('paid', 0);
// getModelTime($query, $date);
// });
// });
} else
getModelTime($query, $date, 'pay_time');
})->group('uid')->count();
$orderPrice = Db::connect('shop')->table('eb_store_order')->when($paid, function ($query, $paid) {
$query->where('paid', $paid);
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) use ($paid) {
if (!$paid) {
$query->where(function ($query) use ($date) {
$query->where(function ($query) use ($date) {
$query->where('paid', 1);
getModelTime($query, $date, 'pay_time');
})->whereOr(function ($query) use ($date) {
$query->where('paid', 0);
getModelTime($query, $date);
});
});
} else
getModelTime($query, $date, 'pay_time');
})->sum('pay_price');
$paid = 1;
$payOrderUser = Db::connect('shop')->table('eb_store_order')->when($paid, function ($query, $paid) {
$query->where('paid', $paid);
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) use ($paid) {
if (!$paid) {
getModelTime($query, $date);
// $query->where(function ($query) use ($date) {
// $query->where(function ($query) use ($date) {
// $query->where('paid', 1);
// getModelTime($query, $date, 'pay_time');
// })->whereOr(function ($query) use ($date) {
// $query->where('paid', 0);
// getModelTime($query, $date);
// });
// });
} else
getModelTime($query, $date, 'pay_time');
})->group('uid')->count();
$payOrderPrice = Db::connect('shop')->table('eb_store_order')->when($paid, function ($query, $paid) {
$query->where('paid', $paid);
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) use ($paid) {
if (!$paid) {
$query->where(function ($query) use ($date) {
$query->where(function ($query) use ($date) {
$query->where('paid', 1);
getModelTime($query, $date, 'pay_time');
})->whereOr(function ($query) use ($date) {
$query->where('paid', 0);
getModelTime($query, $date);
});
});
} else
getModelTime($query, $date, 'pay_time');
})->sum('pay_price');
$userRate = $payOrderUser ? bcdiv((string)$payOrderPrice, (string)$payOrderUser, 2) : 0;
$orderRate = $visitUser ? bcdiv((string)$orderUser, (string)$visitUser, 2) : 0;
$payOrderRate = $orderUser ? bcdiv((string)$payOrderUser, (string)$orderUser, 2) : 0;
return compact('visitUser', 'orderUser', 'orderPrice', 'payOrderUser', 'payOrderPrice', 'payOrderRate', 'userRate', 'orderRate');
}, 2000 + random_int(600, 1200));
$result = ['data' => $res];
return table_assign(0, '', $result);
}
/**
* @param 用户统计饼状图
* @return mixed
* @author xaboy
* @day 2020/6/25
*/
public function userRate()
{
$date = get_params('date') ?? 'today';
$merId = get_params('mer_id') ??'';
$res = Cache::store('file')->remember(self::class . '@userRate' . $merId . $date, function () use ($merId,$date) {
$paid = 1;
$uids = Db::connect('shop')->table('eb_store_order')->when($paid, function ($query, $paid) {
$query->where('paid', $paid);
})->when($merId, function ($query, $merId) {
$query->where('mer_id', $merId);
})->when($date, function ($query, $date) {
getModelTime($query, $date, 'pay_time');
})->group('uid')->field(Db::raw('uid,sum(pay_price) as pay_price,count(order_id) as total'))->select()->toArray();
$ids = array_column($uids, 'uid');
$userPayCount = Db::connect('shop')->table('eb_user')->whereIn('uid', $ids)->column('pay_count', 'uid');
$user = count($uids);
$oldUser = 0;
$totalPrice = 0;
$oldTotalPrice = 0;
foreach ($uids as $uid) {
$totalPrice = bcadd((string)$uid['pay_price'], (string)$totalPrice, 2);
if (($userPayCount[$uid['uid']] ?? 0) > $uid['total']) {
$oldUser++;
$oldTotalPrice = bcadd((string)$uid['pay_price'], (string)$oldTotalPrice, 2);
}
}
$newTotalPrice = bcsub((string)$totalPrice, (string)$oldTotalPrice, 2);
$newUser = $user - $oldUser;
return compact('newTotalPrice', 'newUser', 'oldTotalPrice', 'oldUser', 'totalPrice', 'user');
}, 2000 + random_int(600, 1200));
$result = ['data' => $res];
return table_assign(0, '', $result);
}
/**
* @param 商品支付排行
* @return mixed
* @author xaboy
* @day 2020/6/25
*/
public function product()
{
$date = get_params('date') ?? 'today';
$merId = get_params('mer_id') ??'';
$res = Cache::store('file')->remember(self::class . '@product' . $merId . $date, function () use ($merId, $date) {
return Db::connect('shop')->table('eb_store_order_product')->alias('A')->Join('eb_store_order B', 'A.order_id = B.order_id')
->field(Db::raw('sum(A.product_num) as total,A.product_id,cart_info'))
->withAttr('cart_info', function ($val) {
return json_decode($val, true);
})
->withAttr('store_name', function ($val,$date) {
return $date['cart_info']['product']['store_name'];
})
->withAttr('image', function ($val,$date) {
return $date['cart_info']['product']['image'];
})
->when($date, function ($query, $date) {
getModelTime($query, $date, 'B.pay_time');
})->when($merId, function ($query, $merId) {
$query->where('B.mer_id', $merId);
})->where('B.paid', 1)->group('A.product_id')->limit(10)->order('total DESC')->select();
}, 2000 + random_int(600, 1200));
$result = ['data' => $res];
return table_assign(0, '', $result);
}
//商品访客排行
public function productVisit()
{
$date = get_params('date') ?? 'today';
$merId = get_params('mer_id') ??'';
$res = Cache::store('file')->remember(self::class . '@productVisit' . $merId . $date, function () use ($merId, $date) {
return Db::connect('shop')->table('eb_user_visit')->alias('A')->join('eb_store_product B', 'A.type_id = B.product_id')
->join('eb_merchant C', 'C.mer_id = B.mer_id')
->field(Db::raw('count(A.type_id) as total,B.image,B.store_name'))
->when($date, function ($query, $date) {
getModelTime($query, $date, 'A.create_time');
})->where('A.type', 'product')->where('B.mer_id', $merId)->group('A.type_id')->order('total DESC')
->limit(10)->select();
}, 2000 + random_int(600, 1200));
$result = ['data' => $res];
return table_assign(0, '', $result);
}
/**
* @param 商品加购排行
* @return mixed
* @author xaboy
* @day 2020/6/25
*/
public function productCart()
{
$date = get_params('date') ?? 'today';
$merId = get_params('mer_id') ??'';
$res = Cache::store('file')->remember(self::class . '@productCart' . $merId . $date, function () use ($merId, $date) {
return Db::connect('shop')->table('eb_store_product')->alias('A')->Join('eb_store_cart B', 'A.product_id = B.product_id')
->field(Db::raw('sum(B.cart_num) as total,A.product_id,A.store_name,A.image'))
->when($date, function ($query, $date) {
getModelTime($query, $date, 'B.create_time');
})->when($merId, function ($query, $merId) {
$query->where('A.mer_id', $merId);
})->where('B.product_type', 0)->where('B.is_pay', 0)->where('B.is_del', 0)
->where('B.is_new', 0)->where('B.is_fail', 0)->group('A.product_id')->limit(10)->order('total DESC')->select();
}, 2000 + random_int(600, 1200));
$result = ['data' => $res];
return table_assign(0, '', $result);
}
// 接收微信支付状态的通知
public function notify()
{
$app = $this->payment();
// 用 easywechat 封装的方法接收微信的信息, 根据 $message 的内容进行处理, 之后要告知微信服务器处理好了, 否则微信会一直请求这个 url, 发送信息
$response = $app->handlePaidNotify(function($message, $fail){
// 首先查看 order 表, 如果 order 表有记录, 表示已经支付过了
$order = Order::where('order_sn', $message['out_trade_no'])->first();
if ($order) {
return true; // 如果已经生成订单, 表示已经处理完了, 告诉微信不用再通知了
}
// 查看支付日志
$payLog = PayLog::where('out_trade_no', $message['out_trade_no'])->first();
if (!$payLog || $payLog->paid_at) { // 如果订单不存在 或者 订单已经支付过了
return true; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
}
// return_code 表示通信状态,不代表支付状态
if ($message['return_code'] === 'SUCCESS') {
// 用户是否支付成功
if ($message['result_code'] === 'SUCCESS') {
// 更新支付时间为当前时间
$payLog->paid_at = now();
$post_id = $payLog->post_id;
// 联表查询 post 的相关信息
$post_title = $payLog->post->title;
$post_price = $payLog->post->price;
$post_original_price = $payLog->post->original_price;
$post_cover = $payLog->post->post_cover;
$post_description = $payLog->post->description;
$user_id = $payLog->post->user_id;
// 创建订单记录
Order::create([
'order_sn' => $message['out_trade_no'],
'total_fee' => $message['total_fee'],
'pay_log_id' => $payLog->id,
'status' => 1,
'user_id' => $user_id,
'paid_at' => $payLog->paid_at,
'post_id' => $post_id,
'post_title' => $post_title,
'post_price' => $post_price,
'post_original_price' => $post_original_price,
'post_cover' => $post_cover,
'post_description' => $post_description,
]);
// 更新 PayLog, 这里的字段都是根据微信支付结果通知的字段设置的(https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_7&index=8)
PayLog::where('out_trade_no', $message['out_trade_no'])->update([
'appid' => $message['appid'],
'bank_type' => $message['bank_type'],
'total_fee' => $message['total_fee'],
'trade_type' => $message['trade_type'],
'is_subscribe' => $message['is_subscribe'],
'mch_id' => $message['mch_id'],
'nonce_str' => $message['nonce_str'],
'openid' => $message['openid'],
'sign' => $message['sign'],
'cash_fee' => $message['cash_fee'],
'fee_type' => $message['fee_type'],
'transaction_id' => $message['transaction_id'],
'time_end' => $payLog->paid_at,
'result_code' => $message['result_code'],
'return_code' => $message['return_code'],
]);
}
} else {
// 如果支付失败, 也更新 PayLog, 跟上面一样, 就是多了 error 信息
PayLog::where('out_trade_no', $message['out_trade_no'])->update([
'appid' => $message['appid'],
'bank_type' => $message['bank_type'],
'total_fee' => $message['total_fee'],
'trade_type' => $message['trade_type'],
'is_subscribe' => $message['is_subscribe'],
'mch_id' => $message['mch_id'],
'nonce_str' => $message['nonce_str'],
'openid' => $message['openid'],
'sign' => $message['sign'],
'cash_fee' => $message['cash_fee'],
'fee_type' => $message['fee_type'],
'transaction_id' => $message['transaction_id'],
'time_end' => $payLog->paid_at,
'result_code' => $message['result_code'],
'return_code' => $message['return_code'],
'err_code' => $message['err_code'],
'err_code_des' => $message['err_code_des'],
]);
return $fail('通信失败,请稍后再通知我');
}
return true; // 返回处理完成
});
// 这里是必须这样返回的, 会发送给微信服务器处理结果
return $response;
}
}

View File

@ -74,8 +74,8 @@ class Analysis extends BaseController
$map[] = ['a.type_id','in','2,3'];
$list['num_1'] = Db::connect('shop')->table('eb_merchant')->alias('a')->join('eb_merchant_address b','a.mer_id = b.mer_id')->where($mmm)->where($map)->count();
//企业通过我们平台采购的农产品
$list['num_3'] = Db::connect('shop')->table('eb_user')->alias('a')->join('eb_nk_user b','a.uid = b.user_id')->join('eb_product_order_log c','a.uid = c.uid')->join('nk_lihaink_cn.fa_szxc_information_useraddress d','b.n_user_id = d.user_id')->where($www)->where('a.status',1)->where('c.status',1)->count();
// $list['num_3'] = Db::connect('shop')->table('eb_user')->alias('a')->join('eb_nk_user b','a.uid = b.user_id')->join('eb_product_order_log c','a.uid = c.uid')->join('nk_lihaink_cn.fa_szxc_information_useraddress d','b.n_user_id = d.user_id')->where($www)->where('a.status',1)->where('c.status',1)->count();
$list['num_3'] = 0;
//镇农产品需求量分析(事业单位、企业、居民)
//农产品市场行情分析、显示
//农产品市内需求量
@ -137,8 +137,8 @@ class Analysis extends BaseController
$list['num_1'] = Db::connect('shop')->table('eb_merchant')->alias('a')->join('eb_merchant_address b','a.mer_id = b.mer_id')->where($mmm)->where($map)->count();
//企业通过我们平台采购的农产品
$list['num_3'] = Db::connect('shop')->table('eb_user')->alias('a')->join('eb_nk_user b','a.uid = b.user_id')->join('eb_product_order_log c','a.uid = c.uid')->join('nk_lihaink_cn.fa_szxc_information_useraddress d','b.n_user_id = d.user_id')->where($www)->where('a.status',1)->where('c.status',1)->count();
// $list['num_3'] = Db::connect('shop')->table('eb_user')->alias('a')->join('eb_nk_user b','a.uid = b.user_id')->join('eb_product_order_log c','a.uid = c.uid')->join('nk_lihaink_cn.fa_szxc_information_useraddress d','b.n_user_id = d.user_id')->where($www)->where('a.status',1)->where('c.status',1)->count();
$list['num_3'] = 0;
//镇农产品需求量分析(事业单位、企业、居民)
//农产品市场行情分析、显示
//农产品市内需求量

View File

@ -53,4 +53,19 @@ class StoreCategory extends BaseController
return to_assign(0, '', $list);
}
/**
* 平台商品分类
*
*/
public function getAllList()
{
$where['mer_id'] = 0;
$where['is_show'] = 0;
$data = $this->category->getStoreCategoryList(0,1);
$list = FormatList::FormatCategory($data,'store_category_id', 'pid', 'cate_name','child', 'id', 'title');
return to_assign(0, '', $list);
}
}

View File

@ -19,6 +19,91 @@
.layui-card-body .layui-timeline-item {
padding-bottom: 5px;
}
.layui-card-header span {
position: absolute;
right: 10px;
top: 10px;
}
.layui-sales {
margin-bottom: 0;
overflow: hidden;
color: rgba(0,0,0,.85);
font-size: 30px;
}
.layui-sales-info {
padding-top: 16px;
color: rgba(0,0,0,.65);
white-space: nowrap;
text-overflow: ellipsis;
}
fieldset.layui-field-title {
margin-bottom: 10px;
}
.select_time {
width: 350px;
/* border-radius: 5px; */
float: right;
/*background: #1e3d64;*/
/*left: 74%;*/
/*top: 221%;*/
position: relative;
z-index: 11;
}
.select_time span {
display: block;
width: 60px;
height: 25px;
float: left;
/*background: #4095e5;*/
text-align: center;
line-height: 25px;
position: relative;
top:-28px;
right: -30%;
border-left: 1px solid #dcdfe6;
border-radius: 4px 0 0 4px;
box-shadow: none!important;
cursor:pointer;
}
.select_time .active {
color: #fff;
background-color: #6394f9;
border-color: #6394f9;
box-shadow: -1px 0 0 0 #6394f9;
}
#btsspan{
position: relative;
width: 250px;
left:33%;
z-index: 11;
}
#btsspan span{
display: block;
width: 60px;
height: 25px;
float: left;
/*background: #4095e5;*/
text-align: center;
line-height: 25px;
position: relative;
border-left: 1px solid #dcdfe6;
border-radius: 4px 0 0 4px;
box-shadow: none!important;
cursor:pointer;
}
.el-row .active {
color: #fff;
background-color: #6394f9;
border-color: #6394f9;
box-shadow: -1px 0 0 0 #6394f9;
}
</style>
{/block}
<!-- 主体 -->
@ -122,23 +207,795 @@
</tr>
</table>
</div>
<div class="layui-card">
<div id="chartYear" style="width: 100%;height:240px;"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="p-3">
<div class="layui-row layui-col-space15">
<div class="layui-col-xs6 layui-col-md3">
<div class="layui-card">
<div class="layui-card-header">支付金额<span class="layui-badge layui-badge-blue pull-right" style="background-color:#6394f9">今日</span></div>
<div class="layui-card-body">
<div class="layui-sales" id="pay1">0</div>
<div class="layui-sales-info" style="height: 125px;">
周同比 <span id="pay2">0%</span>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 66px;"></fieldset>
<div>昨日数据 <span id="pay3">0</span></div>
</div>
</div>
</div>
</div>
<div class="layui-col-xs6 layui-col-md3">
<div class="layui-card">
<div class="layui-card-header">支付人数<span class="layui-badge layui-badge-blue pull-right" style="background-color:#6394f9">今日</span></div>
<div class="layui-card-body">
<div class="layui-sales" id="pay4">0</div>
<div class="layui-sales-info" style="height: 125px;">
周环比 <span id="pay5">0%</span>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 66px;"></fieldset>
<div>昨日数据 <span id="pay6">0</span></div>
</div>
</div>
</div>
</div>
<div class="layui-col-xs6 layui-col-md3">
<div class="layui-card">
<div class="layui-card-header">访客<span class="layui-badge layui-badge-green pull-right" style="background-color:#6394f9">今日</span></div>
<div class="layui-card-body">
<div class="layui-sales" id="pay7">0</div>
<div class="layui-sales-info" >
周环比 <span id="pay8">0%</span>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 66px;"></fieldset>
<div>昨日数据 <span id="pay9">0</span></div>
</div>
</div>
</div>
</div>
<div class="layui-col-xs6 layui-col-md3">
<div class="layui-card">
<div class="layui-card-header">关注店铺 <span class="layui-badge pull-right" style="background-color:#6394f9">今日</span></div>
<div class="layui-card-body">
<div class="layui-sales" id="pay10">0</div>
<div class="layui-sales-info" >
周环比 <span id="pay11">0%</span>
<fieldset class="layui-elem-field layui-field-title" style="position: relative;margin-top: 66px;"></fieldset>
<div>昨日数据 <span id="pay12">0</span></div>
</div>
</div>
</div>
</div>
<div class="layui-row">
<div class="layui-card">
<div class="layui-card-header" style="position: relative">
<div style="font-size: 28;font-weight: 700;line-height: 36px;">
支付订单
</div>
<div class="select_time" id="select_time1">
<span data-type="lately7">近七天</span>
<span class="active" data-type="lately30">近30天</span>
<span data-type="month">本月</span>
<span data-type="year">本年</span>
</div>
</div>
<div class="layui-card-body">
<div id="main" style="height: 350px;"></div>
</div>
</div>
</div>
<div class="layui-col-xs6 layui-col-md8">
<div class="layui-card">
<div class="layui-card-header" style="font-size: 28;font-weight: 700;line-height: 36px;">成交用户</div>
<div class="select_time" id="select_time2">
<span data-type="lately7">近七天</span>
<span class="active" data-type="lately30">近30天</span>
<span data-type="month">本月</span>
<span data-type="year">本年</span>
</div>
<div class="layui-card">
<div id="chartView2" style="width: 100%;height:500px;"></div>
</div>
</div>
</div>
<div class="layui-col-xs6 layui-col-md4">
<div class="layui-card">
<div class="layui-card-header" style="font-size: 28;font-weight: 700;line-height: 36px;">用户统计</div>
<div class="select_time" id="select_time3">
<span data-type="lately7">近七天</span>
<span class="active" data-type="lately30">近30天</span>
<span data-type="month">本月</span>
<span data-type="year">本年</span>
</div>
<div data-v-5dd143d3="" class="pieChart-switch el-row">
<div class="bts" id="btsspan">
<span class="active" data-type="money">金额</span>
<span data-type="user">客户数</span>
</div>
</div>
<div class="layui-card">
<div id="chartView3" style="width: 100%;height:500px;"></div>
</div>
</div>
</div>
</div>
</div>
<div class="p-3">
<div class="layui-row layui-col-space15">
<div class="layui-col-xs6 layui-col-md4">
<div class="layui-card">
<div class="layui-card-header" style="font-size: 28;font-weight: 700;line-height: 36px;">商品支付排行</div>
<div class="select_time" id="select_time4">
<span data-type="lately7">近七天</span>
<span data-type="lately30">近30天</span>
<span data-type="month">本月</span>
<span class="active" data-type="year">本年</span>
</div>
<div class="layui-card">
<table class="layui-hide" id="goods1" lay-filter="admin"></table>
</div>
</div>
</div>
<div class="layui-col-xs6 layui-col-md4">
<div class="layui-card">
<div class="layui-card-header" style="font-size: 28;font-weight: 700;line-height: 36px;">商品访客排行</div>
<div class="select_time" id="select_time5">
<span data-type="lately7">近七天</span>
<span data-type="lately30">近30天</span>
<span data-type="month">本月</span>
<span class="active" data-type="year">本年</span>
</div>
<div class="layui-card">
<table class="layui-hide" id="goods2" lay-filter="admin"></table>
</div>
</div>
</div>
<div class="layui-col-xs6 layui-col-md4">
<div class="layui-card">
<div class="layui-card-header" style="font-size: 28;font-weight: 700;line-height: 36px;">商品加购排行</div>
<div class="select_time" id="select_time6">
<span data-type="lately7">近七天</span>
<span data-type="lately30">近30天</span>
<span data-type="month">本月</span>
<span class="active" data-type="year">本年</span>
</div>
<div class="layui-card">
<table class="layui-hide" id="goods3" lay-filter="admin"></table>
</div>
</div>
</div>
</div>
</div>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script src="https://cdn.staticfile.org/echarts/5.3.0/echarts.min.js"></script>
<script src="{__GOUGU__}/third_party/echart/china.js"></script>
<script src="/static/assets/js/jquery.min.js"></script>
<script>
const moduleInit = ['tool'];
const moduleInit = ['tool','admin'];
function gouguInit() {
var table = layui.table, tool = layui.tool, form = layui.form;
// 年月日的切换
var that = this
$("#select_time1").on("click", "span", function() {
// 此时要注意这个索引号的问题
index = $(this).index() - 1;
// 点击当前a 高亮显示 调用active
$(this)
.addClass("active")
.siblings("span")
.removeClass("active");
get_order(this.dataset.type);
});
$("#select_time2").on("click", "span", function() {
// 此时要注意这个索引号的问题
index = $(this).index() - 1;
// 点击当前a 高亮显示 调用active
$(this)
.addClass("active")
.siblings("span")
.removeClass("active");
get_view_data(this.dataset.type);
});
$("#select_time3").on("click", "span", function() {
// 此时要注意这个索引号的问题
index = $(this).index() - 1;
// 点击当前a 高亮显示 调用active
$(this)
.addClass("active")
.siblings("span")
.removeClass("active");
var type = $('#btsspan').children('.active').attr('data-type');
get_view_data2(this.dataset.type,type);
});
$("#btsspan").on("click", "span", function() {
// 此时要注意这个索引号的问题
index = $(this).index() - 1;
// 点击当前a 高亮显示 调用active
$(this)
.addClass("active")
.siblings("span")
.removeClass("active");
var date = $('#select_time3').children('.active').attr('data-type');
var type = this.dataset.type;
get_view_data2(date,type);
});
$("#select_time4").on("click", "span", function() {
// 此时要注意这个索引号的问题
index = $(this).index() - 1;
// 点击当前a 高亮显示 调用active
$(this)
.addClass("active")
.siblings("span")
.removeClass("active");
get_goods1(table,this.dataset.type);
});
$("#select_time5").on("click", "span", function() {
// 此时要注意这个索引号的问题
index = $(this).index() - 1;
// 点击当前a 高亮显示 调用active
$(this)
.addClass("active")
.siblings("span")
.removeClass("active");
get_goods2(table,this.dataset.type);
});
$("#select_time6").on("click", "span", function() {
// 此时要注意这个索引号的问题
index = $(this).index() - 1;
// 点击当前a 高亮显示 调用active
$(this)
.addClass("active")
.siblings("span")
.removeClass("active");
get_goods3(table,this.dataset.type);
});
get_main();
get_order('lately30');
get_view_data('lately30');
get_view_data2('lately30','money');
get_goods1(table,'year');
get_goods2(table,'year');
get_goods3(table,'year');
}
function get_main() {
$.ajax({
url: "/admin/api/main",
type: 'get',
data: {},
success: function (e) {
if (e.code == 0) {
$('#pay1').html(e.data.today.payPrice);
$('#pay2').html(e.data.lastWeekRate.payPrice);
$('#pay3').html(e.data.yesterday.payPrice);
$('#pay4').html(e.data.today.payUser);
$('#pay5').html(e.data.lastWeekRate.payUser);
$('#pay6').html(e.data.yesterday.payUser);
$('#pay7').html(e.data.today.visitNum);
$('#pay8').html(e.data.lastWeekRate.visitNum);
$('#pay9').html(e.data.yesterday.visitNum);
$('#pay10').html(e.data.today.visitUserNum);
$('#pay11').html(e.data.lastWeekRate.visitUserNum);
$('#pay12').html(e.data.yesterday.visitUserNum);
}
}
})
}
function get_order(date) {
var myChart = echarts.init(document.getElementById('main'));
$.ajax({
url: "/admin/api/order?date="+date,
type: 'get',
data: {},
success: function (e) {
if (e.code == 0) {
var option;
option = {
title: {
text: ''
},
tooltip: {
trigger: 'axis'
},
legend: {
left:0,
data: ['订单数', '支付人数', '支付金额']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'category',
boundaryGap: false,
data:e.data.day
},
yAxis: [
{
type: 'value',
name: '订单/支付人数',
axisLine: {
symbol: 'arrow',
lineStyle: {
type: 'dashed'
// ...
}
}
},
{
type: 'value',
name: '支付金额',
axisLine: {
symbol: 'arrow',
lineStyle: {
type: 'dashed'
// ...
}
}
},
],
series: [
{
name: '订单数',
type: 'line',
stack: 'Total',
data: e.data.total
},
{
name: '支付人数',
type: 'line',
stack: 'Total',
data: e.data.user
},
{
name: '支付金额',
type: 'line',
stack: 'Total',
data: e.data.pay_price
},
]
};
myChart.setOption(option);
}
}
})
}
var chartView2 = echarts.init(document.getElementById('chartView2'));
var chartView3 = echarts.init(document.getElementById('chartView3'));
function get_view_data(date) {
$.ajax({
url: "/admin/api/user?date="+date,
type: 'get',
data: {},
success: function (e) {
if (e.code == 0) {
var visitUser = e.data.visitUser; //访客人数
var payOrderUser = e.data.payOrderUser;//支付人数
var orderUser = e.data.orderUser;//下单人数
var payOrderPrice = e.data.payOrderPrice;//支付金额
var payOrderRate = e.data.payOrderRate;//下单-支付转化率
var userRate = e.data.userRate;//客单价
var orderRate = e.data.orderRate;//访客-下单转化率
var orderPrice = e.data.orderPrice;//下单金额
var colors = ['#5b8ff9', '#5ad8a6', '#5d7092'];
// { value: payOrderUser, name: '支付' },
// { value: orderUser, name: '下单' },
// { value: visitUser, name: '访问' }
var lineargroup = [
{
value: 60,
name: '访客人数',
number: visitUser,
oriname: '访客',
color: ['#eff4fe'],
text1: '',
value1: '',
text2: '',
value2: '',
},
{
value: 40,
name: '下单人数',
number: orderUser,
oriname: '下单',
color: ['#effbf6'],
text1: '下单金额',
value1: orderPrice,
text2: '',
value2: '',
},
{
value: 20,
name: '支付人数',
number: payOrderUser,
oriname: '支付',
color: ['#eff4fe'],
text1: '支付金额',
value1: payOrderPrice,
text2: '客单价',
value2: userRate,
},
];
var data1 = [];
var data2 = [];
for (var i = 0; i < lineargroup.length; i++) {
var obj1 = {
value: lineargroup[i].value,
num: lineargroup[i].number,
name: lineargroup[i].oriname,
};
var obj2 = {
value: lineargroup[i].value,
name: lineargroup[i].name,
data: lineargroup[i],
itemStyle: {
normal: {
color: lineargroup[i].color[0],
borderWidth: 0,
opacity: 1,
},
},
};
data1.push(obj1);
data2.push(obj2);
}
var option = {
backgroundColor: '#ffffff',
color: colors,
// tooltip: {
// trigger: 'item',
// formatter: '{b}-下单转换率: {c}%',
// },
xAxis: [
{
show: false,
inverse: true,
position: 'top',
},
],
yAxis: [
{
position: 'left',
top: '120',
show: false,
boundaryGap: false,
inverse: true,
},
],
series: [
{
top: 0,
type: 'funnel',
height: '400',
gap: 10,
minSize: 150,
left: '30%',
width: '60%',
z: 3,
markLine :{
symbol:'none',
data:[
[
{ x: '83%', y: '27%' },
{
x: '85%',
y: '27%',
value: '访客-下单转化率:'+orderRate*100+'%',
lineStyle: { color: '#333' },
},
],
[
{ x: '76%', y: '55%' },
{
x: '80%',
y: '55%',
value: '下单-支付转化率:'+payOrderRate*100+'%',
lineStyle: { color: '#333' },
},
],
]
},
label: {
show: true,
position: 'inside',
fontSize: '14',
formatter: function (d) {
var ins = d.name;
return ins;
},
rich: {
aa: {
padding: [8, 0, 6, 0],
},
},
},
data: data1,
},
{
top: 0,
type: 'funnel',
height: '400',
gap: 10,
minSize: 400,
left: '12%',
width: '55%',
z: 2,
label: {
normal: {
color: '#333',
position: 'insideLeft',
padding: [11, 25],
formatter: function (d) {
let ins =
'{aa|}' +
d.name +
'{aa|}' +
d.data.data.text1 +
'{aa|}' +
d.data.data.text2 +
'\n{bb|}' +
d.data.data.number +
'{bb|}' +
d.data.data.value1 +
'{bb|}' +
d.data.data.value2 +
'';
return ins;
},
rich: {
aa: {
align: 'right',
color: '#666',
fontSize: '12',
lineHeight: '30',
padding: [0, 20, 0, 0],
},
bb: {
align: 'right',
color: '#333',
fontSize: '12',
padding: [0, 25, 0, 0],
},
},
},
},
tooltip: {
show: false,
},
data: data2,
},
],
};
chartView2.setOption(option);
setTimeout(function () {
window.onresize = function () {
chartView.resize();
myChart.resize();
}
})
}
}
})
}
function get_view_data2(date,type) {
$.ajax({
url: "/admin/api/userRate?date="+date,
type: 'post',
data: {},
success: function (e) {
if (e.code == 0) {
if(type == 'user'){
var newUser = e.data.newUser;
var oldUser = e.data.oldUser;
var title = '客户数';
}else{
var newUser = e.data.newTotalPrice;
var oldUser = e.data.oldTotalPrice;
var title = '金额';
}
var newTotalPrice = e.data.newTotalPrice;
var oldTotalPrice = e.data.oldTotalPrice;
var totalPrice = e.data.totalPrice;
var user = e.data.user;
option = {
tooltip: {
trigger: 'item'
},
legend: {
orient: 'vertical',
top: '5%',
x: 'left',
y:'bottom',
},
series: [
{
name: title,
type: 'pie',
radius: ['40%', '70%'],
avoidLabelOverlap: false,
color:['#5b8ff9','#FFBF26'],
label: {
show: false,
position: 'center'
},
emphasis: {
label: {
show: true,
fontSize: 40,
fontWeight: 'bold'
}
},
labelLine: {
show: false
},
data: [
{ value: newUser, name: '新用户'},
{ value: oldUser, name: '老用户'},
]
}
]
};
chartView3.setOption(option);
setTimeout(function () {
window.onresize = function () {
chartView.resize();
myChart.resize();
}
})
}
}
})
}
function get_goods1(table,date){
layui.pageTable = table.render({
elem: '#goods1',
title: '列表',
toolbar: '#toolbarDemo',
defaultToolbar: [],// 去掉“筛选列”,“导出”,“打印”,
url: '/admin/api/product?date='+date, //数据接口
page: false, //开启分页
limit: 10,
cols: [
[
{
title: '排名',
align: 'center',
templet: function (d) {
return d.LAY_TABLE_INDEX+1;
}
},{
field: 'store_name',
title: '名称',
templet: function (d) {
var html = '<div><img src="'+d.image+'" style="width:30px; height:30px;"> '+d.store_name+'</div>';
return html;
}
}, {
field: 'total',
title: '支付数',
align: 'center',
}
]
]
});
}
function get_goods2(table,date){
layui.pageTable = table.render({
elem: '#goods2',
title: '列表',
toolbar: '#toolbarDemo',
defaultToolbar: [],// 去掉“筛选列”,“导出”,“打印”,
url: '/admin/api/productVisit?date='+date, //数据接口
page: false, //开启分页
limit: 10,
cols: [
[
{
title: '排名',
align: 'center',
templet: function (d) {
return d.LAY_TABLE_INDEX+1;
}
},{
field: 'store_name',
title: '名称',
templet: function (d) {
var html = '<div><img src="'+d.image+'" style="width:30px; height:30px;"> '+d.store_name+'</div>';
return html;
}
}, {
field: 'total',
title: '支付数',
align: 'center',
}
]
]
});
}
function get_goods3(table,date){
layui.pageTable = table.render({
elem: '#goods3',
title: '列表',
toolbar: '#toolbarDemo',
defaultToolbar: [],// 去掉“筛选列”,“导出”,“打印”,
url: '/admin/api/productCart?date='+date, //数据接口
page: false, //开启分页
limit: 10,
cols: [
[
{
title: '排名',
align: 'center',
templet: function (d) {
return d.LAY_TABLE_INDEX+1;
}
},{
field: 'store_name',
title: '名称',
templet: function (d) {
var html = '<div><img src="'+d.image+'" style="width:30px; height:30px;"> '+d.store_name+'</div>';
return html;
}
}, {
field: 'total',
title: '支付数',
align: 'center',
}
]
]
});
}
</script>
{/block}

View File

@ -49,7 +49,7 @@
"config": {
"preferred-install": "dist",
"allow-plugins": {
"easywechat-composer/easywechat-composer": false
"easywechat-composer/easywechat-composer": true
}
},
"scripts": {