diff --git a/crmeb/.constant b/crmeb/.constant
index 6b646d01..e9e5c179 100644
--- a/crmeb/.constant
+++ b/crmeb/.constant
@@ -1,3 +1,3 @@
adminInfo->toArray();
- $roles = explode(',',$adminInfo['roles']);
- $site_logo = SystemConfig::getOneConfig('menu_name','site_logo')->toArray();
+ $roles = explode(',', $adminInfo['roles']);
+ $site_logo = SystemConfig::getOneConfig('menu_name', 'site_logo')->toArray();
$this->assign([
- 'menuList'=>SystemMenus::menuList(),
- 'site_logo'=>json_decode($site_logo['value'],true),
- 'new_order_audio_link'=>sysConfig('new_order_audio_link'),
- 'role_name'=>SystemRole::where('id',$roles[0])->field('role_name')->find()
+ 'menuList' => SystemMenus::menuList(),
+ 'site_logo' => json_decode($site_logo['value'], true),
+ 'new_order_audio_link' => sys_config('new_order_audio_link'),
+ 'role_name' => SystemRole::where('id', $roles[0])->field('role_name')->find(),
+ 'workermanPort' => Config::get('workerman.admin.port')
]);
return $this->fetch();
}
- //后台首页内容
+ //后台首页内容
public function main()
{
/*首页第一行统计*/
$now_month = strtotime(date('Y-m'));//本月
- $pre_month = strtotime(date('Y-m',strtotime('-1 month')));//上月
+ $pre_month = strtotime(date('Y-m', strtotime('-1 month')));//上月
$now_day = strtotime(date('Y-m-d'));//今日
- $pre_day = strtotime(date('Y-m-d',strtotime('-1 day')));//昨天时间戳
- $beforyester_day = strtotime(date('Y-m-d',strtotime('-2 day')));//前天时间戳
+ $pre_day = strtotime(date('Y-m-d', strtotime('-1 day')));//昨天时间戳
+ $beforyester_day = strtotime(date('Y-m-d', strtotime('-2 day')));//前天时间戳
//待发货数量
- $topData['orderDeliveryNum'] = StoreOrderModel::where('status',0)
- ->where('paid',1)
- ->where('refund_status',0)
+ $topData['orderDeliveryNum'] = StoreOrderModel::where('status', 0)
+ ->where('paid', 1)
+ ->where('refund_status', 0)
->count();
//退换货订单数
- $topData['orderRefundNum'] = StoreOrderModel::where('paid',1)
- ->where('refund_status','IN','1')
+ $topData['orderRefundNum'] = StoreOrderModel::where('paid', 1)
+ ->where('refund_status', 'IN', '1')
->count();
//库存预警
$replenishment_num = SystemConfig::getConfigValue('store_stock') > 0 ? SystemConfig::getConfigValue('store_stock') : 20;//库存预警界限
- $topData['stockProduct'] = StoreProduct::where('stock','<=',$replenishment_num)->where('is_show',1)->where('is_del',0)->count();
+ $topData['stockProduct'] = StoreProduct::where('stock', '<=', $replenishment_num)->where('is_show', 1)->where('is_del', 0)->count();
//待处理提现
- $topData['treatedExtract'] = UserExtractModel::where('status',0)->count();
+ $topData['treatedExtract'] = UserExtractModel::where('status', 0)->count();
//订单数->昨日
- $now_day_order_p = StoreOrderModel::where('paid',1)->whereTime('pay_time','yesterday')->count();
- $pre_day_order_p = StoreOrderModel::where('paid',1)->where('pay_time','>',$pre_day)->where('pay_time','<',$now_day)->count();
+ $now_day_order_p = StoreOrderModel::where('paid', 1)->whereTime('pay_time', 'yesterday')->count();
+ $pre_day_order_p = StoreOrderModel::where('paid', 1)->where('pay_time', '>', $pre_day)->where('pay_time', '<', $now_day)->count();
$first_line['d_num'] = [
'data' => $now_day_order_p ? $now_day_order_p : 0,
'percent' => abs($now_day_order_p - $pre_day_order_p),
@@ -72,8 +74,8 @@ class Index extends AuthController
];
//交易额->昨天
- $now_month_order_p = StoreOrderModel::where('paid',1)->whereTime('pay_time','yesterday')->sum('pay_price');
- $pre_month_order_p = StoreOrderModel::where('paid',1)->where('pay_time','>',$beforyester_day)->where('pay_time','<',$pre_day)->sum('pay_price');
+ $now_month_order_p = StoreOrderModel::where('paid', 1)->whereTime('pay_time', 'yesterday')->sum('pay_price');
+ $pre_month_order_p = StoreOrderModel::where('paid', 1)->where('pay_time', '>', $beforyester_day)->where('pay_time', '<', $pre_day)->sum('pay_price');
$first_line['d_price'] = [
'data' => $now_month_order_p > 0 ? $now_month_order_p : 0,
'percent' => abs($now_month_order_p - $pre_month_order_p),
@@ -81,8 +83,8 @@ class Index extends AuthController
];
//交易额->月
- $now_month_order_p = StoreOrderModel::where('paid',1)->whereTime('pay_time','month')->sum('pay_price');
- $pre_month_order_p = StoreOrderModel::where('paid',1)->where('pay_time','>',$pre_month)->where('pay_time','<',$now_month)->value('sum(pay_price)');
+ $now_month_order_p = StoreOrderModel::where('paid', 1)->whereTime('pay_time', 'month')->sum('pay_price');
+ $pre_month_order_p = StoreOrderModel::where('paid', 1)->where('pay_time', '>', $pre_month)->where('pay_time', '<', $now_month)->value('sum(pay_price)');
$first_line['m_price'] = [
'data' => $now_month_order_p > 0 ? $now_month_order_p : 0,
'percent' => abs($now_month_order_p - $pre_month_order_p),
@@ -90,8 +92,8 @@ class Index extends AuthController
];
//新粉丝->日
- $now_day_user = User::where('add_time','>',$now_day)->count();
- $pre_day_user = User::where('add_time','>',$pre_day)->where('add_time','<',$now_day)->count();
+ $now_day_user = User::where('add_time', '>', $now_day)->count();
+ $pre_day_user = User::where('add_time', '>', $pre_day)->where('add_time', '<', $now_day)->count();
$pre_day_user = $pre_day_user ? $pre_day_user : 0;
$first_line['day'] = [
'data' => $now_day_user ? $now_day_user : 0,
@@ -100,8 +102,8 @@ class Index extends AuthController
];
//新粉丝->月
- $now_month_user = User::where('add_time','>',$now_month)->count();
- $pre_month_user = User::where('add_time','>',$pre_month)->where('add_time','<',$now_month)->count();
+ $now_month_user = User::where('add_time', '>', $now_month)->count();
+ $pre_month_user = User::where('add_time', '>', $pre_month)->where('add_time', '<', $now_month)->count();
$first_line['month'] = [
'data' => $now_month_user ? $now_month_user : 0,
'percent' => abs($now_month_user - $pre_month_user),
@@ -109,8 +111,8 @@ class Index extends AuthController
];
//本月订单总数
- $now_order_info_c = StoreOrderModel::where('add_time','>',$now_month)->count();
- $pre_order_info_c = StoreOrderModel::where('add_time','>',$pre_month)->where('add_time','<',$now_month)->count();
+ $now_order_info_c = StoreOrderModel::where('add_time', '>', $now_month)->count();
+ $pre_order_info_c = StoreOrderModel::where('add_time', '>', $pre_month)->where('add_time', '<', $now_month)->count();
$order_info['first'] = [
'data' => $now_order_info_c ? $now_order_info_c : 0,
'percent' => abs($now_order_info_c - $pre_order_info_c),
@@ -118,10 +120,10 @@ class Index extends AuthController
];
//上月订单总数
- $second_now_month = strtotime(date('Y-m',strtotime('-1 month')));
- $second_pre_month = strtotime(date('Y-m',strtotime('-2 month')));
- $now_order_info_c = StoreOrderModel::where('add_time','>',$pre_month)->where('add_time','<',$now_month)->count();
- $pre_order_info_c = StoreOrderModel::where('add_time','>',$second_pre_month)->where('add_time','<',$second_now_month)->count();
+ $second_now_month = strtotime(date('Y-m', strtotime('-1 month')));
+ $second_pre_month = strtotime(date('Y-m', strtotime('-2 month')));
+ $now_order_info_c = StoreOrderModel::where('add_time', '>', $pre_month)->where('add_time', '<', $now_month)->count();
+ $pre_order_info_c = StoreOrderModel::where('add_time', '>', $second_pre_month)->where('add_time', '<', $second_now_month)->count();
$order_info["second"] = [
'data' => $now_order_info_c ? $now_order_info_c : 0,
'percent' => abs($now_order_info_c - $pre_order_info_c),
@@ -141,385 +143,386 @@ class Index extends AuthController
/**
* 订单图表
*/
- public function orderchart(){
+ public function orderchart()
+ {
header('Content-type:text/json');
- $cycle = $this->request->param('cycle')?:'thirtyday';//默认30天
+ $cycle = $this->request->param('cycle') ?: 'thirtyday';//默认30天
$datalist = [];
- switch ($cycle){
+ switch ($cycle) {
case 'thirtyday':
- $datebefor = date('Y-m-d',strtotime('-30 day'));
+ $datebefor = date('Y-m-d', strtotime('-30 day'));
$dateafter = date('Y-m-d');
//上期
- $pre_datebefor = date('Y-m-d',strtotime('-60 day'));
- $pre_dateafter = date('Y-m-d',strtotime('-30 day'));
- for($i=-30;$i < 0;$i++){
- $datalist[date('m-d',strtotime($i.' day'))] = date('m-d',strtotime($i.' day'));
+ $pre_datebefor = date('Y-m-d', strtotime('-60 day'));
+ $pre_dateafter = date('Y-m-d', strtotime('-30 day'));
+ for ($i = -30; $i < 0; $i++) {
+ $datalist[date('m-d', strtotime($i . ' day'))] = date('m-d', strtotime($i . ' day'));
}
- $order_list = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
+ $order_list = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
->field("FROM_UNIXTIME(add_time,'%m-%d') as day,count(*) as count,sum(pay_price) as price")
->group("FROM_UNIXTIME(add_time, '%Y%m%d')")
->order('add_time asc')
->select()->toArray();
- if(empty($order_list)) return Json::fail('无数据');
- foreach ($order_list as $k=>&$v){
+ if (empty($order_list)) return Json::fail('无数据');
+ foreach ($order_list as $k => &$v) {
$order_list[$v['day']] = $v;
}
$cycle_list = [];
- foreach ($datalist as $dk=>$dd){
- if(!empty($order_list[$dd])){
+ foreach ($datalist as $dk => $dd) {
+ if (!empty($order_list[$dd])) {
$cycle_list[$dd] = $order_list[$dd];
- }else{
- $cycle_list[$dd] = ['count'=>0,'day'=>$dd,'price'=>''];
+ } else {
+ $cycle_list[$dd] = ['count' => 0, 'day' => $dd, 'price' => ''];
}
}
$chartdata = [];
$data = [];//临时
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
$chartdata['yAxis']['maxprice'] = 0;//最大值金额
- foreach ($cycle_list as $k=>$v){
+ foreach ($cycle_list as $k => $v) {
$data['day'][] = $v['day'];
$data['count'][] = $v['count'];
- $data['price'][] = round($v['price'],2);
- if($chartdata['yAxis']['maxnum'] < $v['count'])
+ $data['price'][] = round($v['price'], 2);
+ if ($chartdata['yAxis']['maxnum'] < $v['count'])
$chartdata['yAxis']['maxnum'] = $v['count'];//日最大订单数
- if($chartdata['yAxis']['maxprice'] < $v['price'])
+ if ($chartdata['yAxis']['maxprice'] < $v['price'])
$chartdata['yAxis']['maxprice'] = $v['price'];//日最大金额
}
- $chartdata['legend'] = ['订单金额','订单数'];//分类
+ $chartdata['legend'] = ['订单金额', '订单数'];//分类
$chartdata['xAxis'] = $data['day'];//X轴值
//,'itemStyle'=>$series
- $series= ['normal'=>['label'=>['show'=>true,'position'=>'top']]];
- $chartdata['series'][] = ['name'=>$chartdata['legend'][0],'type'=>'bar','itemStyle'=>$series,'data'=>$data['price']];//分类1值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][1],'type'=>'bar','itemStyle'=>$series,'data'=>$data['count']];//分类2值
+ $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
+ $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['price']];//分类1值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['count']];//分类2值
//统计总数上期
- $pre_total = StoreOrderModel::where('add_time','between time',[$pre_datebefor,$pre_dateafter])
+ $pre_total = StoreOrderModel::where('add_time', 'between time', [$pre_datebefor, $pre_dateafter])
->field("count(*) as count,sum(pay_price) as price")
->find();
- if($pre_total){
+ if ($pre_total) {
$chartdata['pre_cycle']['count'] = [
- 'data' => $pre_total['count']? : 0
+ 'data' => $pre_total['count'] ?: 0
];
$chartdata['pre_cycle']['price'] = [
- 'data' => $pre_total['price']? : 0
+ 'data' => $pre_total['price'] ?: 0
];
}
//统计总数
- $total = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
+ $total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
->field("count(*) as count,sum(pay_price) as price")
->find();
- if($total){
+ if ($total) {
$cha_count = intval($pre_total['count']) - intval($total['count']);
- $pre_total['count'] = $pre_total['count']==0 ? 1 : $pre_total['count'];
+ $pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
$chartdata['cycle']['count'] = [
- 'data' => $total['count']? : 0,
- 'percent' => round((abs($cha_count)/intval($pre_total['count'])*100),2),
+ 'data' => $total['count'] ?: 0,
+ 'percent' => round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
];
- $cha_price = round($pre_total['price'],2) - round($total['price'],2);
- $pre_total['price'] = $pre_total['price']==0 ? 1 : $pre_total['price'];
+ $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
+ $pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
$chartdata['cycle']['price'] = [
- 'data' => $total['price']? : 0,
- 'percent' => round(abs($cha_price)/$pre_total['price']*100,2),
+ 'data' => $total['price'] ?: 0,
+ 'percent' => round(abs($cha_price) / $pre_total['price'] * 100, 2),
'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
];
}
- return app('json')->success('ok',$chartdata);
+ return app('json')->success('ok', $chartdata);
break;
case 'week':
- $weekarray=array(['周日'],['周一'],['周二'],['周三'],['周四'],['周五'],['周六']);
- $datebefor = date('Y-m-d',strtotime('-1 week Monday'));
- $dateafter = date('Y-m-d',strtotime('-1 week Sunday'));
- $order_list = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
+ $weekarray = array(['周日'], ['周一'], ['周二'], ['周三'], ['周四'], ['周五'], ['周六']);
+ $datebefor = date('Y-m-d', strtotime('-1 week Monday'));
+ $dateafter = date('Y-m-d', strtotime('-1 week Sunday'));
+ $order_list = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
->field("FROM_UNIXTIME(add_time,'%w') as day,count(*) as count,sum(pay_price) as price")
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
->order('add_time asc')
->select()->toArray();
//数据查询重新处理
$new_order_list = [];
- foreach ($order_list as $k=>$v){
+ foreach ($order_list as $k => $v) {
$new_order_list[$v['day']] = $v;
}
$now_datebefor = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
- $now_dateafter = date('Y-m-d',strtotime("+1 day"));
- $now_order_list = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
+ $now_dateafter = date('Y-m-d', strtotime("+1 day"));
+ $now_order_list = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
->field("FROM_UNIXTIME(add_time,'%w') as day,count(*) as count,sum(pay_price) as price")
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
->order('add_time asc')
->select()->toArray();
//数据查询重新处理 key 变为当前值
$new_now_order_list = [];
- foreach ($now_order_list as $k=>$v){
+ foreach ($now_order_list as $k => $v) {
$new_now_order_list[$v['day']] = $v;
}
- foreach ($weekarray as $dk=>$dd){
- if(!empty($new_order_list[$dk])){
+ foreach ($weekarray as $dk => $dd) {
+ if (!empty($new_order_list[$dk])) {
$weekarray[$dk]['pre'] = $new_order_list[$dk];
- }else{
- $weekarray[$dk]['pre'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
+ } else {
+ $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
}
- if(!empty($new_now_order_list[$dk])){
+ if (!empty($new_now_order_list[$dk])) {
$weekarray[$dk]['now'] = $new_now_order_list[$dk];
- }else{
- $weekarray[$dk]['now'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
+ } else {
+ $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
}
}
$chartdata = [];
$data = [];//临时
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
$chartdata['yAxis']['maxprice'] = 0;//最大值金额
- foreach ($weekarray as $k=>$v){
+ foreach ($weekarray as $k => $v) {
$data['day'][] = $v[0];
$data['pre']['count'][] = $v['pre']['count'];
- $data['pre']['price'][] = round($v['pre']['price'],2);
+ $data['pre']['price'][] = round($v['pre']['price'], 2);
$data['now']['count'][] = $v['now']['count'];
- $data['now']['price'][] = round($v['now']['price'],2);
- if($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']){
- $chartdata['yAxis']['maxnum'] = $v['pre']['count']>$v['now']['count']?$v['pre']['count']:$v['now']['count'];//日最大订单数
+ $data['now']['price'][] = round($v['now']['price'], 2);
+ if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
+ $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
}
- if($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']){
- $chartdata['yAxis']['maxprice'] = $v['pre']['price']>$v['now']['price']?$v['pre']['price']:$v['now']['price'];//日最大金额
+ if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
+ $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
}
}
- $chartdata['legend'] = ['上周金额','本周金额','上周订单数','本周订单数'];//分类
+ $chartdata['legend'] = ['上周金额', '本周金额', '上周订单数', '本周订单数'];//分类
$chartdata['xAxis'] = $data['day'];//X轴值
//,'itemStyle'=>$series
- $series= ['normal'=>['label'=>['show'=>true,'position'=>'top']]];
- $chartdata['series'][] = ['name'=>$chartdata['legend'][0],'type'=>'bar','itemStyle'=>$series,'data'=>$data['pre']['price']];//分类1值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][1],'type'=>'bar','itemStyle'=>$series,'data'=>$data['now']['price']];//分类1值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][2],'type'=>'line','itemStyle'=>$series,'data'=>$data['pre']['count']];//分类2值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][3],'type'=>'line','itemStyle'=>$series,'data'=>$data['now']['count']];//分类2值
+ $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
+ $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
//统计总数上期
- $pre_total = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
+ $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
->field("count(*) as count,sum(pay_price) as price")
->find();
- if($pre_total){
+ if ($pre_total) {
$chartdata['pre_cycle']['count'] = [
- 'data' => $pre_total['count']? : 0
+ 'data' => $pre_total['count'] ?: 0
];
$chartdata['pre_cycle']['price'] = [
- 'data' => $pre_total['price']? : 0
+ 'data' => $pre_total['price'] ?: 0
];
}
//统计总数
- $total = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
+ $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
->field("count(*) as count,sum(pay_price) as price")
->find();
- if($total){
+ if ($total) {
$cha_count = intval($pre_total['count']) - intval($total['count']);
- $pre_total['count'] = $pre_total['count']==0 ? 1 : $pre_total['count'];
+ $pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
$chartdata['cycle']['count'] = [
- 'data' => $total['count']? : 0,
- 'percent' => round((abs($cha_count)/intval($pre_total['count'])*100),2),
+ 'data' => $total['count'] ?: 0,
+ 'percent' => round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
];
- $cha_price = round($pre_total['price'],2) - round($total['price'],2);
- $pre_total['price'] = $pre_total['price']==0 ? 1 : $pre_total['price'];
+ $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
+ $pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
$chartdata['cycle']['price'] = [
- 'data' => $total['price']? : 0,
- 'percent' => round(abs($cha_price)/$pre_total['price']*100,2),
+ 'data' => $total['price'] ?: 0,
+ 'percent' => round(abs($cha_price) / $pre_total['price'] * 100, 2),
'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
];
}
- return app('json')->success('ok',$chartdata);
+ return app('json')->success('ok', $chartdata);
break;
case 'month':
- $weekarray=array('01'=>['1'],'02'=>['2'],'03'=>['3'],'04'=>['4'],'05'=>['5'],'06'=>['6'],'07'=>['7'],'08'=>['8'],'09'=>['9'],'10'=>['10'],'11'=>['11'],'12'=>['12'],'13'=>['13'],'14'=>['14'],'15'=>['15'],'16'=>['16'],'17'=>['17'],'18'=>['18'],'19'=>['19'],'20'=>['20'],'21'=>['21'],'22'=>['22'],'23'=>['23'],'24'=>['24'],'25'=>['25'],'26'=>['26'],'27'=>['27'],'28'=>['28'],'29'=>['29'],'30'=>['30'],'31'=>['31']);
+ $weekarray = array('01' => ['1'], '02' => ['2'], '03' => ['3'], '04' => ['4'], '05' => ['5'], '06' => ['6'], '07' => ['7'], '08' => ['8'], '09' => ['9'], '10' => ['10'], '11' => ['11'], '12' => ['12'], '13' => ['13'], '14' => ['14'], '15' => ['15'], '16' => ['16'], '17' => ['17'], '18' => ['18'], '19' => ['19'], '20' => ['20'], '21' => ['21'], '22' => ['22'], '23' => ['23'], '24' => ['24'], '25' => ['25'], '26' => ['26'], '27' => ['27'], '28' => ['28'], '29' => ['29'], '30' => ['30'], '31' => ['31']);
- $datebefor = date('Y-m-01',strtotime('-1 month'));
- $dateafter = date('Y-m-d',strtotime(date('Y-m-01')));
- $order_list = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
+ $datebefor = date('Y-m-01', strtotime('-1 month'));
+ $dateafter = date('Y-m-d', strtotime(date('Y-m-01')));
+ $order_list = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
->field("FROM_UNIXTIME(add_time,'%d') as day,count(*) as count,sum(pay_price) as price")
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
->order('add_time asc')
->select()->toArray();
//数据查询重新处理
$new_order_list = [];
- foreach ($order_list as $k=>$v){
+ foreach ($order_list as $k => $v) {
$new_order_list[$v['day']] = $v;
}
$now_datebefor = date('Y-m-01');
- $now_dateafter = date('Y-m-d',strtotime("+1 day"));
- $now_order_list = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
+ $now_dateafter = date('Y-m-d', strtotime("+1 day"));
+ $now_order_list = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
->field("FROM_UNIXTIME(add_time,'%d') as day,count(*) as count,sum(pay_price) as price")
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
->order('add_time asc')
->select()->toArray();
//数据查询重新处理 key 变为当前值
$new_now_order_list = [];
- foreach ($now_order_list as $k=>$v){
+ foreach ($now_order_list as $k => $v) {
$new_now_order_list[$v['day']] = $v;
}
- foreach ($weekarray as $dk=>$dd){
- if(!empty($new_order_list[$dk])){
+ foreach ($weekarray as $dk => $dd) {
+ if (!empty($new_order_list[$dk])) {
$weekarray[$dk]['pre'] = $new_order_list[$dk];
- }else{
- $weekarray[$dk]['pre'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
+ } else {
+ $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
}
- if(!empty($new_now_order_list[$dk])){
+ if (!empty($new_now_order_list[$dk])) {
$weekarray[$dk]['now'] = $new_now_order_list[$dk];
- }else{
- $weekarray[$dk]['now'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
+ } else {
+ $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
}
}
$chartdata = [];
$data = [];//临时
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
$chartdata['yAxis']['maxprice'] = 0;//最大值金额
- foreach ($weekarray as $k=>$v){
+ foreach ($weekarray as $k => $v) {
$data['day'][] = $v[0];
$data['pre']['count'][] = $v['pre']['count'];
- $data['pre']['price'][] = round($v['pre']['price'],2);
+ $data['pre']['price'][] = round($v['pre']['price'], 2);
$data['now']['count'][] = $v['now']['count'];
- $data['now']['price'][] = round($v['now']['price'],2);
- if($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']){
- $chartdata['yAxis']['maxnum'] = $v['pre']['count']>$v['now']['count']?$v['pre']['count']:$v['now']['count'];//日最大订单数
+ $data['now']['price'][] = round($v['now']['price'], 2);
+ if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
+ $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
}
- if($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']){
- $chartdata['yAxis']['maxprice'] = $v['pre']['price']>$v['now']['price']?$v['pre']['price']:$v['now']['price'];//日最大金额
+ if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
+ $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
}
}
- $chartdata['legend'] = ['上月金额','本月金额','上月订单数','本月订单数'];//分类
+ $chartdata['legend'] = ['上月金额', '本月金额', '上月订单数', '本月订单数'];//分类
$chartdata['xAxis'] = $data['day'];//X轴值
//,'itemStyle'=>$series
- $series= ['normal'=>['label'=>['show'=>true,'position'=>'top']]];
- $chartdata['series'][] = ['name'=>$chartdata['legend'][0],'type'=>'bar','itemStyle'=>$series,'data'=>$data['pre']['price']];//分类1值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][1],'type'=>'bar','itemStyle'=>$series,'data'=>$data['now']['price']];//分类1值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][2],'type'=>'line','itemStyle'=>$series,'data'=>$data['pre']['count']];//分类2值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][3],'type'=>'line','itemStyle'=>$series,'data'=>$data['now']['count']];//分类2值
+ $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
+ $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
//统计总数上期
- $pre_total = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
+ $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
->field("count(*) as count,sum(pay_price) as price")
->find();
- if($pre_total){
+ if ($pre_total) {
$chartdata['pre_cycle']['count'] = [
- 'data' => $pre_total['count']? : 0
+ 'data' => $pre_total['count'] ?: 0
];
$chartdata['pre_cycle']['price'] = [
- 'data' => $pre_total['price']? : 0
+ 'data' => $pre_total['price'] ?: 0
];
}
//统计总数
- $total = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
+ $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
->field("count(*) as count,sum(pay_price) as price")
->find();
- if($total){
+ if ($total) {
$cha_count = intval($pre_total['count']) - intval($total['count']);
- $pre_total['count'] = $pre_total['count']==0 ? 1 : $pre_total['count'];
+ $pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
$chartdata['cycle']['count'] = [
- 'data' => $total['count']? : 0,
- 'percent' => round((abs($cha_count)/intval($pre_total['count'])*100),2),
+ 'data' => $total['count'] ?: 0,
+ 'percent' => round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
];
- $cha_price = round($pre_total['price'],2) - round($total['price'],2);
- $pre_total['price'] = $pre_total['price']==0 ? 1 : $pre_total['price'];
+ $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
+ $pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
$chartdata['cycle']['price'] = [
- 'data' => $total['price']? : 0,
- 'percent' => round(abs($cha_price)/$pre_total['price']*100,2),
+ 'data' => $total['price'] ?: 0,
+ 'percent' => round(abs($cha_price) / $pre_total['price'] * 100, 2),
'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
];
}
- return app('json')->success('ok',$chartdata);
+ return app('json')->success('ok', $chartdata);
break;
case 'year':
- $weekarray=array('01'=>['一月'],'02'=>['二月'],'03'=>['三月'],'04'=>['四月'],'05'=>['五月'],'06'=>['六月'],'07'=>['七月'],'08'=>['八月'],'09'=>['九月'],'10'=>['十月'],'11'=>['十一月'],'12'=>['十二月']);
- $datebefor = date('Y-01-01',strtotime('-1 year'));
- $dateafter = date('Y-12-31',strtotime('-1 year'));
- $order_list = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
+ $weekarray = array('01' => ['一月'], '02' => ['二月'], '03' => ['三月'], '04' => ['四月'], '05' => ['五月'], '06' => ['六月'], '07' => ['七月'], '08' => ['八月'], '09' => ['九月'], '10' => ['十月'], '11' => ['十一月'], '12' => ['十二月']);
+ $datebefor = date('Y-01-01', strtotime('-1 year'));
+ $dateafter = date('Y-12-31', strtotime('-1 year'));
+ $order_list = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
->field("FROM_UNIXTIME(add_time,'%m') as day,count(*) as count,sum(pay_price) as price")
->group("FROM_UNIXTIME(add_time, '%Y%m')")
->order('add_time asc')
->select()->toArray();
//数据查询重新处理
$new_order_list = [];
- foreach ($order_list as $k=>$v){
+ foreach ($order_list as $k => $v) {
$new_order_list[$v['day']] = $v;
}
$now_datebefor = date('Y-01-01');
$now_dateafter = date('Y-m-d');
- $now_order_list = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
+ $now_order_list = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
->field("FROM_UNIXTIME(add_time,'%m') as day,count(*) as count,sum(pay_price) as price")
->group("FROM_UNIXTIME(add_time, '%Y%m')")
->order('add_time asc')
->select()->toArray();
//数据查询重新处理 key 变为当前值
$new_now_order_list = [];
- foreach ($now_order_list as $k=>$v){
+ foreach ($now_order_list as $k => $v) {
$new_now_order_list[$v['day']] = $v;
}
- foreach ($weekarray as $dk=>$dd){
- if(!empty($new_order_list[$dk])){
+ foreach ($weekarray as $dk => $dd) {
+ if (!empty($new_order_list[$dk])) {
$weekarray[$dk]['pre'] = $new_order_list[$dk];
- }else{
- $weekarray[$dk]['pre'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
+ } else {
+ $weekarray[$dk]['pre'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
}
- if(!empty($new_now_order_list[$dk])){
+ if (!empty($new_now_order_list[$dk])) {
$weekarray[$dk]['now'] = $new_now_order_list[$dk];
- }else{
- $weekarray[$dk]['now'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
+ } else {
+ $weekarray[$dk]['now'] = ['count' => 0, 'day' => $weekarray[$dk][0], 'price' => '0'];
}
}
$chartdata = [];
$data = [];//临时
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
$chartdata['yAxis']['maxprice'] = 0;//最大值金额
- foreach ($weekarray as $k=>$v){
+ foreach ($weekarray as $k => $v) {
$data['day'][] = $v[0];
$data['pre']['count'][] = $v['pre']['count'];
- $data['pre']['price'][] = round($v['pre']['price'],2);
+ $data['pre']['price'][] = round($v['pre']['price'], 2);
$data['now']['count'][] = $v['now']['count'];
- $data['now']['price'][] = round($v['now']['price'],2);
- if($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']){
- $chartdata['yAxis']['maxnum'] = $v['pre']['count']>$v['now']['count']?$v['pre']['count']:$v['now']['count'];//日最大订单数
+ $data['now']['price'][] = round($v['now']['price'], 2);
+ if ($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']) {
+ $chartdata['yAxis']['maxnum'] = $v['pre']['count'] > $v['now']['count'] ? $v['pre']['count'] : $v['now']['count'];//日最大订单数
}
- if($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']){
- $chartdata['yAxis']['maxprice'] = $v['pre']['price']>$v['now']['price']?$v['pre']['price']:$v['now']['price'];//日最大金额
+ if ($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']) {
+ $chartdata['yAxis']['maxprice'] = $v['pre']['price'] > $v['now']['price'] ? $v['pre']['price'] : $v['now']['price'];//日最大金额
}
}
- $chartdata['legend'] = ['去年金额','今年金额','去年订单数','今年订单数'];//分类
+ $chartdata['legend'] = ['去年金额', '今年金额', '去年订单数', '今年订单数'];//分类
$chartdata['xAxis'] = $data['day'];//X轴值
//,'itemStyle'=>$series
- $series= ['normal'=>['label'=>['show'=>true,'position'=>'top']]];
- $chartdata['series'][] = ['name'=>$chartdata['legend'][0],'type'=>'bar','itemStyle'=>$series,'data'=>$data['pre']['price']];//分类1值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][1],'type'=>'bar','itemStyle'=>$series,'data'=>$data['now']['price']];//分类1值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][2],'type'=>'line','itemStyle'=>$series,'data'=>$data['pre']['count']];//分类2值
- $chartdata['series'][] = ['name'=>$chartdata['legend'][3],'type'=>'line','itemStyle'=>$series,'data'=>$data['now']['count']];//分类2值
+ $series = ['normal' => ['label' => ['show' => true, 'position' => 'top']]];
+ $chartdata['series'][] = ['name' => $chartdata['legend'][0], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['pre']['price']];//分类1值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][1], 'type' => 'bar', 'itemStyle' => $series, 'data' => $data['now']['price']];//分类1值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][2], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['pre']['count']];//分类2值
+ $chartdata['series'][] = ['name' => $chartdata['legend'][3], 'type' => 'line', 'itemStyle' => $series, 'data' => $data['now']['count']];//分类2值
//统计总数上期
- $pre_total = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
+ $pre_total = StoreOrderModel::where('add_time', 'between time', [$datebefor, $dateafter])
->field("count(*) as count,sum(pay_price) as price")
->find();
- if($pre_total){
+ if ($pre_total) {
$chartdata['pre_cycle']['count'] = [
- 'data' => $pre_total['count']? : 0
+ 'data' => $pre_total['count'] ?: 0
];
$chartdata['pre_cycle']['price'] = [
- 'data' => $pre_total['price']? : 0
+ 'data' => $pre_total['price'] ?: 0
];
}
//统计总数
- $total = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
+ $total = StoreOrderModel::where('add_time', 'between time', [$now_datebefor, $now_dateafter])
->field("count(*) as count,sum(pay_price) as price")
->find();
- if($total){
+ if ($total) {
$cha_count = intval($pre_total['count']) - intval($total['count']);
- $pre_total['count'] = $pre_total['count']==0 ? 1 : $pre_total['count'];
+ $pre_total['count'] = $pre_total['count'] == 0 ? 1 : $pre_total['count'];
$chartdata['cycle']['count'] = [
- 'data' => $total['count']? : 0,
- 'percent' => round((abs($cha_count)/intval($pre_total['count'])*100),2),
+ 'data' => $total['count'] ?: 0,
+ 'percent' => round((abs($cha_count) / intval($pre_total['count']) * 100), 2),
'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
];
- $cha_price = round($pre_total['price'],2) - round($total['price'],2);
- $pre_total['price'] = $pre_total['price']==0 ? 1 : $pre_total['price'];
+ $cha_price = round($pre_total['price'], 2) - round($total['price'], 2);
+ $pre_total['price'] = $pre_total['price'] == 0 ? 1 : $pre_total['price'];
$chartdata['cycle']['price'] = [
- 'data' => $total['price']? : 0,
- 'percent' => round(abs($cha_price)/$pre_total['price']*100,2),
+ 'data' => $total['price'] ?: 0,
+ 'percent' => round(abs($cha_price) / $pre_total['price'] * 100, 2),
'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
];
}
- return app('json')->success('ok',$chartdata);
+ return app('json')->success('ok', $chartdata);
break;
default:
break;
@@ -527,16 +530,18 @@ class Index extends AuthController
}
+
/**
* 用户图表
*/
- public function userchart(){
+ public function userchart()
+ {
header('Content-type:text/json');
- $starday = date('Y-m-d',strtotime('-30 day'));
+ $starday = date('Y-m-d', strtotime('-30 day'));
$yesterday = date('Y-m-d');
- $user_list = UserModel::where('add_time','between time',[$starday,$yesterday])
+ $user_list = UserModel::where('add_time', 'between time', [$starday, $yesterday])
->field("FROM_UNIXTIME(add_time,'%m-%e') as day,count(*) as count")
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
->order('add_time asc')
@@ -547,17 +552,17 @@ class Index extends AuthController
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
$chartdata['xAxis'] = [date('m-d')];//X轴值
$chartdata['series'] = [0];//分类1值
- if(!empty($user_list)) {
- foreach ($user_list as $k=>$v){
+ if (!empty($user_list)) {
+ foreach ($user_list as $k => $v) {
$data['day'][] = $v['day'];
$data['count'][] = $v['count'];
- if($chartdata['yAxis']['maxnum'] < $v['count'])
+ if ($chartdata['yAxis']['maxnum'] < $v['count'])
$chartdata['yAxis']['maxnum'] = $v['count'];
}
$chartdata['xAxis'] = $data['day'];//X轴值
$chartdata['series'] = $data['count'];//分类1值
}
- return app('json')->success('ok',$chartdata);
+ return app('json')->success('ok', $chartdata);
}
/**
@@ -565,20 +570,20 @@ class Index extends AuthController
* @param int $newTime
* @return false|string
*/
- public function Jnotice($newTime=30)
+ public function Jnotice($newTime = 30)
{
header('Content-type:text/json');
$data = [];
$data['ordernum'] = StoreOrderModel::statusByWhere(1)->count();//待发货
$replenishment_num = SystemConfig::getConfigValue('store_stock') > 0 ? SystemConfig::getConfigValue('store_stock') : 2;//库存预警界限
- $data['inventory'] = ProductModel::where('stock','<=',$replenishment_num)->where('is_show',1)->where('is_del',0)->count();//库存
- $data['commentnum'] = StoreProductReplyModel::where('is_reply',0)->count();//评论
- $data['reflectnum'] = UserExtractModel::where('status',0)->count();;//提现
- $data['msgcount'] = intval($data['ordernum'])+intval($data['inventory'])+intval($data['commentnum'])+intval($data['reflectnum']);
+ $data['inventory'] = ProductModel::where('stock', '<=', $replenishment_num)->where('is_show', 1)->where('is_del', 0)->count();//库存
+ $data['commentnum'] = StoreProductReplyModel::where('is_reply', 0)->count();//评论
+ $data['reflectnum'] = UserExtractModel::where('status', 0)->count();;//提现
+ $data['msgcount'] = intval($data['ordernum']) + intval($data['inventory']) + intval($data['commentnum']) + intval($data['reflectnum']);
//新订单提醒
- $data['newOrderId']=StoreOrderModel::statusByWhere(1)->where('is_remind',0)->column('order_id','id');
- if(count($data['newOrderId'])) StoreOrderModel::where('order_id','in',$data['newOrderId'])->update(['is_remind'=>1]);
- return app('json')->success('ok',$data);
+ $data['newOrderId'] = StoreOrderModel::statusByWhere(1)->where('is_remind', 0)->column('order_id', 'id');
+ if (count($data['newOrderId'])) StoreOrderModel::where('order_id', 'in', $data['newOrderId'])->update(['is_remind' => 1]);
+ return app('json')->success('ok', $data);
}
}
diff --git a/crmeb/app/admin/controller/finance/UserRecharge.php b/crmeb/app/admin/controller/finance/UserRecharge.php
index 64b7be1f..3c4aaba2 100644
--- a/crmeb/app/admin/controller/finance/UserRecharge.php
+++ b/crmeb/app/admin/controller/finance/UserRecharge.php
@@ -127,13 +127,7 @@ SCRIPT;
],Url::buildUrl('/user/bill/2')->suffix(false)->build());
break;
case 'routine':
- RoutineTemplate::sendOut('ORDER_REFUND_SUCCESS',$UserRecharge['uid'],[
- 'keyword1'=>$UserRecharge['order_id'],
- 'keyword2'=>date('Y-m-d H:i:s',time()),
- 'keyword3'=>$UserRecharge['price'],
- 'keyword4'=>'余额充值退款',
- 'keyword5'=>'亲,您充值的金额已退款,本次退款'. $data['refund_price'].'金额',
- ]);
+ RoutineTemplate::sendRechargeSuccess($UserRecharge,$data['refund_price']);
break;
}
UserBill::expend('系统退款',$UserRecharge['uid'],'now_money','user_recharge_refund',$refund_price,$id,$UserRecharge['price'],'退款给用户'.$refund_price.'元');
diff --git a/crmeb/app/admin/controller/routine/RoutineTemplate.php b/crmeb/app/admin/controller/routine/RoutineTemplate.php
index 2b557e56..e7391499 100644
--- a/crmeb/app/admin/controller/routine/RoutineTemplate.php
+++ b/crmeb/app/admin/controller/routine/RoutineTemplate.php
@@ -3,6 +3,7 @@
namespace app\admin\controller\routine;
use app\admin\controller\AuthController;
+use crmeb\services\CacheService;
use crmeb\services\FormBuilder as Form;
use crmeb\services\UtilService as Util;
use crmeb\services\JsonService as Json;
@@ -19,10 +20,10 @@ class RoutineTemplate extends AuthController
public function index()
{
$where = Util::getMore([
- ['name',''],
- ['status','']
- ],$this->request);
- $this->assign('where',$where);
+ ['name', ''],
+ ['status', '']
+ ], $this->request);
+ $this->assign('where', $where);
$this->assign(RoutineTemplateModel::SystemPage($where));
return $this->fetch();
}
@@ -34,15 +35,16 @@ class RoutineTemplate extends AuthController
public function create()
{
$f = array();
- $f[] = Form::input('tempkey','模板编号');
- $f[] = Form::input('tempid','模板ID');
- $f[] = Form::input('name','模板名');
- $f[] = Form::input('content','回复内容')->type('textarea');
- $f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
- $form = Form::make_post_form('添加模板消息',$f,Url::buildUrl('save'));
+ $f[] = Form::input('tempkey', '模板编号');
+ $f[] = Form::input('tempid', '模板ID');
+ $f[] = Form::input('name', '模板名');
+ $f[] = Form::input('content', '回复内容')->type('textarea');
+ $f[] = Form::radio('status', '状态', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
+ $form = Form::make_post_form('添加模板消息', $f, Url::buildUrl('save'));
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
+
public function save()
{
$data = Util::postMore([
@@ -50,16 +52,17 @@ class RoutineTemplate extends AuthController
'tempid',
'name',
'content',
- ['status',0]
+ ['status', 0]
]);
- if($data['tempkey'] == '') return Json::fail('请输入模板编号');
- if($data['tempkey'] != '' && RoutineTemplateModel::be($data['tempkey'],'tempkey'))
+ if ($data['tempkey'] == '') return Json::fail('请输入模板编号');
+ if ($data['tempkey'] != '' && RoutineTemplateModel::be($data['tempkey'], 'tempkey'))
return Json::fail('请输入模板编号已存在,请重新输入');
- if($data['tempid'] == '') return Json::fail('请输入模板ID');
- if($data['name'] == '') return Json::fail('请输入模板名');
- if($data['content'] == '') return Json::fail('请输入回复内容');
+ if ($data['tempid'] == '') return Json::fail('请输入模板ID');
+ if ($data['name'] == '') return Json::fail('请输入模板名');
+ if ($data['content'] == '') return Json::fail('请输入回复内容');
$data['add_time'] = time();
RoutineTemplateModel::create($data);
+ CacheService::clear();
return Json::successful('添加模板消息成功!');
}
@@ -70,15 +73,15 @@ class RoutineTemplate extends AuthController
*/
public function edit($id)
{
- if(!$id) return $this->failed('数据不存在');
+ if (!$id) return $this->failed('数据不存在');
$product = RoutineTemplateModel::get($id);
- if(!$product) return Json::fail('数据不存在!');
+ if (!$product) return Json::fail('数据不存在!');
$f = array();
- $f[] = Form::input('tempkey','模板编号',$product->getData('tempkey'))->disabled(1);
- $f[] = Form::input('name','模板名',$product->getData('name'))->disabled(1);
- $f[] = Form::input('tempid','模板ID',$product->getData('tempid'));
- $f[] = Form::radio('status','状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
- $form = Form::make_post_form('编辑模板消息',$f,Url::buildUrl('update',compact('id')));
+ $f[] = Form::input('tempkey', '模板编号', $product->getData('tempkey'))->disabled(1);
+ $f[] = Form::input('name', '模板名', $product->getData('name'))->disabled(1);
+ $f[] = Form::input('tempid', '模板ID', $product->getData('tempid'));
+ $f[] = Form::radio('status', '状态', $product->getData('status'))->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
+ $form = Form::make_post_form('编辑模板消息', $f, Url::buildUrl('update', compact('id')));
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
@@ -87,13 +90,14 @@ class RoutineTemplate extends AuthController
{
$data = Util::postMore([
'tempid',
- ['status',0]
+ ['status', 0]
]);
- if($data['tempid'] == '') return Json::fail('请输入模板ID');
- if(!$id) return $this->failed('数据不存在');
+ if ($data['tempid'] == '') return Json::fail('请输入模板ID');
+ if (!$id) return $this->failed('数据不存在');
$product = RoutineTemplateModel::get($id);
- if(!$product) return Json::fail('数据不存在!');
- RoutineTemplateModel::edit($data,$id);
+ if (!$product) return Json::fail('数据不存在!');
+ RoutineTemplateModel::edit($data, $id);
+ CacheService::clear();
return Json::successful('修改成功!');
}
@@ -104,11 +108,13 @@ class RoutineTemplate extends AuthController
*/
public function delete($id)
{
- if(!$id) return Json::fail('数据不存在!');
- if(!RoutineTemplateModel::del($id))
+ if (!$id) return Json::fail('数据不存在!');
+ if (!RoutineTemplateModel::del($id))
return Json::fail(RoutineTemplateModel::getErrorInfo('删除失败,请稍候再试!'));
- else
+ else {
+ CacheService::clear();
return Json::successful('删除成功!');
+ }
}
diff --git a/crmeb/app/admin/controller/system/Clear.php b/crmeb/app/admin/controller/system/Clear.php
index 560217ca..3e54ab9a 100644
--- a/crmeb/app/admin/controller/system/Clear.php
+++ b/crmeb/app/admin/controller/system/Clear.php
@@ -3,6 +3,7 @@
namespace app\admin\controller\system;
use app\admin\controller\AuthController;
+use crmeb\services\CacheService;
use crmeb\services\JsonService as Json;
/**
@@ -48,7 +49,7 @@ class Clear extends AuthController
}
}
}
-
+ CacheService::clear();
return app('json')->successful('数据缓存刷新成功!');
}
diff --git a/crmeb/app/admin/controller/system/SystemCleardata.php b/crmeb/app/admin/controller/system/SystemCleardata.php
index 2833531d..85f35bf7 100644
--- a/crmeb/app/admin/controller/system/SystemCleardata.php
+++ b/crmeb/app/admin/controller/system/SystemCleardata.php
@@ -12,6 +12,8 @@ namespace app\admin\controller\system;
use app\admin\controller\AuthController;
use app\admin\model\store\StoreProduct;
use crmeb\services\JsonService as Json;
+use crmeb\services\SystemConfigService;
+use think\facade\Config;
use think\facade\Db;
/**
@@ -19,117 +21,137 @@ use think\facade\Db;
* Class SystemclearData
* @package app\admin\controller\system
*/
-class SystemclearData extends AuthController
+class SystemclearData extends AuthController
{
- public function index(){
- return $this->fetch();
+ public function index()
+ {
+ return $this->fetch();
}
+
//清除用户数据
- public function userRelevantData(){
- self::clearData('user_recharge',1);
- self::clearData('user_address',1);
- self::clearData('user_bill',1);
- self::clearData('user_enter',1);
- self::clearData('user_extract',1);
- self::clearData('user_notice',1);
- self::clearData('user_notice_see',1);
- self::clearData('wechat_qrcode',1);
- self::clearData('wechat_message',1);
- self::clearData('store_visit',1);
- self::clearData('store_coupon_user',1);
- self::clearData('store_coupon_issue_user',1);
- self::clearData('store_bargain_user',1);
- self::clearData('store_bargain_user_help',1);
- self::clearData('store_product_reply',1);
- self::clearData('store_product_cate',1);
- self::clearData('routine_qrcode',1);
- self::clearData('routine_form_id',1);
- self::clearData('user_sign',1);
- self::clearData('user_task_finish',1);
- self::clearData('user_level',1);
- self::clearData('user_token',1);
- self::clearData('user_group',1);
+ public function userRelevantData()
+ {
+ self::clearData('user_recharge', 1);
+ self::clearData('user_address', 1);
+ self::clearData('user_bill', 1);
+ self::clearData('user_enter', 1);
+ self::clearData('user_extract', 1);
+ self::clearData('user_notice', 1);
+ self::clearData('user_notice_see', 1);
+ self::clearData('wechat_qrcode', 1);
+ self::clearData('wechat_message', 1);
+ self::clearData('store_visit', 1);
+ self::clearData('store_coupon_user', 1);
+ self::clearData('store_coupon_issue_user', 1);
+ self::clearData('store_bargain_user', 1);
+ self::clearData('store_bargain_user_help', 1);
+ self::clearData('store_product_reply', 1);
+ self::clearData('store_product_cate', 1);
+ self::clearData('routine_qrcode', 1);
+ self::clearData('routine_form_id', 1);
+ self::clearData('user_sign', 1);
+ self::clearData('user_task_finish', 1);
+ self::clearData('user_level', 1);
+ self::clearData('user_token', 1);
+ self::clearData('user_group', 1);
$this->delDirAndFile('./public/uploads/store/comment');
- self::clearData('store_product_relation',1);
+ self::clearData('store_product_relation', 1);
return Json::successful('清除数据成功!');
}
+
//清除商城数据
- public function storeData(){
- self::clearData('store_coupon',1);
- self::clearData('store_coupon_issue',1);
- self::clearData('store_bargain',1);
- self::clearData('store_combination',1);
- self::clearData('store_combination_attr',1);
- self::clearData('store_combination_attr_result',1);
- self::clearData('store_combination_attr_value',1);
- self::clearData('store_product_attr',1);
- self::clearData('store_product_cate',1);
- self::clearData('store_product_attr_result',1);
- self::clearData('store_product_attr_value',1);
- self::clearData('store_seckill',1);
- self::clearData('store_seckill_attr',1);
- self::clearData('store_seckill_attr_result',1);
- self::clearData('store_seckill_attr_value',1);
- self::clearData('store_product',1);
- self::clearData('store_visit',1);
+ public function storeData()
+ {
+ self::clearData('store_coupon', 1);
+ self::clearData('store_coupon_issue', 1);
+ self::clearData('store_bargain', 1);
+ self::clearData('store_combination', 1);
+ self::clearData('store_combination_attr', 1);
+ self::clearData('store_combination_attr_result', 1);
+ self::clearData('store_combination_attr_value', 1);
+ self::clearData('store_product_attr', 1);
+ self::clearData('store_product_cate', 1);
+ self::clearData('store_product_attr_result', 1);
+ self::clearData('store_product_attr_value', 1);
+ self::clearData('store_seckill', 1);
+ self::clearData('store_seckill_attr', 1);
+ self::clearData('store_seckill_attr_result', 1);
+ self::clearData('store_seckill_attr_value', 1);
+ self::clearData('store_product', 1);
+ self::clearData('store_visit', 1);
return Json::successful('清除数据成功!');
}
+
//清除产品分类
- public function categoryData(){
- self::clearData('store_category',1);
+ public function categoryData()
+ {
+ self::clearData('store_category', 1);
return Json::successful('清除数据成功!');
}
+
//清除订单数据
- public function orderData(){
- self::clearData('store_order',1);
- self::clearData('store_order_cart_info',1);
- self::clearData('store_order_status',1);
- self::clearData('store_pink',1);
- self::clearData('store_cart',1);
- self::clearData('store_order_status',1);
+ public function orderData()
+ {
+ self::clearData('store_order', 1);
+ self::clearData('store_order_cart_info', 1);
+ self::clearData('store_order_status', 1);
+ self::clearData('store_pink', 1);
+ self::clearData('store_cart', 1);
+ self::clearData('store_order_status', 1);
return Json::successful('清除数据成功!');
}
+
//清除客服数据
- public function kefuData(){
- self::clearData('store_service',1);
+ public function kefuData()
+ {
+ self::clearData('store_service', 1);
$this->delDirAndFile('./public/uploads/store/service');
- self::clearData('store_service_log',1);
+ self::clearData('store_service_log', 1);
return Json::successful('清除数据成功!');
}
//清除微信管理数据
- public function wechatData(){
- self::clearData('wechat_media',1);
- self::clearData('wechat_reply',1);
- self::clearData('cache',1);
+ public function wechatData()
+ {
+ self::clearData('wechat_media', 1);
+ self::clearData('wechat_reply', 1);
+ self::clearData('cache', 1);
$this->delDirAndFile('./public/uploads/wechat');
return Json::successful('清除数据成功!');
}
+
//清除所有附件
- public function uploadData(){
- self::clearData('system_attachment',1);
- self::clearData('system_attachment_category',1);
+ public function uploadData()
+ {
+ self::clearData('system_attachment', 1);
+ self::clearData('system_attachment_category', 1);
$this->delDirAndFile('./public/uploads/');
return Json::successful('清除上传文件成功!');
}
+
//清除微信用户
- public function wechatuserData(){
- self::clearData('wechat_user',1);
- self::clearData('user',1);
+ public function wechatuserData()
+ {
+ self::clearData('wechat_user', 1);
+ self::clearData('user', 1);
return Json::successful('清除数据成功!');
}
+
//清除内容分类
- public function articledata(){
- self::clearData('article_category',1);
- self::clearData('article',1);
- self::clearData('article_content',1);
+ public function articledata()
+ {
+ self::clearData('article_category', 1);
+ self::clearData('article', 1);
+ self::clearData('article_content', 1);
return Json::successful('清除数据成功!');
}
+
//清除系统记录
- public function systemdata(){
- self::clearData('system_notice_admin',1);
- self::clearData('system_log',1);
+ public function systemdata()
+ {
+ self::clearData('system_notice_admin', 1);
+ self::clearData('system_log', 1);
return Json::successful('清除数据成功!');
}
@@ -140,39 +162,91 @@ class SystemclearData extends AuthController
*/
public function undata($type = 1)
{
- switch ((int)$type){
+ switch ((int)$type) {
case 1:
- \app\admin\model\system\SystemAttachment::where('module_type',2)->delete();
+ $fileImage = \app\admin\model\system\SystemAttachment::where('module_type', 2)->field(['att_dir', 'satt_dir'])->select();
+ foreach ($fileImage as $image) {
+ if ($image['att_dir'] && ($imagePath = strstr($image['att_dir'], 'uploads')) !== false) {
+ if (is_file($imagePath))
+ unlink($imagePath);
+ unset($imagePath);
+ }
+
+ if ($image['satt_dir'] && ($imagePath = strstr($image['satt_dir'], 'uploads')) !== false) {
+ if (is_file($imagePath))
+ unlink($imagePath);
+ unset($imagePath);
+ }
+ }
+ \app\admin\model\system\SystemAttachment::where('module_type', 2)->delete();
+ @unlink('uploads/follow/follow.jpg');//删除海报二维码
break;
case 2:
- StoreProduct::where('is_del',1)->delete();
+ StoreProduct::where('is_del', 1)->delete();
+ break;
+ case 3:
+ $value = $this->request->param('value');
+ if (!$value)
+ return Json::fail('请输入需要更换的域名');
+ if (!verify_domain($value))
+ return Json::fail('域名不合法');
+ $siteUrl = SystemConfigService::get('site_url', true);
+ $siteUrlJosn = str_replace('http://', 'http:\\/\\/', $siteUrl);
+ $valueJosn = str_replace('http://', 'http:\\/\\/', $value);
+ $prefix = Config::get('database.connections.' . Config::get('database.default') . '.prefix');
+ $sql = [
+ "UPDATE `{$prefix}system_attachment` SET `att_dir` = replace(att_dir ,'{$siteUrl}','{$value}'),`satt_dir` = replace(satt_dir ,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}store_product` SET `image` = replace(image ,'{$siteUrl}','{$value}'),`slider_image` = replace(slider_image ,'{$siteUrl}','{$value}'),`description`= replace(description,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}store_product_attr_value` SET `image` = replace(image ,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}store_seckill` SET `image` = replace(image ,'{$siteUrl}','{$value}'),`images` = replace(images,'{$siteUrl}','{$value}'),`description` = replace(description,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}store_combination` SET `image` = replace(image ,'{$siteUrl}','{$value}'),`images` = replace(images,'{$siteUrl}','{$value}'),`description` = replace(description,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}store_bargain` SET `image` = replace(image ,'{$siteUrl}','{$value}'),`images` = replace(images,'{$siteUrl}','{$value}'),`description` = replace(description,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}system_config` SET `value` = replace(value ,'{$siteUrlJosn}','{$valueJosn}')",
+ "UPDATE `{$prefix}article_category` SET `image` = replace(`image` ,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}article` SET `image_input` = replace(`image_input` ,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}article_content` SET `content` = replace(`content` ,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}store_category` SET `pic` = replace(`pic` ,'{$siteUrl}','{$value}')",
+ "UPDATE `{$prefix}system_group_data` SET `value` = replace(value ,'{$siteUrlJosn}','{$valueJosn}')"
+ ];
+ try {
+ foreach ($sql as $item) {
+ db::execute($item);
+ }
+ } catch (\Throwable $e) {
+ return Json::fail('替换失败,失败原因:' . $e->getMessage());
+ }
+ return Json::success('替换成功!');
break;
}
return Json::successful('清除数据成功!');
}
+
//清除制定表数据
- public function clearData($table_name,$status){
- $table_name = config('database.connections.' . config('database.default'))['prefix'].$table_name;
- if($status){
- @db::execute('TRUNCATE TABLE '.$table_name);
- }else{
- @db::execute('DELETE FROM'.$table_name);
+ public function clearData($table_name, $status)
+ {
+ $table_name = config('database.connections.' . config('database.default'))['prefix'] . $table_name;
+ if ($status) {
+ @db::execute('TRUNCATE TABLE ' . $table_name);
+ } else {
+ @db::execute('DELETE FROM' . $table_name);
}
}
+
//递归删除文件
- function delDirAndFile($dirName,$subdir=true){
- if ($handle = @opendir("$dirName")){
- while(false !== ($item = readdir($handle))){
- if($item != "." && $item != ".."){
- if(is_dir("$dirName/$item"))
- $this->delDirAndFile("$dirName/$item",false);
+ function delDirAndFile($dirName, $subdir = true)
+ {
+ if ($handle = @opendir("$dirName")) {
+ while (false !== ($item = readdir($handle))) {
+ if ($item != "." && $item != "..") {
+ if (is_dir("$dirName/$item"))
+ $this->delDirAndFile("$dirName/$item", false);
else
@unlink("$dirName/$item");
}
}
closedir($handle);
- if(!$subdir) @rmdir($dirName);
+ if (!$subdir) @rmdir($dirName);
}
}
}
\ No newline at end of file
diff --git a/crmeb/app/admin/controller/user/User.php b/crmeb/app/admin/controller/user/User.php
index b3bb0c73..52b9c20a 100644
--- a/crmeb/app/admin/controller/user/User.php
+++ b/crmeb/app/admin/controller/user/User.php
@@ -4,6 +4,7 @@
* @author: xaboy<365615158@qq.com>
* @day: 2017/11/11
*/
+
namespace app\admin\controller\user;
use app\admin\controller\AuthController;
@@ -33,13 +34,15 @@ use app\admin\model\store\StoreCouponUser;
class User extends AuthController
{
use CurdControllerTrait;
+
/**
* 显示资源列表
*
* @return \think\Response
*/
- public function index(){
- $this->assign('count_user',UserModel::getcount());
+ public function index()
+ {
+ $this->assign('count_user', UserModel::getcount());
return $this->fetch();
}
@@ -47,111 +50,111 @@ class User extends AuthController
* 赠送会员等级
* @paran int $uid
* */
- public function give_level($uid=0)
+ public function give_level($uid = 0)
{
- if(!$uid) return $this->failed('缺少参数');
- $level=\app\models\user\UserLevel::getUserLevel($uid);
+ if (!$uid) return $this->failed('缺少参数');
+ $level = \app\models\user\UserLevel::getUserLevel($uid);
//获取当前会员等级
- if($level===false)
- $grade=0;
+ if ($level === false)
+ $grade = 0;
else
- $grade=\app\models\user\UserLevel::getUserLevelInfo($level,'grade');
+ $grade = \app\models\user\UserLevel::getUserLevelInfo($level, 'grade');
//查询高于当前会员的所有会员等级
- $systemLevelList=SystemUserLevel::where('grade','>',$grade)->where(['is_show'=>1,'is_del'=>0])->field(['name','id'])->select();
- $field[]=Form::select('level_id','会员等级')->setOptions(function() use($systemLevelList) {
- $menus=[];
- foreach ($systemLevelList as $menu){
- $menus[] = ['value'=>$menu['id'],'label'=>$menu['name']];
+ $systemLevelList = SystemUserLevel::where('grade', '>', $grade)->where(['is_show' => 1, 'is_del' => 0])->field(['name', 'id'])->select();
+ $field[] = Form::select('level_id', '会员等级')->setOptions(function () use ($systemLevelList) {
+ $menus = [];
+ foreach ($systemLevelList as $menu) {
+ $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
}
return $menus;
})->filterable(1);
- $form = Form::make_post_form('赠送会员',$field,Url::buildUrl('save_give_level',['uid'=>$uid]),2);
+ $form = Form::make_post_form('赠送会员', $field, Url::buildUrl('save_give_level', ['uid' => $uid]), 2);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
public function edit_other($uid)
{
- if(!$uid) return $this->failed('数据不存在');
+ if (!$uid) return $this->failed('数据不存在');
$user = UserModel::get($uid);
- if(!$user) return Json::fail('数据不存在!');
+ if (!$user) return Json::fail('数据不存在!');
$f = array();
- $f[] = Form::radio('money_status','修改余额',1)->options([['value'=>1,'label'=>'增加'],['value'=>2,'label'=>'减少']]);
- $f[] = Form::number('money','余额')->min(0);
- $f[] = Form::radio('integration_status','修改积分',1)->options([['value'=>1,'label'=>'增加'],['value'=>2,'label'=>'减少']]);
- $f[] = Form::number('integration','积分')->min(0);
- $form = Form::make_post_form('修改其他',$f,Url::buildUrl('update_other',array('uid'=>$uid)));
+ $f[] = Form::radio('money_status', '修改余额', 1)->options([['value' => 1, 'label' => '增加'], ['value' => 2, 'label' => '减少']]);
+ $f[] = Form::number('money', '余额')->min(0);
+ $f[] = Form::radio('integration_status', '修改积分', 1)->options([['value' => 1, 'label' => '增加'], ['value' => 2, 'label' => '减少']]);
+ $f[] = Form::number('integration', '积分')->min(0);
+ $form = Form::make_post_form('修改其他', $f, Url::buildUrl('update_other', array('uid' => $uid)));
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
- public function update_other($uid=0)
+ public function update_other($uid = 0)
{
$data = Util::postMore([
- ['money_status',0],
- ['money',0],
- ['integration_status',0],
- ['integration',0],
- ],$this->request);
- if(!$uid) return $this->failed('数据不存在');
+ ['money_status', 0],
+ ['money', 0],
+ ['integration_status', 0],
+ ['integration', 0],
+ ], $this->request);
+ if (!$uid) return $this->failed('数据不存在');
$user = UserModel::get($uid);
- if(!$user) return Json::fail('数据不存在!');
+ if (!$user) return Json::fail('数据不存在!');
BaseModel::beginTrans();
$res1 = false;
$res2 = false;
$edit = array();
- if($data['money_status'] && $data['money']){//余额增加或者减少
- if($data['money_status'] == 1){//增加
- $edit['now_money'] = bcadd($user['now_money'],$data['money'],2);
- $res1 = UserBillAdmin::income('系统增加余额',$user['uid'],'now_money','system_add',$data['money'],$this->adminId,$edit['now_money'],'系统增加了'.floatval($data['money']).'余额');
- try{
- UserRepository::adminAddMoney($user,$data['money']);
- }catch (\Exception $e){
+ if ($data['money_status'] && $data['money']) {//余额增加或者减少
+ if ($data['money_status'] == 1) {//增加
+ $edit['now_money'] = bcadd($user['now_money'], $data['money'], 2);
+ $res1 = UserBillAdmin::income('系统增加余额', $user['uid'], 'now_money', 'system_add', $data['money'], $this->adminId, $edit['now_money'], '系统增加了' . floatval($data['money']) . '余额');
+ try {
+ UserRepository::adminAddMoney($user, $data['money']);
+ } catch (\Exception $e) {
BaseModel::rollbackTrans();
return Json::fail($e->getMessage());
}
- }else if($data['money_status'] == 2){//减少
- $edit['now_money'] = bcsub($user['now_money'],$data['money'],2);
- $res1 = UserBillAdmin::expend('系统减少余额',$user['uid'],'now_money','system_sub',$data['money'],$this->adminId,$edit['now_money'],'系统扣除了'.floatval($data['money']).'余额');
- try{
- UserRepository::adminSubMoney($user,$data['money']);
- }catch (\Exception $e){
+ } else if ($data['money_status'] == 2) {//减少
+ $edit['now_money'] = bcsub($user['now_money'], $data['money'], 2);
+ $res1 = UserBillAdmin::expend('系统减少余额', $user['uid'], 'now_money', 'system_sub', $data['money'], $this->adminId, $edit['now_money'], '系统扣除了' . floatval($data['money']) . '余额');
+ try {
+ UserRepository::adminSubMoney($user, $data['money']);
+ } catch (\Exception $e) {
BaseModel::rollbackTrans();
return Json::fail($e->getMessage());
}
}
- }else{
+ } else {
$res1 = true;
}
- if($data['integration_status'] && $data['integration']){//积分增加或者减少
- if($data['integration_status'] == 1){//增加
- $edit['integral'] = bcadd($user['integral'],$data['integration'],2);
- $res2 = UserBillAdmin::income('系统增加积分',$user['uid'],'integral','system_add',$data['integration'],$this->adminId,$edit['integral'],'系统增加了'.floatval($data['integration']).'积分');
- try{
- UserRepository::adminAddIntegral($user,$data['integration']);
- }catch (\Exception $e){
+ if ($data['integration_status'] && $data['integration']) {//积分增加或者减少
+ if ($data['integration_status'] == 1) {//增加
+ $edit['integral'] = bcadd($user['integral'], $data['integration'], 2);
+ $res2 = UserBillAdmin::income('系统增加积分', $user['uid'], 'integral', 'system_add', $data['integration'], $this->adminId, $edit['integral'], '系统增加了' . floatval($data['integration']) . '积分');
+ try {
+ UserRepository::adminAddIntegral($user, $data['integration']);
+ } catch (\Exception $e) {
BaseModel::rollbackTrans();
return Json::fail($e->getMessage());
}
- }else if($data['integration_status'] == 2){//减少
- $edit['integral'] = bcsub($user['integral'],$data['integration'],2);
- $res2 = UserBillAdmin::expend('系统减少积分',$user['uid'],'integral','system_sub',$data['integration'],$this->adminId,$edit['integral'],'系统扣除了'.floatval($data['integration']).'积分');
- try{
- UserRepository::adminSubIntegral($user,$data['integration']);
- }catch (\Exception $e){
+ } else if ($data['integration_status'] == 2) {//减少
+ $edit['integral'] = bcsub($user['integral'], $data['integration'], 2);
+ $res2 = UserBillAdmin::expend('系统减少积分', $user['uid'], 'integral', 'system_sub', $data['integration'], $this->adminId, $edit['integral'], '系统扣除了' . floatval($data['integration']) . '积分');
+ try {
+ UserRepository::adminSubIntegral($user, $data['integration']);
+ } catch (\Exception $e) {
BaseModel::rollbackTrans();
return Json::fail($e->getMessage());
}
}
- }else{
+ } else {
$res2 = true;
}
- if($edit) $res3 = UserModel::edit($edit,$uid);
+ if ($edit) $res3 = UserModel::edit($edit, $uid);
else $res3 = true;
- if($res1 && $res2 && $res3) $res =true;
+ if ($res1 && $res2 && $res3) $res = true;
else $res = false;
BaseModel::checkTrans($res);
- if($res) return Json::successful('修改成功!');
+ if ($res) return Json::successful('修改成功!');
else return Json::fail('修改失败');
}
@@ -160,112 +163,118 @@ class User extends AuthController
* @paran int $uid
* @return json
* */
- public function save_give_level($uid=0)
+ public function save_give_level($uid = 0)
{
- if(!$uid) return JsonService::fail('缺少参数');
- list($level_id)=Util::postMore([
- ['level_id',0],
- ],$this->request,true);
+ if (!$uid) return JsonService::fail('缺少参数');
+ list($level_id) = Util::postMore([
+ ['level_id', 0],
+ ], $this->request, true);
//查询当前选择的会员等级
- $systemLevel=SystemUserLevel::where(['is_show'=>1,'is_del'=>0,'id'=>$level_id])->find();
- if(!$systemLevel) return JsonService::fail('您选择赠送的会员等级不存在!');
+ $systemLevel = SystemUserLevel::where(['is_show' => 1, 'is_del' => 0, 'id' => $level_id])->find();
+ if (!$systemLevel) return JsonService::fail('您选择赠送的会员等级不存在!');
//检查是否拥有此会员等级
- $level=UserLevel::where(['uid'=>$uid,'level_id'=>$level_id,'is_del'=>0])->field('valid_time,is_forever')->find();
- if($level) if(!$level['is_forever'] && time() < $level['valid_time']) return JsonService::fail('此用户已有该会员等级,无法再次赠送');
+ $level = UserLevel::where(['uid' => $uid, 'level_id' => $level_id, 'is_del' => 0])->field('valid_time,is_forever')->find();
+ if ($level) if (!$level['is_forever'] && time() < $level['valid_time']) return JsonService::fail('此用户已有该会员等级,无法再次赠送');
//设置会员过期时间
- $add_valid_time=(int)$systemLevel->valid_date*86400;
+ $add_valid_time = (int)$systemLevel->valid_date * 86400;
UserModel::commitTrans();
- try{
+ try {
//保存会员信息
- $res=UserLevel::create([
- 'is_forever'=>$systemLevel->is_forever,
- 'status'=>1,
- 'is_del'=>0,
- 'grade'=>$systemLevel->grade,
- 'uid'=>$uid,
- 'add_time'=>time(),
- 'level_id'=>$level_id,
- 'discount'=>$systemLevel->discount,
- 'valid_time'=>$systemLevel->discount ? $add_valid_time + time() : 0,
- 'mark'=>'尊敬的用户【'.UserModel::where('uid',$uid)->value('nickname').'】在'.date('Y-m-d H:i:s',time()).'赠送会员等级成为'.$systemLevel['name'].'会员',
+ $res = UserLevel::create([
+ 'is_forever' => $systemLevel->is_forever,
+ 'status' => 1,
+ 'is_del' => 0,
+ 'grade' => $systemLevel->grade,
+ 'uid' => $uid,
+ 'add_time' => time(),
+ 'level_id' => $level_id,
+ 'discount' => $systemLevel->discount,
+ 'valid_time' => $systemLevel->discount ? $add_valid_time + time() : 0,
+ 'mark' => '尊敬的用户【' . UserModel::where('uid', $uid)->value('nickname') . '】在' . date('Y-m-d H:i:s', time()) . '赠送会员等级成为' . $systemLevel['name'] . '会员',
]);
//提取等级任务并记录完成情况
- $levelIds=[$level_id];
- $lowGradeLevelIds=SystemUserLevel::where('grade','<',$systemLevel->grade)->where(['is_show'=>1,'is_del'=>0])->column('id','id');
- if(count($lowGradeLevelIds)) $levelIds=array_merge($levelIds,$lowGradeLevelIds);
- $taskIds=Db::name('system_user_task')->where('level_id','in',$levelIds)->column('id','id');
- $inserValue=[];
- foreach ($taskIds as $id){
- $inserValue[]=['uid'=>$uid,'task_id'=>$id,'status'=>1,'add_time'=>time()];
+ $levelIds = [$level_id];
+ $lowGradeLevelIds = SystemUserLevel::where('grade', '<', $systemLevel->grade)->where(['is_show' => 1, 'is_del' => 0])->column('id', 'id');
+ if (count($lowGradeLevelIds)) $levelIds = array_merge($levelIds, $lowGradeLevelIds);
+ $taskIds = Db::name('system_user_task')->where('level_id', 'in', $levelIds)->column('id', 'id');
+ $inserValue = [];
+ foreach ($taskIds as $id) {
+ $inserValue[] = ['uid' => $uid, 'task_id' => $id, 'status' => 1, 'add_time' => time()];
}
- $res=$res && Db::name('user_task_finish')->insertAll($inserValue) && UserModel::where('uid',$uid)->update(['level'=>$level_id]);
- if($res){
+ $res = $res && Db::name('user_task_finish')->insertAll($inserValue) && UserModel::where('uid', $uid)->update(['level' => $level_id]);
+ if ($res) {
UserModel::commitTrans();
return JsonService::successful('赠送成功');
- }else{
+ } else {
UserModel::rollbackTrans();
return JsonService::successful('赠送失败');
}
- }catch (\Exception $e){
+ } catch (\Exception $e) {
UserModel::rollbackTrans();
return JsonService::fail('赠送失败');
}
}
+
/*
* 清除会员等级
* @param int $uid
* @return json
* */
- public function del_level($uid=0)
+ public function del_level($uid = 0)
{
- if(!$uid) return JsonService::fail('缺少参数');
- if(UserLevel::cleanUpLevel($uid))
+ if (!$uid) return JsonService::fail('缺少参数');
+ if (UserLevel::cleanUpLevel($uid))
return JsonService::successful('清除成功');
else
return JsonService::fail('清除失败');
}
+
/**
* 修改user表状态
*
* @return json
*/
- public function set_status($status='',$uid=0,$is_echo=0){
- if($is_echo==0) {
+ public function set_status($status = '', $uid = 0, $is_echo = 0)
+ {
+ if ($is_echo == 0) {
if ($status == '' || $uid == 0) return Json::fail('参数错误');
UserModel::where(['uid' => $uid])->update(['status' => $status]);
- }else{
- $uids=Util::postMore([
- ['uids',[]]
+ } else {
+ $uids = Util::postMore([
+ ['uids', []]
]);
- UserModel::destrSyatus($uids['uids'],$status);
+ UserModel::destrSyatus($uids['uids'], $status);
}
- return Json::successful($status==0 ? '禁用成功':'解禁成功');
+ return Json::successful($status == 0 ? '禁用成功' : '解禁成功');
}
+
/**
* 获取user表
*
* @return json
*/
- public function get_user_list(){
- $where=Util::getMore([
- ['page',1],
- ['limit',20],
- ['nickname',''],
- ['status',''],
- ['pay_count',''],
- ['is_promoter',''],
- ['order',''],
- ['data',''],
- ['user_type',''],
- ['country',''],
- ['province',''],
- ['city',''],
- ['user_time_type',''],
- ['user_time',''],
- ['sex',''],
+ public function get_user_list()
+ {
+ $where = Util::getMore([
+ ['page', 1],
+ ['limit', 20],
+ ['nickname', ''],
+ ['status', ''],
+ ['pay_count', ''],
+ ['is_promoter', ''],
+ ['order', ''],
+ ['data', ''],
+ ['user_type', ''],
+ ['country', ''],
+ ['province', ''],
+ ['city', ''],
+ ['user_time_type', ''],
+ ['user_time', ''],
+ ['sex', ''],
]);
return Json::successlayui(UserModel::getUserList($where));
}
+
/**
* 编辑模板消息
* @param $id
@@ -273,18 +282,18 @@ class User extends AuthController
*/
public function edit($uid)
{
- if(!$uid) return $this->failed('数据不存在');
+ if (!$uid) return $this->failed('数据不存在');
$user = UserModel::get($uid);
- if(!$user) return Json::fail('数据不存在!');
+ if (!$user) return Json::fail('数据不存在!');
$f = array();
- $f[] = Form::input('uid','用户编号',$user->getData('uid'))->disabled(1);
- $f[] = Form::input('real_name','真实姓名',$user->getData('real_name'));
- $f[] = Form::date('birthday','生日',$user->getData('birthday') ? date('Y-m-d',$user->getData('birthday')) : 0);
- $f[] = Form::input('card_id','身份证号',$user->getData('card_id'));
- $f[] = Form::textarea('mark','用户备注',$user->getData('mark'));
- $f[] = Form::radio('is_promoter','推广员',$user->getData('is_promoter'))->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'关闭']]);
- $f[] = Form::radio('status','状态',$user->getData('status'))->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'锁定']]);
- $form = Form::make_post_form('添加用户通知',$f,Url::buildUrl('update',array('uid'=>$uid)),5);
+ $f[] = Form::input('uid', '用户编号', $user->getData('uid'))->disabled(1);
+ $f[] = Form::input('real_name', '真实姓名', $user->getData('real_name'));
+ $f[] = Form::date('birthday', '生日', $user->getData('birthday') ? date('Y-m-d', $user->getData('birthday')) : 0);
+ $f[] = Form::input('card_id', '身份证号', $user->getData('card_id'));
+ $f[] = Form::textarea('mark', '用户备注', $user->getData('mark'));
+ $f[] = Form::radio('is_promoter', '推广员', $user->getData('is_promoter'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
+ $f[] = Form::radio('status', '状态', $user->getData('status'))->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '锁定']]);
+ $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('update', array('uid' => $uid)), 5);
$this->assign(compact('form'));
return $this->fetch('public/form-builder');
}
@@ -292,68 +301,68 @@ class User extends AuthController
public function update($uid)
{
$data = Util::postMore([
- ['money_status',0],
- ['is_promoter',1],
- ['real_name',''],
- ['card_id',''],
- ['birthday',''],
- ['mark',''],
- ['money',0],
- ['integration_status',0],
- ['integration',0],
- ['status',0],
+ ['money_status', 0],
+ ['is_promoter', 1],
+ ['real_name', ''],
+ ['card_id', ''],
+ ['birthday', ''],
+ ['mark', ''],
+ ['money', 0],
+ ['integration_status', 0],
+ ['integration', 0],
+ ['status', 0],
]);
- if(!$uid) return $this->failed('数据不存在');
+ if (!$uid) return $this->failed('数据不存在');
$user = UserModel::get($uid);
- if(!$user) return Json::fail('数据不存在!');
+ if (!$user) return Json::fail('数据不存在!');
BaseModel::beginTrans();
$res1 = false;
$res2 = false;
$edit = array();
- if($data['money_status'] && $data['money']){//余额增加或者减少
- if($data['money_status'] == 1){//增加
- $edit['now_money'] = bcadd($user['now_money'],$data['money'],2);
- $res1 = UserBillAdmin::income('系统增加余额',$user['uid'],'now_money','system_add',$data['money'],$this->adminId,$edit['now_money'],'系统增加了'.floatval($data['money']).'余额');
- try{
- UserRepository::adminAddMoney($user,$data['money']);
- }catch (\Exception $e){
- BaseModel::rollbackTrans();
- return Json::fail($e->getMessage());
- }
- }else if($data['money_status'] == 2){//减少
- $edit['now_money'] = bcsub($user['now_money'],$data['money'],2);
- $res1 = UserBillAdmin::expend('系统减少余额',$user['uid'],'now_money','system_sub',$data['money'],$this->adminId,$edit['now_money'],'系统扣除了'.floatval($data['money']).'余额');
- try{
- UserRepository::adminSubMoney($user,$data['money']);
- }catch (\Exception $e){
- BaseModel::rollbackTrans();
- return Json::fail($e->getMessage());
- }
- }
- }else{
- $res1 = true;
- }
- if($data['integration_status'] && $data['integration']){//积分增加或者减少
- if($data['integration_status'] == 1){//增加
- $edit['integral'] = bcadd($user['integral'],$data['integration'],2);
- $res2 = UserBillAdmin::income('系统增加积分',$user['uid'],'integral','system_add',$data['integration'],$this->adminId,$edit['integral'],'系统增加了'.floatval($data['integration']).'积分');
- try{
- UserRepository::adminAddIntegral($user,$data['integration']);
- }catch (\Exception $e){
+ if ($data['money_status'] && $data['money']) {//余额增加或者减少
+ if ($data['money_status'] == 1) {//增加
+ $edit['now_money'] = bcadd($user['now_money'], $data['money'], 2);
+ $res1 = UserBillAdmin::income('系统增加余额', $user['uid'], 'now_money', 'system_add', $data['money'], $this->adminId, $edit['now_money'], '系统增加了' . floatval($data['money']) . '余额');
+ try {
+ UserRepository::adminAddMoney($user, $data['money']);
+ } catch (\Exception $e) {
BaseModel::rollbackTrans();
return Json::fail($e->getMessage());
}
- }else if($data['integration_status'] == 2){//减少
- $edit['integral'] = bcsub($user['integral'],$data['integration'],2);
- $res2 = UserBillAdmin::expend('系统减少积分',$user['uid'],'integral','system_sub',$data['integration'],$this->adminId,$edit['integral'],'系统扣除了'.floatval($data['integration']).'积分');
- try{
- UserRepository::adminSubIntegral($user,$data['integration']);
- }catch (\Exception $e){
+ } else if ($data['money_status'] == 2) {//减少
+ $edit['now_money'] = bcsub($user['now_money'], $data['money'], 2);
+ $res1 = UserBillAdmin::expend('系统减少余额', $user['uid'], 'now_money', 'system_sub', $data['money'], $this->adminId, $edit['now_money'], '系统扣除了' . floatval($data['money']) . '余额');
+ try {
+ UserRepository::adminSubMoney($user, $data['money']);
+ } catch (\Exception $e) {
BaseModel::rollbackTrans();
return Json::fail($e->getMessage());
}
}
- }else{
+ } else {
+ $res1 = true;
+ }
+ if ($data['integration_status'] && $data['integration']) {//积分增加或者减少
+ if ($data['integration_status'] == 1) {//增加
+ $edit['integral'] = bcadd($user['integral'], $data['integration'], 2);
+ $res2 = UserBillAdmin::income('系统增加积分', $user['uid'], 'integral', 'system_add', $data['integration'], $this->adminId, $edit['integral'], '系统增加了' . floatval($data['integration']) . '积分');
+ try {
+ UserRepository::adminAddIntegral($user, $data['integration']);
+ } catch (\Exception $e) {
+ BaseModel::rollbackTrans();
+ return Json::fail($e->getMessage());
+ }
+ } else if ($data['integration_status'] == 2) {//减少
+ $edit['integral'] = bcsub($user['integral'], $data['integration'], 2);
+ $res2 = UserBillAdmin::expend('系统减少积分', $user['uid'], 'integral', 'system_sub', $data['integration'], $this->adminId, $edit['integral'], '系统扣除了' . floatval($data['integration']) . '积分');
+ try {
+ UserRepository::adminSubIntegral($user, $data['integration']);
+ } catch (\Exception $e) {
+ BaseModel::rollbackTrans();
+ return Json::fail($e->getMessage());
+ }
+ }
+ } else {
$res2 = true;
}
$edit['status'] = $data['status'];
@@ -362,358 +371,384 @@ class User extends AuthController
$edit['birthday'] = $data['birthday'];
$edit['mark'] = $data['mark'];
$edit['is_promoter'] = $data['is_promoter'];
- if($edit) $res3 = UserModel::edit($edit,$uid);
+ if ($edit) $res3 = UserModel::edit($edit, $uid);
else $res3 = true;
- if($res1 && $res2 && $res3) $res =true;
+ if ($res1 && $res2 && $res3) $res = true;
else $res = false;
BaseModel::checkTrans($res);
- if($res) return Json::successful('修改成功!');
+ if ($res) return Json::successful('修改成功!');
else return Json::fail('修改失败');
}
+
/**
* 用户图表
* @return mixed
*/
- public function user_analysis(){
+ public function user_analysis()
+ {
$where = Util::getMore([
- ['nickname',''],
- ['status',''],
- ['is_promoter',''],
- ['date',''],
- ['user_type',''],
- ['export',0]
- ],$this->request);
- $user_count=UserModel::consume($where,'',true);
+ ['nickname', ''],
+ ['status', ''],
+ ['is_promoter', ''],
+ ['date', ''],
+ ['user_type', ''],
+ ['export', 0]
+ ], $this->request);
+ $user_count = UserModel::consume($where, '', true);
//头部信息
- $header=[
+ $header = [
[
- 'name'=>'新增用户',
- 'class'=>'fa-line-chart',
- 'value'=>$user_count,
- 'color'=>'red'
+ 'name' => '新增用户',
+ 'class' => 'fa-line-chart',
+ 'value' => $user_count,
+ 'color' => 'red'
],
[
- 'name'=>'用户留存',
- 'class'=>'fa-area-chart',
- 'value'=>$this->gethreaderValue(UserModel::consume($where,'',true),$where).'%',
- 'color'=>'lazur'
+ 'name' => '用户留存',
+ 'class' => 'fa-area-chart',
+ 'value' => $this->gethreaderValue(UserModel::consume($where, '', true), $where) . '%',
+ 'color' => 'lazur'
],
[
- 'name'=>'新增用户总消费',
- 'class'=>'fa-bar-chart',
- 'value'=>'¥'.UserModel::consume($where),
- 'color'=>'navy'
+ 'name' => '新增用户总消费',
+ 'class' => 'fa-bar-chart',
+ 'value' => '¥' . UserModel::consume($where),
+ 'color' => 'navy'
],
[
- 'name'=>'用户活跃度',
- 'class'=>'fa-pie-chart',
- 'value'=>$this->gethreaderValue(UserModel::consume($where,'',true)).'%',
- 'color'=>'yellow'
+ 'name' => '用户活跃度',
+ 'class' => 'fa-pie-chart',
+ 'value' => $this->gethreaderValue(UserModel::consume($where, '', true)) . '%',
+ 'color' => 'yellow'
],
];
- $name=['新增用户','用户消费'];
- $dates=$this->get_user_index($where,$name);
- $user_index=['name'=>json_encode($name), 'date'=>json_encode($dates['time']), 'series'=>json_encode($dates['series'])];
+ $name = ['新增用户', '用户消费'];
+ $dates = $this->get_user_index($where, $name);
+ $user_index = ['name' => json_encode($name), 'date' => json_encode($dates['time']), 'series' => json_encode($dates['series'])];
//用户浏览分析
- $view=StoreVisit::getVisit($where['date'],['','warning','info','danger']);
- $view_v1=WechatMessage::getViweList($where['date'],['','warning','info','danger']);
- $view=array_merge($view,$view_v1);
- $view_v2=[];
- foreach ($view as $val){
- $view_v2['color'][]='#'.rand(100000,339899);
- $view_v2['name'][]=$val['name'];
- $view_v2['value'][]=$val['value'];
+ $view = StoreVisit::getVisit($where['date'], ['', 'warning', 'info', 'danger']);
+ $view_v1 = WechatMessage::getViweList($where['date'], ['', 'warning', 'info', 'danger']);
+ $view = array_merge($view, $view_v1);
+ $view_v2 = [];
+ foreach ($view as $val) {
+ $view_v2['color'][] = '#' . rand(100000, 339899);
+ $view_v2['name'][] = $val['name'];
+ $view_v2['value'][] = $val['value'];
}
- $view=$view_v2;
+ $view = $view_v2;
//消费会员排行用户分析
- $user_null=UserModel::getUserSpend($where['date']);
+ $user_null = UserModel::getUserSpend($where['date']);
//消费数据
- $now_number=UserModel::getUserSpend($where['date'],true);
- list($paren_number,$title)=UserModel::getPostNumber($where['date']);
- if($paren_number==0) {
- $rightTitle=[
- 'number'=>$now_number>0?$now_number:0,
- 'icon'=>'fa-level-up',
- 'title'=>$title
+ $now_number = UserModel::getUserSpend($where['date'], true);
+ list($paren_number, $title) = UserModel::getPostNumber($where['date']);
+ if ($paren_number == 0) {
+ $rightTitle = [
+ 'number' => $now_number > 0 ? $now_number : 0,
+ 'icon' => 'fa-level-up',
+ 'title' => $title
];
- }else{
- $number=(float)bcsub($now_number,$paren_number,4);
- if($now_number==0){
- $icon='fa-level-down';
- }else{
- $icon=$now_number>$paren_number?'fa-level-up':'fa-level-down';
+ } else {
+ $number = (float)bcsub($now_number, $paren_number, 4);
+ if ($now_number == 0) {
+ $icon = 'fa-level-down';
+ } else {
+ $icon = $now_number > $paren_number ? 'fa-level-up' : 'fa-level-down';
}
- $rightTitle=['number'=>$number, 'icon'=>$icon, 'title'=>$title];
+ $rightTitle = ['number' => $number, 'icon' => $icon, 'title' => $title];
}
- unset($title,$paren_number,$now_number);
- list($paren_user_count,$title)=UserModel::getPostNumber($where['date'],true,'add_time','');
- if($paren_user_count==0){
- $count=$user_count==0?0:$user_count;
- $icon=$user_count==0?'fa-level-down':'fa-level-up';
- }else{
- $count=(float)bcsub($user_count,$paren_user_count,4);
- $icon=$user_count<$paren_user_count?'fa-level-down':'fa-level-up';
+ unset($title, $paren_number, $now_number);
+ list($paren_user_count, $title) = UserModel::getPostNumber($where['date'], true, 'add_time', '');
+ if ($paren_user_count == 0) {
+ $count = $user_count == 0 ? 0 : $user_count;
+ $icon = $user_count == 0 ? 'fa-level-down' : 'fa-level-up';
+ } else {
+ $count = (float)bcsub($user_count, $paren_user_count, 4);
+ $icon = $user_count < $paren_user_count ? 'fa-level-down' : 'fa-level-up';
}
- $leftTitle=[
- 'count'=>$count,
- 'icon'=>$icon,
- 'title'=>$title
+ $leftTitle = [
+ 'count' => $count,
+ 'icon' => $icon,
+ 'title' => $title
];
- unset($count,$icon,$title);
- $consume=[
- 'title'=>'消费金额为¥'.UserModel::consume($where),
- 'series'=>UserModel::consume($where,'xiaofei'),
- 'rightTitle'=>$rightTitle,
- 'leftTitle'=>$leftTitle,
+ unset($count, $icon, $title);
+ $consume = [
+ 'title' => '消费金额为¥' . UserModel::consume($where),
+ 'series' => UserModel::consume($where, 'xiaofei'),
+ 'rightTitle' => $rightTitle,
+ 'leftTitle' => $leftTitle,
];
- $form=UserModel::consume($where,'form');
- $grouping=UserModel::consume($where,'grouping');
- $this->assign(compact('header','user_index','view','user_null','consume','form','grouping','where'));
+ $form = UserModel::consume($where, 'form');
+ $grouping = UserModel::consume($where, 'grouping');
+ $this->assign(compact('header', 'user_index', 'view', 'user_null', 'consume', 'form', 'grouping', 'where'));
return $this->fetch();
}
- public function gethreaderValue($chart,$where=[]){
- if($where){
- switch($where['date']){
- case null:case 'today':case 'week':case 'year':
- if($where['date']==null){
- $where['date']='month';
- }
- $sum_user=UserModel::whereTime('add_time',$where['date'])->count();
- if($sum_user==0) return 0;
- $counts=bcdiv($chart,$sum_user,4)*100;
- return $counts;
- break;
+
+ public function gethreaderValue($chart, $where = [])
+ {
+ if ($where) {
+ switch ($where['date']) {
+ case null:
+ case 'today':
+ case 'week':
+ case 'year':
+ if ($where['date'] == null) {
+ $where['date'] = 'month';
+ }
+ $sum_user = UserModel::whereTime('add_time', $where['date'])->count();
+ if ($sum_user == 0) return 0;
+ $counts = bcdiv($chart, $sum_user, 4) * 100;
+ return $counts;
+ break;
case 'quarter':
- $quarter=UserModel::getMonth('n');
- $quarter[0]=strtotime($quarter[0]);
- $quarter[1]=strtotime($quarter[1]);
- $sum_user=UserModel::where('add_time','between',$quarter)->count();
- if($sum_user==0) return 0;
- $counts=bcdiv($chart,$sum_user,4)*100;
+ $quarter = UserModel::getMonth('n');
+ $quarter[0] = strtotime($quarter[0]);
+ $quarter[1] = strtotime($quarter[1]);
+ $sum_user = UserModel::where('add_time', 'between', $quarter)->count();
+ if ($sum_user == 0) return 0;
+ $counts = bcdiv($chart, $sum_user, 4) * 100;
return $counts;
default:
//自定义时间
- $quarter=explode('-',$where['date']);
- $quarter[0]=strtotime($quarter[0]);
- $quarter[1]=strtotime($quarter[1]);
- $sum_user=UserModel::where('add_time','between',$quarter)->count();
- if($sum_user==0) return 0;
- $counts=bcdiv($chart,$sum_user,4)*100;
+ $quarter = explode('-', $where['date']);
+ $quarter[0] = strtotime($quarter[0]);
+ $quarter[1] = strtotime($quarter[1]);
+ $sum_user = UserModel::where('add_time', 'between', $quarter)->count();
+ if ($sum_user == 0) return 0;
+ $counts = bcdiv($chart, $sum_user, 4) * 100;
return $counts;
break;
}
- }else{
- $num=UserModel::count();
- $chart=$num!=0?bcdiv($chart,$num,5)*100:0;
+ } else {
+ $num = UserModel::count();
+ $chart = $num != 0 ? bcdiv($chart, $num, 5) * 100 : 0;
return $chart;
}
}
- public function get_user_index($where,$name){
- switch ($where['date']){
+
+ public function get_user_index($where, $name)
+ {
+ switch ($where['date']) {
case null:
- $days = date("t",strtotime(date('Y-m',time())));
- $dates=[];
- $series=[];
- $times_list=[];
- foreach ($name as $key=>$val){
- for($i=1;$i<=$days;$i++){
- if(!in_array($i.'号',$times_list)){
- array_push($times_list,$i.'号');
+ $days = date("t", strtotime(date('Y-m', time())));
+ $dates = [];
+ $series = [];
+ $times_list = [];
+ foreach ($name as $key => $val) {
+ for ($i = 1; $i <= $days; $i++) {
+ if (!in_array($i . '号', $times_list)) {
+ array_push($times_list, $i . '号');
}
- $time=$this->gettime(date("Y-m",time()).'-'.$i);
- if($key==0){
- $dates['data'][]=UserModel::where('add_time','between',$time)->count();
- }else if($key==1){
- $dates['data'][]=UserModel::consume(true,$time);
+ $time = $this->gettime(date("Y-m", time()) . '-' . $i);
+ if ($key == 0) {
+ $dates['data'][] = UserModel::where('add_time', 'between', $time)->count();
+ } else if ($key == 1) {
+ $dates['data'][] = UserModel::consume(true, $time);
}
}
- $dates['name']=$val;
- $dates['type']='line';
- $series[]=$dates;
+ $dates['name'] = $val;
+ $dates['type'] = 'line';
+ $series[] = $dates;
unset($dates);
}
- return ['time'=>$times_list,'series'=>$series];
+ return ['time' => $times_list, 'series' => $series];
case 'today':
- $dates=[];
- $series=[];
- $times_list=[];
- foreach ($name as $key=>$val){
- for($i=0;$i<=24;$i++){
- $strtitle=$i.'点';
- if(!in_array($strtitle,$times_list)){
- array_push($times_list,$strtitle);
+ $dates = [];
+ $series = [];
+ $times_list = [];
+ foreach ($name as $key => $val) {
+ for ($i = 0; $i <= 24; $i++) {
+ $strtitle = $i . '点';
+ if (!in_array($strtitle, $times_list)) {
+ array_push($times_list, $strtitle);
}
- $time=$this->gettime(date("Y-m-d ",time()).$i);
- if($key==0){
- $dates['data'][]=UserModel::where('add_time','between',$time)->count();
- }else if($key==1){
- $dates['data'][]=UserModel::consume(true,$time);
+ $time = $this->gettime(date("Y-m-d ", time()) . $i);
+ if ($key == 0) {
+ $dates['data'][] = UserModel::where('add_time', 'between', $time)->count();
+ } else if ($key == 1) {
+ $dates['data'][] = UserModel::consume(true, $time);
}
}
- $dates['name']=$val;
- $dates['type']='line';
- $series[]=$dates;
+ $dates['name'] = $val;
+ $dates['type'] = 'line';
+ $series[] = $dates;
unset($dates);
}
- return ['time'=>$times_list,'series'=>$series];
+ return ['time' => $times_list, 'series' => $series];
case "week":
- $dates=[];
- $series=[];
- $times_list=[];
- foreach ($name as $key=>$val){
- for($i=0;$i<=6;$i++){
- if(!in_array('星期'.($i+1),$times_list)){
- array_push($times_list,'星期'.($i+1));
+ $dates = [];
+ $series = [];
+ $times_list = [];
+ foreach ($name as $key => $val) {
+ for ($i = 0; $i <= 6; $i++) {
+ if (!in_array('星期' . ($i + 1), $times_list)) {
+ array_push($times_list, '星期' . ($i + 1));
}
- $time=UserModel::getMonth('h',$i);
- if($key==0){
- $dates['data'][]=UserModel::where('add_time','between',[strtotime($time[0]),strtotime($time[1])])->count();
- }else if($key==1){
- $dates['data'][]=UserModel::consume(true,[strtotime($time[0]),strtotime($time[1])]);
+ $time = UserModel::getMonth('h', $i);
+ if ($key == 0) {
+ $dates['data'][] = UserModel::where('add_time', 'between', [strtotime($time[0]), strtotime($time[1])])->count();
+ } else if ($key == 1) {
+ $dates['data'][] = UserModel::consume(true, [strtotime($time[0]), strtotime($time[1])]);
}
}
- $dates['name']=$val;
- $dates['type']='line';
- $series[]=$dates;
+ $dates['name'] = $val;
+ $dates['type'] = 'line';
+ $series[] = $dates;
unset($dates);
}
- return ['time'=>$times_list,'series'=>$series];
+ return ['time' => $times_list, 'series' => $series];
case 'year':
- $dates=[];
- $series=[];
- $times_list=[];
- $year=date('Y');
- foreach ($name as $key=>$val){
- for($i=1;$i<=12;$i++){
- if(!in_array($i.'月',$times_list)){
- array_push($times_list,$i.'月');
+ $dates = [];
+ $series = [];
+ $times_list = [];
+ $year = date('Y');
+ foreach ($name as $key => $val) {
+ for ($i = 1; $i <= 12; $i++) {
+ if (!in_array($i . '月', $times_list)) {
+ array_push($times_list, $i . '月');
}
- $t = strtotime($year.'-'.$i.'-01');
- $arr= explode('/',date('Y-m-01',$t).'/'.date('Y-m-',$t).date('t',$t));
- if($key==0){
- $dates['data'][]=UserModel::where('add_time','between',[strtotime($arr[0]),strtotime($arr[1])])->count();
- }else if($key==1){
- $dates['data'][]=UserModel::consume(true,[strtotime($arr[0]),strtotime($arr[1])]);
+ $t = strtotime($year . '-' . $i . '-01');
+ $arr = explode('/', date('Y-m-01', $t) . '/' . date('Y-m-', $t) . date('t', $t));
+ if ($key == 0) {
+ $dates['data'][] = UserModel::where('add_time', 'between', [strtotime($arr[0]), strtotime($arr[1])])->count();
+ } else if ($key == 1) {
+ $dates['data'][] = UserModel::consume(true, [strtotime($arr[0]), strtotime($arr[1])]);
}
}
- $dates['name']=$val;
- $dates['type']='line';
- $series[]=$dates;
+ $dates['name'] = $val;
+ $dates['type'] = 'line';
+ $series[] = $dates;
unset($dates);
}
- return ['time'=>$times_list,'series'=>$series];
+ return ['time' => $times_list, 'series' => $series];
case 'quarter':
- $dates=[];
- $series=[];
- $times_list=[];
- foreach ($name as $key=>$val){
- for($i=1;$i<=4;$i++){
- $arr=$this->gettime('quarter',$i);
- if(!in_array(implode('--',$arr).'季度',$times_list)){
- array_push($times_list,implode('--',$arr).'季度');
+ $dates = [];
+ $series = [];
+ $times_list = [];
+ foreach ($name as $key => $val) {
+ for ($i = 1; $i <= 4; $i++) {
+ $arr = $this->gettime('quarter', $i);
+ if (!in_array(implode('--', $arr) . '季度', $times_list)) {
+ array_push($times_list, implode('--', $arr) . '季度');
}
- if($key==0){
- $dates['data'][]=UserModel::where('add_time','between',[strtotime($arr[0]),strtotime($arr[1])])->count();
- }else if($key==1){
- $dates['data'][]=UserModel::consume(true,[strtotime($arr[0]),strtotime($arr[1])]);
+ if ($key == 0) {
+ $dates['data'][] = UserModel::where('add_time', 'between', [strtotime($arr[0]), strtotime($arr[1])])->count();
+ } else if ($key == 1) {
+ $dates['data'][] = UserModel::consume(true, [strtotime($arr[0]), strtotime($arr[1])]);
}
}
- $dates['name']=$val;
- $dates['type']='line';
- $series[]=$dates;
+ $dates['name'] = $val;
+ $dates['type'] = 'line';
+ $series[] = $dates;
unset($dates);
}
- return ['time'=>$times_list,'series'=>$series];
+ return ['time' => $times_list, 'series' => $series];
default:
- $list=UserModel::consume($where,'default');
- $dates=[];
- $series=[];
- $times_list=[];
- foreach ($name as $k=>$v){
- foreach ($list as $val){
- $date=$val['add_time'];
- if(!in_array($date,$times_list)){
- array_push($times_list,$date);
+ $list = UserModel::consume($where, 'default');
+ $dates = [];
+ $series = [];
+ $times_list = [];
+ foreach ($name as $k => $v) {
+ foreach ($list as $val) {
+ $date = $val['add_time'];
+ if (!in_array($date, $times_list)) {
+ array_push($times_list, $date);
}
- if($k==0){
- $dates['data'][]=$val['num'];
- }else if($k==1){
- $dates['data'][]=UserBillAdmin::where(['uid'=>$val['uid'],'type'=>'pay_product'])->sum('number');
+ if ($k == 0) {
+ $dates['data'][] = $val['num'];
+ } else if ($k == 1) {
+ $dates['data'][] = UserBillAdmin::where(['uid' => $val['uid'], 'type' => 'pay_product'])->sum('number');
}
}
- $dates['name']=$v;
- $dates['type']='line';
- $series[]=$dates;
+ $dates['name'] = $v;
+ $dates['type'] = 'line';
+ $series[] = $dates;
unset($dates);
}
- return ['time'=>$times_list,'series'=>$series];
+ return ['time' => $times_list, 'series' => $series];
}
}
- public function gettime($time='',$season=''){
- if(!empty($time) && empty($season)){
+
+ public function gettime($time = '', $season = '')
+ {
+ if (!empty($time) && empty($season)) {
$timestamp0 = strtotime($time);
- $timestamp24 =strtotime($time)+86400;
- return [$timestamp0,$timestamp24];
- }else if(!empty($time) && !empty($season)){
- $firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
- $lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y')));
- return [$firstday,$lastday];
+ $timestamp24 = strtotime($time) + 86400;
+ return [$timestamp0, $timestamp24];
+ } else if (!empty($time) && !empty($season)) {
+ $firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
+ $lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
+ return [$firstday, $lastday];
}
}
/**
* 会员等级首页
*/
- public function group(){
+ public function group()
+ {
return $this->fetch();
}
+
/**
* 会员详情
*/
- public function see($uid=''){
+ public function see($uid = '')
+ {
$this->assign([
- 'uid'=>$uid,
- 'userinfo'=>UserModel::getUserDetailed($uid),
- 'is_layui'=>true,
- 'headerList'=>UserModel::getHeaderList($uid),
- 'count'=>UserModel::getCountInfo($uid),
+ 'uid' => $uid,
+ 'userinfo' => UserModel::getUserDetailed($uid),
+ 'is_layui' => true,
+ 'headerList' => UserModel::getHeaderList($uid),
+ 'count' => UserModel::getCountInfo($uid),
]);
return $this->fetch();
}
+
/*
* 获取某个用户的推广下线
* */
- public function getSpreadList($uid,$page=1,$limit=20){
- return Json::successful(UserModel::getSpreadList($uid,(int)$page,(int)$limit));
+ public function getSpreadList($uid, $page = 1, $limit = 20)
+ {
+ return Json::successful(UserModel::getSpreadList($uid, (int)$page, (int)$limit));
}
+
/**
* 获取某用户的订单列表
*/
- public function getOneorderList($uid,$page=1,$limit=20){
- return Json::successful(StoreOrder::getOneorderList(compact('uid','page','limit')));
+ public function getOneorderList($uid, $page = 1, $limit = 20)
+ {
+ return Json::successful(StoreOrder::getOneorderList(compact('uid', 'page', 'limit')));
}
+
/**
* 获取某用户的积分列表
*/
- public function getOneIntegralList($uid,$page=1,$limit=20){
- return Json::successful(UserBillAdmin::getOneIntegralList(compact('uid','page','limit')));
+ public function getOneIntegralList($uid, $page = 1, $limit = 20)
+ {
+ return Json::successful(UserBillAdmin::getOneIntegralList(compact('uid', 'page', 'limit')));
}
+
/**
* 获取某用户的积分列表
*/
- public function getOneSignList($uid,$page=1,$limit=20){
- return Json::successful(UserBillAdmin::getOneSignList(compact('uid','page','limit')));
+ public function getOneSignList($uid, $page = 1, $limit = 20)
+ {
+ return Json::successful(UserBillAdmin::getOneSignList(compact('uid', 'page', 'limit')));
}
+
/**
* 获取某用户的持有优惠劵
*/
- public function getOneCouponsList($uid,$page=1,$limit=20){
- return Json::successful(StoreCouponUser::getOneCouponsList(compact('uid','page','limit')));
+ public function getOneCouponsList($uid, $page = 1, $limit = 20)
+ {
+ return Json::successful(StoreCouponUser::getOneCouponsList(compact('uid', 'page', 'limit')));
}
+
/**
* 获取某用户的余额变动记录
*/
- public function getOneBalanceChangList($uid,$page=1,$limit=20){
- return Json::successful(UserBillAdmin::getOneBalanceChangList(compact('uid','page','limit')));
+ public function getOneBalanceChangList($uid, $page = 1, $limit = 20)
+ {
+ return Json::successful(UserBillAdmin::getOneBalanceChangList(compact('uid', 'page', 'limit')));
}
}
diff --git a/crmeb/app/admin/model/order/StoreOrder.php b/crmeb/app/admin/model/order/StoreOrder.php
index 7d839a00..88fa54cb 100644
--- a/crmeb/app/admin/model/order/StoreOrder.php
+++ b/crmeb/app/admin/model/order/StoreOrder.php
@@ -22,6 +22,7 @@ use think\facade\Route as Url;
use think\facade\Db;
use app\admin\model\user\User;
use app\admin\model\user\UserBill;
+
/**
* 订单管理Model
* Class StoreOrder
@@ -44,52 +45,54 @@ class StoreOrder extends BaseModel
use ModelTrait;
- public static function orderCount(){
- $data['wz']=self::statusByWhere(0,new self())->where(['is_system_del'=>0])->count();
- $data['wf']=self::statusByWhere(1,new self())->where(['is_system_del'=>0,'shipping_type'=>1])->count();
- $data['ds']=self::statusByWhere(2,new self())->where(['is_system_del'=>0,'shipping_type'=>1])->count();
- $data['dp']=self::statusByWhere(3,new self())->where(['is_system_del'=>0])->count();
- $data['jy']=self::statusByWhere(4,new self())->where(['is_system_del'=>0])->count();
- $data['tk']=self::statusByWhere(-1,new self())->where(['is_system_del'=>0])->count();
- $data['yt']=self::statusByWhere(-2,new self())->where(['is_system_del'=>0])->count();
- $data['del']=self::statusByWhere(-4,new self())->where(['is_system_del'=>0])->count();
- $data['write_off'] =self::statusByWhere(5,new self())->where(['is_system_del'=>0])->count();
- $data['general']=self::where(['pink_id'=>0,'combination_id'=>0,'seckill_id'=>0,'bargain_id'=>0,'is_system_del'=>0])->count();
- $data['pink']=self::where('pink_id|combination_id','>',0)->where('is_system_del',0)->count();
- $data['seckill']=self::where('seckill_id','>',0)->where('is_system_del',0)->count();
- $data['bargain']=self::where('bargain_id','>',0)->where('is_system_del',0)->count();
+ public static function orderCount()
+ {
+ $data['wz'] = self::statusByWhere(0, new self())->where(['is_system_del' => 0])->count();
+ $data['wf'] = self::statusByWhere(1, new self())->where(['is_system_del' => 0, 'shipping_type' => 1])->count();
+ $data['ds'] = self::statusByWhere(2, new self())->where(['is_system_del' => 0, 'shipping_type' => 1])->count();
+ $data['dp'] = self::statusByWhere(3, new self())->where(['is_system_del' => 0])->count();
+ $data['jy'] = self::statusByWhere(4, new self())->where(['is_system_del' => 0])->count();
+ $data['tk'] = self::statusByWhere(-1, new self())->where(['is_system_del' => 0])->count();
+ $data['yt'] = self::statusByWhere(-2, new self())->where(['is_system_del' => 0])->count();
+ $data['del'] = self::statusByWhere(-4, new self())->where(['is_system_del' => 0])->count();
+ $data['write_off'] = self::statusByWhere(5, new self())->where(['is_system_del' => 0])->count();
+ $data['general'] = self::where(['pink_id' => 0, 'combination_id' => 0, 'seckill_id' => 0, 'bargain_id' => 0, 'is_system_del' => 0])->count();
+ $data['pink'] = self::where('pink_id|combination_id', '>', 0)->where('is_system_del', 0)->count();
+ $data['seckill'] = self::where('seckill_id', '>', 0)->where('is_system_del', 0)->count();
+ $data['bargain'] = self::where('bargain_id', '>', 0)->where('is_system_del', 0)->count();
return $data;
}
- public static function OrderList($where){
- $model = self::getOrderWhere($where,self::alias('a')->join('user r','r.uid=a.uid','LEFT'),'a.','r')->field('a.*,r.nickname,r.phone,r.spread_uid');
- if($where['order']!=''){
+ public static function OrderList($where)
+ {
+ $model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.*,r.nickname,r.phone,r.spread_uid');
+ if ($where['order'] != '') {
$model = $model->order(self::setOrder($where['order']));
- }else{
+ } else {
$model = $model->order('a.id desc');
}
- if(isset($where['excel']) && $where['excel']==1){
- $data=($data=$model->select()) && count($data) ? $data->toArray() : [];
- }else{
- $data=($data=$model->page((int)$where['page'],(int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
+ if (isset($where['excel']) && $where['excel'] == 1) {
+ $data = ($data = $model->select()) && count($data) ? $data->toArray() : [];
+ } else {
+ $data = ($data = $model->page((int)$where['page'], (int)$where['limit'])->select()) && count($data) ? $data->toArray() : [];
}
- foreach ($data as &$item){
- $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select();
+ foreach ($data as &$item) {
+ $_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->field('cart_info')->select();
$_info = count($_info) ? $_info->toArray() : [];
- foreach ($_info as $k=>$v){
- $cart_info = json_decode($v['cart_info'],true);
- if(!isset($cart_info['productInfo'])) $cart_info['productInfo']=[];
+ foreach ($_info as $k => $v) {
+ $cart_info = json_decode($v['cart_info'], true);
+ if (!isset($cart_info['productInfo'])) $cart_info['productInfo'] = [];
$_info[$k]['cart_info'] = $cart_info;
unset($cart_info);
}
$item['_info'] = $_info;
- $item['spread_nickname'] = Db::name('user')->where('uid',$item['spread_uid'])->value('nickname');
- $item['add_time'] = date('Y-m-d H:i:s',$item['add_time']);
- $item['back_integral'] = $item['back_integral'] ? : 0;
- if($item['pink_id'] || $item['combination_id']){
- $pinkStatus = StorePink::where('order_id_key',$item['id'])->value('status');
- switch ($pinkStatus){
+ $item['spread_nickname'] = Db::name('user')->where('uid', $item['spread_uid'])->value('nickname');
+ $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
+ $item['back_integral'] = $item['back_integral'] ?: 0;
+ if ($item['pink_id'] || $item['combination_id']) {
+ $pinkStatus = StorePink::where('order_id_key', $item['id'])->value('status');
+ switch ($pinkStatus) {
case 1:
$item['pink_name'] = '[拼团订单]正在进行中';
$item['color'] = '#f00';
@@ -107,75 +110,75 @@ class StoreOrder extends BaseModel
$item['color'] = '#457856';
break;
}
- }elseif ($item['seckill_id']){
+ } elseif ($item['seckill_id']) {
$item['pink_name'] = '[秒杀订单]';
$item['color'] = '#32c5e9';
- }elseif ($item['bargain_id']){
+ } elseif ($item['bargain_id']) {
$item['pink_name'] = '[砍价订单]';
$item['color'] = '#12c5e9';
- }else{
- if($item['shipping_type']==1){
+ } else {
+ if ($item['shipping_type'] == 1) {
$item['pink_name'] = '[普通订单]';
$item['color'] = '#895612';
- }else if($item['shipping_type']==2){
+ } else if ($item['shipping_type'] == 2) {
$item['pink_name'] = '[核销订单]';
$item['color'] = '#8956E8';
}
}
- if($item['paid']==1){
- switch ($item['pay_type']){
+ if ($item['paid'] == 1) {
+ switch ($item['pay_type']) {
case 'weixin':
- $item['pay_type_name']='微信支付';
+ $item['pay_type_name'] = '微信支付';
break;
case 'yue':
- $item['pay_type_name']='余额支付';
+ $item['pay_type_name'] = '余额支付';
break;
case 'offline':
- $item['pay_type_name']='线下支付';
+ $item['pay_type_name'] = '线下支付';
break;
default:
- $item['pay_type_name']='其他支付';
+ $item['pay_type_name'] = '其他支付';
break;
}
- }else{
- switch ($item['pay_type']){
+ } else {
+ switch ($item['pay_type']) {
default:
- $item['pay_type_name']='未支付';
+ $item['pay_type_name'] = '未支付';
break;
case 'offline':
- $item['pay_type_name']='线下支付';
- $item['pay_type_info']=1;
+ $item['pay_type_name'] = '线下支付';
+ $item['pay_type_info'] = 1;
break;
}
}
- if($item['paid']==0 && $item['status']==0){
- $item['status_name']='未支付';
- }else if($item['paid']==1 && $item['status']==0 && $item['shipping_type']==1 && $item['refund_status']==0){
- $item['status_name']='未发货';
- }else if($item['paid']==1 && $item['status']==0 && $item['shipping_type']==2 && $item['refund_status']==0){
- $item['status_name']='未核销';
- }else if($item['paid']==1 && $item['status']==1 && $item['shipping_type']==1 && $item['refund_status']==0){
- $item['status_name']='待收货';
- }else if($item['paid']==1 && $item['status']==1 && $item['shipping_type']==2 && $item['refund_status']==0){
- $item['status_name']='未核销';
- }else if($item['paid']==1 && $item['status']==2 && $item['refund_status']==0){
- $item['status_name']='待评价';
- }else if($item['paid']==1 && $item['status']==3 && $item['refund_status']==0){
- $item['status_name']='已完成';
- }else if($item['paid']==1 && $item['refund_status']==1){
+ if ($item['paid'] == 0 && $item['status'] == 0) {
+ $item['status_name'] = '未支付';
+ } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
+ $item['status_name'] = '未发货';
+ } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
+ $item['status_name'] = '未核销';
+ } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['shipping_type'] == 1 && $item['refund_status'] == 0) {
+ $item['status_name'] = '待收货';
+ } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['shipping_type'] == 2 && $item['refund_status'] == 0) {
+ $item['status_name'] = '未核销';
+ } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
+ $item['status_name'] = '待评价';
+ } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
+ $item['status_name'] = '已完成';
+ } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
$refundReasonTime = date('Y-m-d H:i', $item['refund_reason_time']);
$refundReasonWapImg = json_decode($item['refund_reason_wap_img'], true);
$refundReasonWapImg = $refundReasonWapImg ? $refundReasonWapImg : [];
$img = '';
- if(count($refundReasonWapImg)){
- foreach ($refundReasonWapImg as $itemImg){
- if(strlen(trim($itemImg)))
- $img .='
';
+ if (count($refundReasonWapImg)) {
+ foreach ($refundReasonWapImg as $itemImg) {
+ if (strlen(trim($itemImg)))
+ $img .= '
';
}
}
- if (!strlen(trim($img))) $img = '无';
+ if (!strlen(trim($img))) $img = '无';
if (isset($where['excel']) && $where['excel'] == 1) {
- $refundImageStr = implode(',',$refundReasonWapImg);
+ $refundImageStr = implode(',', $refundReasonWapImg);
$item['status_name'] = <<申请退款
退款原因:{$item['refund_reason_wap']}
@@ -192,54 +195,56 @@ TEXT;
退款凭证:{$img}
HTML;
}
- }else if($item['paid']==1 && $item['refund_status']==2){
- $item['status_name']='已退款';
+ } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
+ $item['status_name'] = '已退款';
}
- if($item['paid']==0 && $item['status']==0 && $item['refund_status']==0){
- $item['_status']=1;
- }else if($item['paid']==1 && $item['status']==0 && $item['refund_status']==0){
- $item['_status']=2;
- }else if($item['paid']==1 && $item['refund_status']==1){
- $item['_status']=3;
- }else if($item['paid']==1 && $item['status']==1 && $item['refund_status']==0){
- $item['_status']=4;
- }else if($item['paid']==1 && $item['status']==2 && $item['refund_status']==0){
- $item['_status']=5;
- }else if($item['paid']==1 && $item['status']==3 && $item['refund_status']==0){
- $item['_status']=6;
- }else if($item['paid']==1 && $item['refund_status']==2){
- $item['_status']=7;
+ if ($item['paid'] == 0 && $item['status'] == 0 && $item['refund_status'] == 0) {
+ $item['_status'] = 1;
+ } else if ($item['paid'] == 1 && $item['status'] == 0 && $item['refund_status'] == 0) {
+ $item['_status'] = 2;
+ } else if ($item['paid'] == 1 && $item['refund_status'] == 1) {
+ $item['_status'] = 3;
+ } else if ($item['paid'] == 1 && $item['status'] == 1 && $item['refund_status'] == 0) {
+ $item['_status'] = 4;
+ } else if ($item['paid'] == 1 && $item['status'] == 2 && $item['refund_status'] == 0) {
+ $item['_status'] = 5;
+ } else if ($item['paid'] == 1 && $item['status'] == 3 && $item['refund_status'] == 0) {
+ $item['_status'] = 6;
+ } else if ($item['paid'] == 1 && $item['refund_status'] == 2) {
+ $item['_status'] = 7;
}
}
- if(isset($where['excel']) && $where['excel']==1){
+ if (isset($where['excel']) && $where['excel'] == 1) {
self::SaveExcel($data);
}
- $count=self::getOrderWhere($where,self::alias('a')->join('user r','r.uid=a.uid','LEFT'),'a.','r')->count();
- return compact('count','data');
+ $count = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->count();
+ return compact('count', 'data');
}
+
/*
* 保存并下载excel
* $list array
* return
*/
- public static function SaveExcel($list){
+ public static function SaveExcel($list)
+ {
$export = [];
- foreach ($list as $index=>$item){
- $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->column('cart_info');
+ foreach ($list as $index => $item) {
+ $_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->column('cart_info');
$goodsName = [];
- foreach ($_info as $k=>$v){
- $v = json_decode($v,true);
+ foreach ($_info as $k => $v) {
+ $v = json_decode($v, true);
$goodsName[] = implode(
[$v['productInfo']['store_name'],
- isset($v['productInfo']['attrInfo']) ? '('.$v['productInfo']['attrInfo']['suk'].')' : '',
+ isset($v['productInfo']['attrInfo']) ? '(' . $v['productInfo']['attrInfo']['suk'] . ')' : '',
"[{$v['cart_num']} * {$v['truePrice']}]"
- ],' ');
+ ], ' ');
}
$item['cartInfo'] = $_info;
- $sex=Db::name('wechat_user')->where('uid',$item['uid'])->value('sex');
- if($sex==1) $sex_name='男';
- else if($sex==2) $sex_name='女';
- else $sex_name='未知';
+ $sex = Db::name('wechat_user')->where('uid', $item['uid'])->value('sex');
+ if ($sex == 1) $sex_name = '男';
+ else if ($sex == 2) $sex_name = '女';
+ else $sex_name = '未知';
$export[] = [
$item['order_id'],
$sex_name,
@@ -253,15 +258,15 @@ HTML;
$item['pay_postage'],
$item['coupon_price'],
$item['pay_type_name'],
- $item['pay_time'] > 0 ? date('Y/m-d H:i',$item['pay_time']) : '暂无',
+ $item['pay_time'] > 0 ? date('Y/m-d H:i', $item['pay_time']) : '暂无',
$item['status_name'],
$item['add_time'],
$item['mark']
];
}
- PHPExcelService::setExcelHeader(['订单号','性别','电话','收货人姓名','收货人电话','收货地址','商品信息',
- '总价格','实际支付','邮费','优惠金额','支付状态','支付时间','订单状态','下单时间','用户备注'])
- ->setExcelTile('订单导出'.date('YmdHis',time()),'订单信息'.time(),' 生成时间:'.date('Y-m-d H:i:s',time()))
+ PHPExcelService::setExcelHeader(['订单号', '性别', '电话', '收货人姓名', '收货人电话', '收货地址', '商品信息',
+ '总价格', '实际支付', '邮费', '优惠金额', '支付状态', '支付时间', '订单状态', '下单时间', '用户备注'])
+ ->setExcelTile('订单导出' . date('YmdHis', time()), '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
->setExcelContent($export)
->ExcelSave();
}
@@ -270,64 +275,65 @@ HTML;
* @param $where
* @return array
*/
- public static function systemPage($where,$userid=false){
- $model = self::getOrderWhere($where,self::alias('a')->join('user r','r.uid=a.uid','LEFT'),'a.','r')->field('a.*,r.nickname');
- if($where['order']){
- $model = $model->order('a.'.$where['order']);
- }else{
+ public static function systemPage($where, $userid = false)
+ {
+ $model = self::getOrderWhere($where, self::alias('a')->join('user r', 'r.uid=a.uid', 'LEFT'), 'a.', 'r')->field('a.*,r.nickname');
+ if ($where['order']) {
+ $model = $model->order('a.' . $where['order']);
+ } else {
$model = $model->order('a.id desc');
}
- if($where['export'] == 1){
+ if ($where['export'] == 1) {
$list = $model->select()->toArray();
$export = [];
- foreach ($list as $index=>$item){
+ foreach ($list as $index => $item) {
- if ($item['pay_type'] == 'weixin'){
+ if ($item['pay_type'] == 'weixin') {
$payType = '微信支付';
- }elseif($item['pay_type'] == 'yue'){
+ } elseif ($item['pay_type'] == 'yue') {
$payType = '余额支付';
- }elseif($item['pay_type'] == 'offline'){
+ } elseif ($item['pay_type'] == 'offline') {
$payType = '线下支付';
- }else{
+ } else {
$payType = '其他支付';
}
- $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->column('cart_info','oid');
+ $_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->column('cart_info', 'oid');
$goodsName = [];
- foreach ($_info as $k=>$v){
- $v = json_decode($v,true);
+ foreach ($_info as $k => $v) {
+ $v = json_decode($v, true);
$goodsName[] = implode(
[$v['productInfo']['store_name'],
- isset($v['productInfo']['attrInfo']) ? '('.$v['productInfo']['attrInfo']['suk'].')' : '',
+ isset($v['productInfo']['attrInfo']) ? '(' . $v['productInfo']['attrInfo']['suk'] . ')' : '',
"[{$v['cart_num']} * {$v['truePrice']}]"
- ],' ');
+ ], ' ');
}
$item['cartInfo'] = $_info;
$export[] = [
- $item['order_id'],$payType,
- $item['total_num'],$item['total_price'],$item['total_postage'],$item['pay_price'],$item['refund_price'],
- $item['mark'],$item['remark'],
- [$item['real_name'],$item['user_phone'],$item['user_address']],
+ $item['order_id'], $payType,
+ $item['total_num'], $item['total_price'], $item['total_postage'], $item['pay_price'], $item['refund_price'],
+ $item['mark'], $item['remark'],
+ [$item['real_name'], $item['user_phone'], $item['user_address']],
$goodsName,
- [$item['paid'] == 1? '已支付':'未支付','支付时间: '.($item['pay_time'] > 0 ? date('Y/md H:i',$item['pay_time']) : '暂无')]
+ [$item['paid'] == 1 ? '已支付' : '未支付', '支付时间: ' . ($item['pay_time'] > 0 ? date('Y/md H:i', $item['pay_time']) : '暂无')]
];
$list[$index] = $item;
}
- PHPExcelService::setExcelHeader(['订单号','支付方式','商品总数','商品总价','邮费','支付金额','退款金额','用户备注','管理员备注','收货人信息','商品信息','支付状态'])
- ->setExcelTile('订单导出','订单信息'.time(),' 生成时间:'.date('Y-m-d H:i:s',time()))
+ PHPExcelService::setExcelHeader(['订单号', '支付方式', '商品总数', '商品总价', '邮费', '支付金额', '退款金额', '用户备注', '管理员备注', '收货人信息', '商品信息', '支付状态'])
+ ->setExcelTile('订单导出', '订单信息' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
->setExcelContent($export)
->ExcelSave();
}
- return self::page($model,function ($item){
- $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select();
- foreach ($_info as $k=>$v){
- $_info[$k]['cart_info'] = json_decode($v['cart_info'],true);
+ return self::page($model, function ($item) {
+ $_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->field('cart_info')->select();
+ foreach ($_info as $k => $v) {
+ $_info[$k]['cart_info'] = json_decode($v['cart_info'], true);
}
$item['_info'] = $_info;
- if($item['pink_id'] && $item['combination_id']){
- $pinkStatus = StorePink::where('order_id_key',$item['id'])->value('status');
- switch ($pinkStatus){
+ if ($item['pink_id'] && $item['combination_id']) {
+ $pinkStatus = StorePink::where('order_id_key', $item['id'])->value('status');
+ switch ($pinkStatus) {
case 1:
$item['pink_name'] = '[拼团订单]正在进行中';
$item['color'] = '#f00';
@@ -345,65 +351,65 @@ HTML;
$item['color'] = '#457856';
break;
}
- }else{
- if($item['seckill_id']){
- $item['pink_name'] = '[秒杀订单]';
- $item['color'] = '#32c5e9';
- }elseif ($item['bargain_id']){
- $item['pink_name'] = '[砍价订单]';
- $item['color'] = '#12c5e9';
- }else{
- $item['pink_name'] = '[普通订单]';
- $item['color'] = '#895612';
- }
+ } else {
+ if ($item['seckill_id']) {
+ $item['pink_name'] = '[秒杀订单]';
+ $item['color'] = '#32c5e9';
+ } elseif ($item['bargain_id']) {
+ $item['pink_name'] = '[砍价订单]';
+ $item['color'] = '#12c5e9';
+ } else {
+ $item['pink_name'] = '[普通订单]';
+ $item['color'] = '#895612';
+ }
}
- },$where);
+ }, $where);
}
- public static function statusByWhere($status,$model = null,$alert='')
+ public static function statusByWhere($status, $model = null, $alert = '')
{
- if($model == null) $model = new self;
- if('' === $status)
+ if ($model == null) $model = new self;
+ if ('' === $status)
return $model;
- else if($status == 8)
+ else if ($status == 8)
return $model;
- else if($status == 0)//未支付
- return $model->where($alert.'paid',0)->where($alert.'status',0)->where($alert.'refund_status',0)->where($alert.'is_del',0);
- else if($status == 1)//已支付 未发货
- return $model->where($alert.'paid',1)->where($alert.'status',0)->where($alert.'shipping_type',1)->where($alert.'refund_status',0)->where($alert.'is_del',0);
- else if($status == 2)//已支付 待收货
- return $model->where($alert.'paid',1)->where($alert.'status',1)->where($alert.'shipping_type',1)->where($alert.'refund_status',0)->where($alert.'is_del',0);
- else if($status == 5)//已支付 待核销
- return $model->where($alert.'paid',1)->where($alert.'status',0)->where($alert.'shipping_type',2)->where($alert.'refund_status',0)->where($alert.'is_del',0);
- else if($status == 3)// 已支付 已收货 待评价
- return $model->where($alert.'paid',1)->where($alert.'status',2)->where($alert.'refund_status',0)->where($alert.'is_del',0);
- else if($status == 4)// 交易完成
- return $model->where($alert.'paid',1)->where($alert.'status',3)->where($alert.'refund_status',0)->where($alert.'is_del',0);
- else if($status == -1)//退款中
- return $model->where($alert.'paid',1)->where($alert.'refund_status',1)->where($alert.'is_del',0);
- else if($status == -2)//已退款
- return $model->where($alert.'paid',1)->where($alert.'refund_status',2)->where($alert.'is_del',0);
- else if($status == -3)//退款
- return $model->where($alert.'paid',1)->where($alert.'refund_status','in','1,2')->where($alert.'is_del',0);
- else if($status == -4)//已删除
- return $model->where($alert.'is_del',1);
+ else if ($status == 0)//未支付
+ return $model->where($alert . 'paid', 0)->where($alert . 'status', 0)->where($alert . 'refund_status', 0)->where($alert . 'is_del', 0);
+ else if ($status == 1)//已支付 未发货
+ return $model->where($alert . 'paid', 1)->where($alert . 'status', 0)->where($alert . 'shipping_type', 1)->where($alert . 'refund_status', 0)->where($alert . 'is_del', 0);
+ else if ($status == 2)//已支付 待收货
+ return $model->where($alert . 'paid', 1)->where($alert . 'status', 1)->where($alert . 'shipping_type', 1)->where($alert . 'refund_status', 0)->where($alert . 'is_del', 0);
+ else if ($status == 5)//已支付 待核销
+ return $model->where($alert . 'paid', 1)->where($alert . 'status', 0)->where($alert . 'shipping_type', 2)->where($alert . 'refund_status', 0)->where($alert . 'is_del', 0);
+ else if ($status == 3)// 已支付 已收货 待评价
+ return $model->where($alert . 'paid', 1)->where($alert . 'status', 2)->where($alert . 'refund_status', 0)->where($alert . 'is_del', 0);
+ else if ($status == 4)// 交易完成
+ return $model->where($alert . 'paid', 1)->where($alert . 'status', 3)->where($alert . 'refund_status', 0)->where($alert . 'is_del', 0);
+ else if ($status == -1)//退款中
+ return $model->where($alert . 'paid', 1)->where($alert . 'refund_status', 1)->where($alert . 'is_del', 0);
+ else if ($status == -2)//已退款
+ return $model->where($alert . 'paid', 1)->where($alert . 'refund_status', 2)->where($alert . 'is_del', 0);
+ else if ($status == -3)//退款
+ return $model->where($alert . 'paid', 1)->where($alert . 'refund_status', 'in', '1,2')->where($alert . 'is_del', 0);
+ else if ($status == -4)//已删除
+ return $model->where($alert . 'is_del', 1);
else
return $model;
}
- public static function timeQuantumWhere($startTime = null,$endTime = null,$model = null)
+ public static function timeQuantumWhere($startTime = null, $endTime = null, $model = null)
{
- if($model === null) $model = new self;
- if($startTime != null && $endTime != null)
- $model = $model->where('add_time','>',strtotime($startTime))->where('add_time','<',strtotime($endTime));
+ if ($model === null) $model = new self;
+ if ($startTime != null && $endTime != null)
+ $model = $model->where('add_time', '>', strtotime($startTime))->where('add_time', '<', strtotime($endTime));
return $model;
}
public static function changeOrderId($orderId)
{
- $ymd = substr($orderId,2,8);
- $key = substr($orderId,16);
- return 'wx'.$ymd.date('His').$key;
+ $ymd = substr($orderId, 2, 8);
+ $key = substr($orderId, 16);
+ return 'wx' . $ymd . date('His') . $key;
}
/**
@@ -411,12 +417,13 @@ HTML;
* @param $id
* @return $this
*/
- public static function updateOffline($id){
- $count = self::where('id',$id)->count();
- if(!$count) return self::setErrorInfo('订单不存在');
- $count = self::where('id',$id)->where('paid', 0)->count();
- if(!$count) return self::setErrorInfo('订单已支付');
- $res = self::where('id', $id)->update(['paid'=>1,'pay_time'=>time()]);
+ public static function updateOffline($id)
+ {
+ $count = self::where('id', $id)->count();
+ if (!$count) return self::setErrorInfo('订单不存在');
+ $count = self::where('id', $id)->where('paid', 0)->count();
+ if (!$count) return self::setErrorInfo('订单已支付');
+ $res = self::where('id', $id)->update(['paid' => 1, 'pay_time' => time()]);
return $res;
}
@@ -425,16 +432,16 @@ HTML;
* @param $oid
* $oid 订单id key
*/
- public static function refundTemplate($data,$oid)
+ public static function refundTemplate($data, $oid)
{
- $order = self::where('id',$oid)->find();
- WechatTemplateService::sendTemplate(WechatUser::where('uid',$order['uid'])->value('openid'),WechatTemplateService::ORDER_REFUND_STATUS, [
- 'first'=>'亲,您购买的商品已退款,本次退款'.$data['refund_price'].'金额',
- 'keyword1'=>$order['order_id'],
- 'keyword2'=>$order['pay_price'],
- 'keyword3'=>date('Y-m-d H:i:s',$order['add_time']),
- 'remark'=>'点击查看订单详情'
- ],Url::buildUrl('/order/detail/'.$order['order_id'])->suffix('')->domain(true)->build());
+ $order = self::where('id', $oid)->find();
+ WechatTemplateService::sendTemplate(WechatUser::where('uid', $order['uid'])->value('openid'), WechatTemplateService::ORDER_REFUND_STATUS, [
+ 'first' => '亲,您购买的商品已退款,本次退款' . $data['refund_price'] . '金额',
+ 'keyword1' => $order['order_id'],
+ 'keyword2' => $order['pay_price'],
+ 'keyword3' => date('Y-m-d H:i:s', $order['add_time']),
+ 'remark' => '点击查看订单详情'
+ ], Url::buildUrl('/order/detail/' . $order['order_id'])->suffix('')->domain(true)->build());
}
/**
@@ -445,16 +452,10 @@ HTML;
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
- public static function refundRoutineTemplate($oid){
- $order = self::where('id',$oid)->find();
- $data['keyword1'] = $order['order_id'];
- $data['keyword2'] = date('Y-m-d H:i:s',time());
- $data['keyword3'] = $order['pay_price'];
- if($order['pay_type'] == 'yue') $data['keyword4'] = '余额支付';
- else if($order['pay_type'] == 'weixin') $data['keyword4'] = '微信支付';
- else if($order['pay_type'] == 'offline') $data['keyword4'] = '线下支付';
- $data['keyword5'] = '已成功退款';
- return RoutineTemplate::sendOut('ORDER_REFUND_SUCCESS',$order['uid'],$data);
+ public static function refundRoutineTemplate($oid)
+ {
+ $order = self::where('id', $oid)->find();
+ return RoutineTemplate::sendOrderRefundSuccess($order);
}
/**
@@ -463,82 +464,87 @@ HTML;
* @param $model
* @return mixed
*/
- public static function getOrderWhere($where,$model,$aler='',$join=''){
+ public static function getOrderWhere($where, $model, $aler = '', $join = '')
+ {
// $model = $model->where('combination_id',0);
- $model = $model->where('is_system_del',0);
- if(isset($where['status']) && $where['status'] != '') {
- $model = self::statusByWhere($where['status'],$model,$aler);
+ $model = $model->where('is_system_del', 0);
+ if (isset($where['status']) && $where['status'] != '') {
+ $model = self::statusByWhere($where['status'], $model, $aler);
}
- if(isset($where['is_del']) && $where['is_del'] != '' && $where['is_del'] != -1) $model = $model->where($aler.'is_del',$where['is_del']);
- if(isset($where['combination_id'])){
- if($where['combination_id'] =='普通订单'){
- $model = $model->where($aler.'combination_id',0)->where($aler.'seckill_id',0)->where($aler.'bargain_id',0);
+ if (isset($where['is_del']) && $where['is_del'] != '' && $where['is_del'] != -1) $model = $model->where($aler . 'is_del', $where['is_del']);
+ if (isset($where['combination_id'])) {
+ if ($where['combination_id'] == '普通订单') {
+ $model = $model->where($aler . 'combination_id', 0)->where($aler . 'seckill_id', 0)->where($aler . 'bargain_id', 0);
}
- if($where['combination_id'] =='拼团订单'){
- $model = $model->where($aler.'combination_id',">",0)->where($aler.'pink_id',">",0);
+ if ($where['combination_id'] == '拼团订单') {
+ $model = $model->where($aler . 'combination_id', ">", 0)->where($aler . 'pink_id', ">", 0);
}
- if($where['combination_id'] =='秒杀订单'){
- $model = $model->where($aler.'seckill_id',">",0);
+ if ($where['combination_id'] == '秒杀订单') {
+ $model = $model->where($aler . 'seckill_id', ">", 0);
}
- if($where['combination_id'] =='砍价订单'){
- $model = $model->where($aler.'bargain_id',">",0);
+ if ($where['combination_id'] == '砍价订单') {
+ $model = $model->where($aler . 'bargain_id', ">", 0);
}
}
- if(isset($where['pay_type'])){
- switch ($where['pay_type']){
+ if (isset($where['pay_type'])) {
+ switch ($where['pay_type']) {
case 1:
- $model = $model->where($aler.'pay_type','weixin');
+ $model = $model->where($aler . 'pay_type', 'weixin');
break;
case 2:
- $model = $model->where($aler.'pay_type','yue');
+ $model = $model->where($aler . 'pay_type', 'yue');
break;
case 3:
- $model = $model->where($aler.'pay_type','offline');
+ $model = $model->where($aler . 'pay_type', 'offline');
break;
}
}
- if(isset($where['type'])){
- switch ($where['type']){
+ if (isset($where['type'])) {
+ switch ($where['type']) {
case 1:
- $model = $model->where($aler.'combination_id',0)->where($aler.'seckill_id',0)->where($aler.'bargain_id',0);
+ $model = $model->where($aler . 'combination_id', 0)->where($aler . 'seckill_id', 0)->where($aler . 'bargain_id', 0);
break;
case 2:
// $model = $model->where($aler.'combination_id',">",0)->where($aler.'pink_id',">",0);
- $model = $model->where($aler.'combination_id',">",0);
+ $model = $model->where($aler . 'combination_id', ">", 0);
break;
case 3:
- $model = $model->where($aler.'seckill_id',">",0);
+ $model = $model->where($aler . 'seckill_id', ">", 0);
break;
case 4:
- $model = $model->where($aler.'bargain_id',">",0);
+ $model = $model->where($aler . 'bargain_id', ">", 0);
break;
}
}
- if(isset($where['real_name']) && $where['real_name'] != ''){
- $model = $model->where($aler.'order_id|'.$aler.'real_name|'.$aler.'user_phone'.($join ? '|'.$join.'.nickname|'.$join.'.uid|'.$join.'.phone':''),'LIKE',"%$where[real_name]%");
+ if (isset($where['real_name']) && $where['real_name'] != '') {
+ $model = $model->where($aler . 'order_id|' . $aler . 'real_name|' . $aler . 'user_phone' . ($join ? '|' . $join . '.nickname|' . $join . '.uid|' . $join . '.phone' : ''), 'LIKE', "%$where[real_name]%");
}
- if(isset($where['data']) && $where['data'] !== ''){
- switch ($where['data']){
- case 'today':case 'week':case 'month':case 'year':case 'yesterday':
- $model=$model->whereTime($aler.'add_time',$where['data']);
- break;
+ if (isset($where['data']) && $where['data'] !== '') {
+ switch ($where['data']) {
+ case 'today':
+ case 'week':
+ case 'month':
+ case 'year':
+ case 'yesterday':
+ $model = $model->whereTime($aler . 'add_time', $where['data']);
+ break;
case 'quarter':
- list($startTime,$endTime)=self::getMonth();
- $model = $model->where($aler.'add_time', '>', strtotime($startTime));
- $model = $model->where($aler.'add_time', '<', strtotime($endTime));
+ list($startTime, $endTime) = self::getMonth();
+ $model = $model->where($aler . 'add_time', '>', strtotime($startTime));
+ $model = $model->where($aler . 'add_time', '<', strtotime($endTime));
break;
case 'lately7':
- $model = $model->where($aler.'add_time','between',[strtotime("-7 day"),time()]);
+ $model = $model->where($aler . 'add_time', 'between', [strtotime("-7 day"), time()]);
break;
case 'lately30':
- $model = $model->where($aler.'add_time','between',[strtotime("-30 day"),time()]);
+ $model = $model->where($aler . 'add_time', 'between', [strtotime("-30 day"), time()]);
break;
default:
- if(strstr($where['data'],' - ')!==false){
+ if (strstr($where['data'], ' - ') !== false) {
list($startTime, $endTime) = explode(' - ', $where['data']);
- $model = $model->where($aler.'add_time', '>', strtotime($startTime));
- $model = $model->where($aler.'add_time', '<', (int)bcadd(strtotime($endTime), 86400, 0));
+ $model = $model->where($aler . 'add_time', '>', strtotime($startTime));
+ $model = $model->where($aler . 'add_time', '<', (int)bcadd(strtotime($endTime), 86400, 0));
}
break;
}
@@ -546,94 +552,98 @@ HTML;
}
return $model;
}
- public static function getBadge($where){
- $price=self::getOrderPrice($where);
+
+ public static function getBadge($where)
+ {
+ $price = self::getOrderPrice($where);
return [
[
- 'name'=>'订单数量',
- 'field'=>'件',
- 'count'=>$price['count_sum'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '订单数量',
+ 'field' => '件',
+ 'count' => $price['count_sum'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'售出商品',
- 'field'=>'件',
- 'count'=>$price['total_num'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '售出商品',
+ 'field' => '件',
+ 'count' => $price['total_num'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'订单金额',
- 'field'=>'元',
- 'count'=>$price['pay_price'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '订单金额',
+ 'field' => '元',
+ 'count' => $price['pay_price'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'退款金额',
- 'field'=>'元',
- 'count'=>$price['refund_price'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '退款金额',
+ 'field' => '元',
+ 'count' => $price['refund_price'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'微信支付金额',
- 'field'=>'元',
- 'count'=>$price['pay_price_wx'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '微信支付金额',
+ 'field' => '元',
+ 'count' => $price['pay_price_wx'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'余额支付金额',
- 'field'=>'元',
- 'count'=>$price['pay_price_yue'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '余额支付金额',
+ 'field' => '元',
+ 'count' => $price['pay_price_yue'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'运费金额',
- 'field'=>'元',
- 'count'=>$price['pay_postage'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '运费金额',
+ 'field' => '元',
+ 'count' => $price['pay_postage'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'分佣金额',
- 'field'=>'元',
- 'count'=>$price['brokerage'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '分佣金额',
+ 'field' => '元',
+ 'count' => $price['brokerage'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'线下支付金额',
- 'field'=>'元',
- 'count'=>$price['pay_price_offline'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '线下支付金额',
+ 'field' => '元',
+ 'count' => $price['pay_price_offline'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'积分抵扣',
- 'field'=>'分',
- 'count'=>$price['use_integral'].'(抵扣金额:¥'.$price['deduction_price'].')',
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '积分抵扣',
+ 'field' => '分',
+ 'count' => $price['use_integral'] . '(抵扣金额:¥' . $price['deduction_price'] . ')',
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
],
[
- 'name'=>'退回积分',
- 'field'=>'元',
- 'count'=>$price['back_integral'],
- 'background_color'=>'layui-bg-blue',
- 'col'=>2
+ 'name' => '退回积分',
+ 'field' => '元',
+ 'count' => $price['back_integral'],
+ 'background_color' => 'layui-bg-blue',
+ 'col' => 2
]
];
}
+
/**
* 处理订单金额
* @param $where
* @return array
*/
- public static function getOrderPrice($where){
+ public static function getOrderPrice($where)
+ {
$where['is_del'] = 0;//删除订单不统计
$model = new self;
$price = array();
@@ -648,19 +658,19 @@ HTML;
$price['deduction_price'] = 0;//抵扣金额
$price['total_num'] = 0; //商品总数
$price['count_sum'] = 0; //商品总数
- $price['brokerage'] =0;
- $price['pay_postage'] =0;
- $whereData=['is_del'=>0];
- if($where['status']==''){
- $whereData['paid']=1;
- $whereData['refund_status']=0;
+ $price['brokerage'] = 0;
+ $price['pay_postage'] = 0;
+ $whereData = ['is_del' => 0];
+ if ($where['status'] == '') {
+ $whereData['paid'] = 1;
+ $whereData['refund_status'] = 0;
}
- $ids= self::getOrderWhere($where,$model)->where($whereData)->column('id');
- if(count($ids)){
- $price['brokerage'] = UserBill::where(['category'=>'now_money','type'=>'brokerage'])->where('link_id','in',$ids)->sum('number');
+ $ids = self::getOrderWhere($where, $model)->where($whereData)->column('id');
+ if (count($ids)) {
+ $price['brokerage'] = UserBill::where(['category' => 'now_money', 'type' => 'brokerage'])->where('link_id', 'in', $ids)->sum('number');
}
- $price['refund_price'] = self::getOrderWhere($where,$model)->where(['is_del'=>0,'paid'=>1,'refund_status'=>2])->sum('refund_price');
- $sumNumber =self::getOrderWhere($where,$model)->where($whereData)->field([
+ $price['refund_price'] = self::getOrderWhere($where, $model)->where(['is_del' => 0, 'paid' => 1, 'refund_status' => 2])->sum('refund_price');
+ $sumNumber = self::getOrderWhere($where, $model)->where($whereData)->field([
'sum(total_num) as sum_total_num',
'count(id) as count_sum',
'sum(pay_price) as sum_pay_price',
@@ -669,7 +679,7 @@ HTML;
'sum(back_integral) as sum_back_integral',
'sum(deduction_price) as sum_deduction_price'
])->find();
- if($sumNumber) {
+ if ($sumNumber) {
$price['count_sum'] = $sumNumber['count_sum'];
$price['total_num'] = $sumNumber['sum_total_num'];
$price['pay_price'] = $sumNumber['sum_pay_price'];
@@ -678,74 +688,75 @@ HTML;
$price['back_integral'] = $sumNumber['sum_back_integral'];
$price['deduction_price'] = $sumNumber['sum_deduction_price'];
}
- $list = self::getOrderWhere($where,$model)->where($whereData)->group('pay_type')->column('sum(pay_price) as sum_pay_price,pay_type','id');
- foreach ($list as $v){
- if ($v['pay_type'] == 'weixin'){
+ $list = self::getOrderWhere($where, $model)->where($whereData)->group('pay_type')->column('sum(pay_price) as sum_pay_price,pay_type', 'id');
+ foreach ($list as $v) {
+ if ($v['pay_type'] == 'weixin') {
$price['pay_price_wx'] = $v['sum_pay_price'];
- }elseif($v['pay_type'] == 'yue'){
+ } elseif ($v['pay_type'] == 'yue') {
$price['pay_price_yue'] = $v['sum_pay_price'];
- }elseif($v['pay_type'] == 'offline'){
+ } elseif ($v['pay_type'] == 'offline') {
$price['pay_price_offline'] = $v['sum_pay_price'];
- }else{
+ } else {
$price['pay_price_other'] = $v['sum_pay_price'];
}
}
return $price;
}
- public static function systemPagePink($where){
+ public static function systemPagePink($where)
+ {
$model = new self;
- $model = self::getOrderWherePink($where,$model);
+ $model = self::getOrderWherePink($where, $model);
$model = $model->order('id desc');
- if($where['export'] == 1){
+ if ($where['export'] == 1) {
$list = $model->select()->toArray();
$export = [];
- foreach ($list as $index=>$item){
+ foreach ($list as $index => $item) {
- if ($item['pay_type'] == 'weixin'){
+ if ($item['pay_type'] == 'weixin') {
$payType = '微信支付';
- }elseif($item['pay_type'] == 'yue'){
+ } elseif ($item['pay_type'] == 'yue') {
$payType = '余额支付';
- }elseif($item['pay_type'] == 'offline'){
+ } elseif ($item['pay_type'] == 'offline') {
$payType = '线下支付';
- }else{
+ } else {
$payType = '其他支付';
}
- $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->column('cart_info','oid');
+ $_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->column('cart_info', 'oid');
$goodsName = [];
- foreach ($_info as $k=>$v){
- $v = json_decode($v,true);
+ foreach ($_info as $k => $v) {
+ $v = json_decode($v, true);
$goodsName[] = implode(
[$v['productInfo']['store_name'],
- isset($v['productInfo']['attrInfo']) ? '('.$v['productInfo']['attrInfo']['suk'].')' : '',
+ isset($v['productInfo']['attrInfo']) ? '(' . $v['productInfo']['attrInfo']['suk'] . ')' : '',
"[{$v['cart_num']} * {$v['truePrice']}]"
- ],' ');
+ ], ' ');
}
$item['cartInfo'] = $_info;
$export[] = [
- $item['order_id'],$payType,
- $item['total_num'],$item['total_price'],$item['total_postage'],$item['pay_price'],$item['refund_price'],
- $item['mark'],$item['remark'],
- [$item['real_name'],$item['user_phone'],$item['user_address']],
+ $item['order_id'], $payType,
+ $item['total_num'], $item['total_price'], $item['total_postage'], $item['pay_price'], $item['refund_price'],
+ $item['mark'], $item['remark'],
+ [$item['real_name'], $item['user_phone'], $item['user_address']],
$goodsName,
- [$item['paid'] == 1? '已支付':'未支付','支付时间: '.($item['pay_time'] > 0 ? date('Y/md H:i',$item['pay_time']) : '暂无')]
+ [$item['paid'] == 1 ? '已支付' : '未支付', '支付时间: ' . ($item['pay_time'] > 0 ? date('Y/md H:i', $item['pay_time']) : '暂无')]
];
$list[$index] = $item;
}
- ExportService::exportCsv($export,'订单导出'.time(),['订单号','支付方式','商品总数','商品总价','邮费','支付金额','退款金额','用户备注','管理员备注','收货人信息','商品信息','支付状态']);
+ ExportService::exportCsv($export, '订单导出' . time(), ['订单号', '支付方式', '商品总数', '商品总价', '邮费', '支付金额', '退款金额', '用户备注', '管理员备注', '收货人信息', '商品信息', '支付状态']);
}
- return self::page($model,function ($item){
- $item['nickname'] = WechatUser::where('uid',$item['uid'])->value('nickname');
- $_info = Db::name('store_order_cart_info')->where('oid',$item['id'])->field('cart_info')->select();
- foreach ($_info as $k=>$v){
- $_info[$k]['cart_info'] = json_decode($v['cart_info'],true);
+ return self::page($model, function ($item) {
+ $item['nickname'] = WechatUser::where('uid', $item['uid'])->value('nickname');
+ $_info = Db::name('store_order_cart_info')->where('oid', $item['id'])->field('cart_info')->select();
+ foreach ($_info as $k => $v) {
+ $_info[$k]['cart_info'] = json_decode($v['cart_info'], true);
}
$item['_info'] = $_info;
- },$where);
+ }, $where);
}
/**
@@ -754,17 +765,18 @@ HTML;
* @param $model
* @return mixed
*/
- public static function getOrderWherePink($where,$model){
- $model = $model->where('combination_id','>',0);
- if($where['status'] != '') $model = $model::statusByWhere($where['status']);
+ public static function getOrderWherePink($where, $model)
+ {
+ $model = $model->where('combination_id', '>', 0);
+ if ($where['status'] != '') $model = $model::statusByWhere($where['status']);
// if($where['is_del'] != '' && $where['is_del'] != -1) $model = $model->where('is_del',$where['is_del']);
- if($where['real_name'] != ''){
- $model = $model->where('order_id|real_name|user_phone','LIKE',"%$where[real_name]%");
+ if ($where['real_name'] != '') {
+ $model = $model->where('order_id|real_name|user_phone', 'LIKE', "%$where[real_name]%");
}
- if($where['data'] !== ''){
- list($startTime,$endTime) = explode(' - ',$where['data']);
- $model = $model->where('add_time','>',strtotime($startTime));
- $model = $model->where('add_time','<',strtotime($endTime));
+ if ($where['data'] !== '') {
+ list($startTime, $endTime) = explode(' - ', $where['data']);
+ $model = $model->where('add_time', '>', strtotime($startTime));
+ $model = $model->where('add_time', '<', strtotime($endTime));
}
return $model;
}
@@ -774,7 +786,8 @@ HTML;
* @param $where
* @return array
*/
- public static function getOrderPricePink($where){
+ public static function getOrderPricePink($where)
+ {
$model = new self;
$price = array();
$price['pay_price'] = 0;//支付金额
@@ -787,23 +800,23 @@ HTML;
$price['back_integral'] = 0;//退积分总数
$price['deduction_price'] = 0;//抵扣金额
$price['total_num'] = 0; //商品总数
- $model = self::getOrderWherePink($where,$model);
+ $model = self::getOrderWherePink($where, $model);
$list = $model->select()->toArray();
- foreach ($list as $v){
- $price['total_num'] = bcadd($price['total_num'],$v['total_num'],0);
- $price['pay_price'] = bcadd($price['pay_price'],$v['pay_price'],2);
- $price['refund_price'] = bcadd($price['refund_price'],$v['refund_price'],2);
- $price['use_integral'] = bcadd($price['use_integral'],$v['use_integral'],2);
- $price['back_integral'] = bcadd($price['back_integral'],$v['back_integral'],2);
- $price['deduction_price'] = bcadd($price['deduction_price'],$v['deduction_price'],2);
- if ($v['pay_type'] == 'weixin'){
- $price['pay_price_wx'] = bcadd($price['pay_price_wx'],$v['pay_price'],2);
- }elseif($v['pay_type'] == 'yue'){
- $price['pay_price_yue'] = bcadd($price['pay_price_yue'],$v['pay_price'],2);
- }elseif($v['pay_type'] == 'offline'){
- $price['pay_price_offline'] = bcadd($price['pay_price_offline'],$v['pay_price'],2);
- }else{
- $price['pay_price_other'] = bcadd($price['pay_price_other'],$v['pay_price'],2);
+ foreach ($list as $v) {
+ $price['total_num'] = bcadd($price['total_num'], $v['total_num'], 0);
+ $price['pay_price'] = bcadd($price['pay_price'], $v['pay_price'], 2);
+ $price['refund_price'] = bcadd($price['refund_price'], $v['refund_price'], 2);
+ $price['use_integral'] = bcadd($price['use_integral'], $v['use_integral'], 2);
+ $price['back_integral'] = bcadd($price['back_integral'], $v['back_integral'], 2);
+ $price['deduction_price'] = bcadd($price['deduction_price'], $v['deduction_price'], 2);
+ if ($v['pay_type'] == 'weixin') {
+ $price['pay_price_wx'] = bcadd($price['pay_price_wx'], $v['pay_price'], 2);
+ } elseif ($v['pay_type'] == 'yue') {
+ $price['pay_price_yue'] = bcadd($price['pay_price_yue'], $v['pay_price'], 2);
+ } elseif ($v['pay_type'] == 'offline') {
+ $price['pay_price_offline'] = bcadd($price['pay_price_offline'], $v['pay_price'], 2);
+ } else {
+ $price['pay_price_other'] = bcadd($price['pay_price_other'], $v['pay_price'], 2);
}
}
return $price;
@@ -815,10 +828,11 @@ HTML;
* @param int $day
* @return $this|StoreOrder
*/
- public static function isMainYesterdayCount($preDay = 0,$day = 0){
+ public static function isMainYesterdayCount($preDay = 0, $day = 0)
+ {
$model = new self();
- $model = $model->where('add_time','>',$preDay);
- $model = $model->where('add_time','<',$day);
+ $model = $model->where('add_time', '>', $preDay);
+ $model = $model->where('add_time', '<', $day);
return $model;
}
@@ -827,9 +841,10 @@ HTML;
* @param int $uid
* @return int|string
*/
- public static function getUserCountPay($uid = 0){
- if(!$uid) return 0;
- return self::where('uid',$uid)->where('paid',1)->count();
+ public static function getUserCountPay($uid = 0)
+ {
+ if (!$uid) return 0;
+ return self::where('uid', $uid)->where('paid', 1)->count();
}
/**
@@ -837,229 +852,237 @@ HTML;
* @param array $where
* @return array
*/
- public static function getOneorderList($where){
+ public static function getOneorderList($where)
+ {
return self::where('uid', $where['uid'])
->order('add_time desc')
- ->page((int)$where['page'],(int)$where['limit'])
+ ->page((int)$where['page'], (int)$where['limit'])
->field(['order_id,real_name,total_num,total_price,pay_price,FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,paid,pay_type,pink_id,seckill_id,bargain_id'
])->select()
->toArray();
}
- /*
+
+ /**
* 设置订单统计图搜索
- * $where array 条件
- * return object
+ * @param array $where 条件
+ * @param null $status
+ * @param null $time
+ * @return array
*/
- public static function setEchatWhere($where,$status=null,$time=null){
- $model=self::statusByWhere($where['status']);
- if($status!==null) $where['type']=$status;
- if($time===true) $where['data']='';
- switch ($where['type']){
+ public static function setEchatWhere($where, $status = null, $time = null)
+ {
+ $model = self::statusByWhere($where['status'])->where('is_system_del',0);
+ if ($status !== null) $where['type'] = $status;
+ if ($time === true) $where['data'] = '';
+ switch ($where['type']) {
case 1:
//普通商品
- $model=$model->where('combination_id',0)->where('seckill_id',0)->where('bargain_id',0);
+ $model = $model->where('combination_id', 0)->where('seckill_id', 0)->where('bargain_id', 0);
break;
case 2:
//拼团商品
- $model=$model->where('combination_id',">",0)->where('pink_id',">",0);
+ $model = $model->where('combination_id', ">", 0)->where('pink_id', ">", 0);
break;
case 3:
//秒杀商品
- $model=$model->where('seckill_id',">",0);
+ $model = $model->where('seckill_id', ">", 0);
break;
case 4:
//砍价商品
- $model=$model->where('bargain_id','>',0);
+ $model = $model->where('bargain_id', '>', 0);
break;
}
- return self::getModelTime($where,$model);
+ return self::getModelTime($where, $model);
}
+
/*
* 获取订单数据统计图
* $where array
* $limit int
* return array
*/
- public static function getEchartsOrder($where,$limit=20){
- $orderlist=self::setEchatWhere($where)->field(
+ public static function getEchartsOrder($where, $limit = 20)
+ {
+ $orderlist = self::setEchatWhere($where)->field(
'FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time,sum(total_num) total_num,count(*) count,sum(total_price) total_price,sum(refund_price) refund_price,group_concat(cart_id SEPARATOR "|") cart_ids'
)->group('_add_time')->order('_add_time asc')->select();
- count($orderlist) && $orderlist=$orderlist->toArray();
- $legend=['商品数量','订单数量','订单金额','退款金额'];
- $seriesdata=[
+ count($orderlist) && $orderlist = $orderlist->toArray();
+ $legend = ['商品数量', '订单数量', '订单金额', '退款金额'];
+ $seriesdata = [
[
- 'name'=>$legend[0],
- 'type'=>'line',
- 'data'=>[],
+ 'name' => $legend[0],
+ 'type' => 'line',
+ 'data' => [],
],
[
- 'name'=>$legend[1],
- 'type'=>'line',
- 'data'=>[]
+ 'name' => $legend[1],
+ 'type' => 'line',
+ 'data' => []
],
[
- 'name'=>$legend[2],
- 'type'=>'line',
- 'data'=>[]
+ 'name' => $legend[2],
+ 'type' => 'line',
+ 'data' => []
],
[
- 'name'=>$legend[3],
- 'type'=>'line',
- 'data'=>[]
+ 'name' => $legend[3],
+ 'type' => 'line',
+ 'data' => []
]
];
- $xdata=[];
- $zoom='';
- foreach ($orderlist as $item){
- $xdata[]=$item['_add_time'];
- $seriesdata[0]['data'][]=$item['total_num'];
- $seriesdata[1]['data'][]=$item['count'];
- $seriesdata[2]['data'][]=$item['total_price'];
- $seriesdata[3]['data'][]=$item['refund_price'];
+ $xdata = [];
+ $zoom = '';
+ foreach ($orderlist as $item) {
+ $xdata[] = $item['_add_time'];
+ $seriesdata[0]['data'][] = $item['total_num'];
+ $seriesdata[1]['data'][] = $item['count'];
+ $seriesdata[2]['data'][] = $item['total_price'];
+ $seriesdata[3]['data'][] = $item['refund_price'];
}
- count($xdata) > $limit && $zoom=$xdata[$limit-5];
- $badge=self::getOrderBadge($where);
- $bingpaytype=self::setEchatWhere($where)->group('pay_type')->field('count(*) as count,pay_type')->select();
- count($bingpaytype) && $bingpaytype=$bingpaytype->toArray();
- $bing_xdata=['微信支付','余额支付','其他支付'];
- $color=['#ffcccc','#99cc00','#fd99cc','#669966'];
- $bing_data=[];
- foreach ($bingpaytype as $key=>$item){
- if($item['pay_type']=='weixin'){
- $value['name']=$bing_xdata[0];
- }else if($item['pay_type']=='yue'){
- $value['name']=$bing_xdata[1];
- }else{
- $value['name']=$bing_xdata[2];
+ count($xdata) > $limit && $zoom = $xdata[$limit - 5];
+ $badge = self::getOrderBadge($where);
+ $bingpaytype = self::setEchatWhere($where)->group('pay_type')->field('count(*) as count,pay_type')->select();
+ count($bingpaytype) && $bingpaytype = $bingpaytype->toArray();
+ $bing_xdata = ['微信支付', '余额支付', '其他支付'];
+ $color = ['#ffcccc', '#99cc00', '#fd99cc', '#669966'];
+ $bing_data = [];
+ foreach ($bingpaytype as $key => $item) {
+ if ($item['pay_type'] == 'weixin') {
+ $value['name'] = $bing_xdata[0];
+ } else if ($item['pay_type'] == 'yue') {
+ $value['name'] = $bing_xdata[1];
+ } else {
+ $value['name'] = $bing_xdata[2];
}
- $value['value']=$item['count'];
- $value['itemStyle']['color']=isset($color[$key]) ? $color[$key]:$color[0];
- $bing_data[]=$value;
+ $value['value'] = $item['count'];
+ $value['itemStyle']['color'] = isset($color[$key]) ? $color[$key] : $color[0];
+ $bing_data[] = $value;
}
- return compact('zoom','xdata','seriesdata','badge','legend','bing_data','bing_xdata');
+ return compact('zoom', 'xdata', 'seriesdata', 'badge', 'legend', 'bing_data', 'bing_xdata');
}
- public static function getOrderBadge($where){
+ public static function getOrderBadge($where)
+ {
return [
[
- 'name'=>'拼团订单数量',
- 'field'=>'个',
- 'count'=>self::setEchatWhere($where,2)->count(),
- 'content'=>'拼团总订单数量',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,2,true)->count(),
- 'class'=>'fa fa-line-chart',
- 'col'=>2
+ 'name' => '拼团订单数量',
+ 'field' => '个',
+ 'count' => self::setEchatWhere($where, 2)->count(),
+ 'content' => '拼团总订单数量',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, 2, true)->count(),
+ 'class' => 'fa fa-line-chart',
+ 'col' => 2
],
[
- 'name'=>'砍价订单数量',
- 'field'=>'个',
- 'count'=>self::setEchatWhere($where,4)->count(),
- 'content'=>'砍价总订单数量',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,4,true)->count(),
- 'class'=>'fa fa-line-chart',
- 'col'=>2
+ 'name' => '砍价订单数量',
+ 'field' => '个',
+ 'count' => self::setEchatWhere($where, 4)->count(),
+ 'content' => '砍价总订单数量',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, 4, true)->count(),
+ 'class' => 'fa fa-line-chart',
+ 'col' => 2
],
[
- 'name'=>'秒杀订单数量',
- 'field'=>'个',
- 'count'=>self::setEchatWhere($where,3)->count(),
- 'content'=>'秒杀总订单数量',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,3,true)->count(),
- 'class'=>'fa fa-line-chart',
- 'col'=>2
+ 'name' => '秒杀订单数量',
+ 'field' => '个',
+ 'count' => self::setEchatWhere($where, 3)->count(),
+ 'content' => '秒杀总订单数量',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, 3, true)->count(),
+ 'class' => 'fa fa-line-chart',
+ 'col' => 2
],
[
- 'name'=>'普通订单数量',
- 'field'=>'个',
- 'count'=>self::setEchatWhere($where,1)->count(),
- 'content'=>'普通总订单数量',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,1,true)->count(),
- 'class'=>'fa fa-line-chart',
- 'col'=>2,
+ 'name' => '普通订单数量',
+ 'field' => '个',
+ 'count' => self::setEchatWhere($where, 1)->count(),
+ 'content' => '普通总订单数量',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, 1, true)->count(),
+ 'class' => 'fa fa-line-chart',
+ 'col' => 2,
],
[
- 'name'=>'使用优惠卷金额',
- 'field'=>'元',
- 'count'=>self::setEchatWhere($where)->sum('coupon_price'),
- 'content'=>'普通总订单数量',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,null,true)->sum('coupon_price'),
- 'class'=>'fa fa-line-chart',
- 'col'=>2
+ 'name' => '使用优惠卷金额',
+ 'field' => '元',
+ 'count' => self::setEchatWhere($where)->sum('coupon_price'),
+ 'content' => '普通总订单数量',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, null, true)->sum('coupon_price'),
+ 'class' => 'fa fa-line-chart',
+ 'col' => 2
],
[
- 'name'=>'积分消耗数',
- 'field'=>'个',
- 'count'=>self::setEchatWhere($where)->sum('use_integral'),
- 'content'=>'积分消耗总数',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,null,true)->sum('use_integral'),
- 'class'=>'fa fa-line-chart',
- 'col'=>2
+ 'name' => '积分消耗数',
+ 'field' => '个',
+ 'count' => self::setEchatWhere($where)->sum('use_integral'),
+ 'content' => '积分消耗总数',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, null, true)->sum('use_integral'),
+ 'class' => 'fa fa-line-chart',
+ 'col' => 2
],
[
- 'name'=>'积分抵扣金额',
- 'field'=>'个',
- 'count'=>self::setEchatWhere($where)->sum('deduction_price'),
- 'content'=>'积分抵扣总金额',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,null,true)->sum('deduction_price'),
- 'class'=>'fa fa-money',
- 'col'=>2
+ 'name' => '积分抵扣金额',
+ 'field' => '个',
+ 'count' => self::setEchatWhere($where)->sum('deduction_price'),
+ 'content' => '积分抵扣总金额',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, null, true)->sum('deduction_price'),
+ 'class' => 'fa fa-money',
+ 'col' => 2
],
[
- 'name'=>'在线支付金额',
- 'field'=>'元',
- 'count'=>self::setEchatWhere($where)->where('pay_type','weixin')->sum('pay_price'),
- 'content'=>'在线支付总金额',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,null,true)->where('pay_type','weixin')->sum('pay_price'),
- 'class'=>'fa fa-weixin',
- 'col'=>2
+ 'name' => '在线支付金额',
+ 'field' => '元',
+ 'count' => self::setEchatWhere($where)->where(['paid'=>1,'refund_status'=>0])->where('pay_type', 'weixin')->sum('pay_price'),
+ 'content' => '在线支付总金额',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, null, true)->where(['paid'=>1,'refund_status'=>0])->where('pay_type', 'weixin')->sum('pay_price'),
+ 'class' => 'fa fa-weixin',
+ 'col' => 2
],
[
- 'name'=>'余额支付金额',
- 'field'=>'元',
- 'count'=>self::setEchatWhere($where)->where('pay_type','yue')->sum('pay_price'),
- 'content'=>'余额支付总金额',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,null,true)->where('pay_type','yue')->sum('pay_price'),
- 'class'=>'fa fa-balance-scale',
- 'col'=>2
+ 'name' => '余额支付金额',
+ 'field' => '元',
+ 'count' => self::setEchatWhere($where)->where('pay_type', 'yue')->where(['paid'=>1,'refund_status'=>0])->sum('pay_price'),
+ 'content' => '余额支付总金额',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, null, true)->where(['paid'=>1,'refund_status'=>0])->where('pay_type', 'yue')->sum('pay_price'),
+ 'class' => 'fa fa-balance-scale',
+ 'col' => 2
],
[
- 'name'=>'赚取积分',
- 'field'=>'分',
- 'count'=>self::setEchatWhere($where)->sum('gain_integral'),
- 'content'=>'赚取总积分',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,null,true)->sum('gain_integral'),
- 'class'=>'fa fa-gg-circle',
- 'col'=>2
+ 'name' => '赚取积分',
+ 'field' => '分',
+ 'count' => self::setEchatWhere($where)->sum('gain_integral'),
+ 'content' => '赚取总积分',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, null, true)->sum('gain_integral'),
+ 'class' => 'fa fa-gg-circle',
+ 'col' => 2
],
[
- 'name'=>'交易额',
- 'field'=>'元',
- 'count'=>self::setEchatWhere($where)->sum('pay_price'),
- 'content'=>'总交易额',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,null,true)->sum('pay_price'),
- 'class'=>'fa fa-jpy',
- 'col'=>2
+ 'name' => '交易额',
+ 'field' => '元',
+ 'count' => self::setEchatWhere($where)->where(['paid'=>1,'refund_status'=>0])->sum('pay_price'),
+ 'content' => '总交易额',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, null, true)->where(['paid'=>1,'refund_status'=>0])->sum('pay_price'),
+ 'class' => 'fa fa-jpy',
+ 'col' => 2
],
[
- 'name'=>'订单商品数量',
- 'field'=>'元',
- 'count'=>self::setEchatWhere($where)->sum('total_num'),
- 'content'=>'订单商品总数量',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::setEchatWhere($where,null,true)->sum('total_num'),
- 'class'=>'fa fa-cube',
- 'col'=>2
+ 'name' => '订单商品数量',
+ 'field' => '元',
+ 'count' => self::setEchatWhere($where)->sum('total_num'),
+ 'content' => '订单商品总数量',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::setEchatWhere($where, null, true)->sum('total_num'),
+ 'class' => 'fa fa-cube',
+ 'col' => 2
]
];
}
@@ -1072,37 +1095,37 @@ HTML;
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
- public static function orderPostageAfter($oid,$postageData = [])
+ public static function orderPostageAfter($oid, $postageData = [])
{
- $order = self::where('id',$oid)->find();
- $url = Url::buildUrl('/order/detail/'.$order['order_id'])->suffix('')->domain(true)->build();
+ $order = self::where('id', $oid)->find();
+ $url = Url::buildUrl('/order/detail/' . $order['order_id'])->suffix('')->domain(true)->build();
$group = [
- 'first'=>'亲,您的订单已发货,请注意查收',
- 'remark'=>'点击查看订单详情'
+ 'first' => '亲,您的订单已发货,请注意查收',
+ 'remark' => '点击查看订单详情'
];
- if($postageData['delivery_type'] == 'send'){//送货
+ if ($postageData['delivery_type'] == 'send') {//送货
$goodsName = StoreOrderCartInfo::getProductNameList($order['id']);
- if($order['is_channel'] == 1){
+ if ($order['is_channel'] == 1) {
//小程序送货模版消息
RoutineTemplate::sendOrderPostage($order);
- }else{//公众号
- $openid = WechatUser::where('uid',$order['uid'])->value('openid');
- $group = array_merge($group,[
- 'keyword1'=>$goodsName,
- 'keyword2'=>$order['pay_type'] == 'offline' ? '线下支付' : date('Y/m/d H:i',$order['pay_time']),
- 'keyword3'=>$order['user_address'],
- 'keyword4'=>$postageData['delivery_name'],
- 'keyword5'=>$postageData['delivery_id']
+ } else {//公众号
+ $openid = WechatUser::where('uid', $order['uid'])->value('openid');
+ $group = array_merge($group, [
+ 'keyword1' => $goodsName,
+ 'keyword2' => $order['pay_type'] == 'offline' ? '线下支付' : date('Y/m/d H:i', $order['pay_time']),
+ 'keyword3' => $order['user_address'],
+ 'keyword4' => $postageData['delivery_name'],
+ 'keyword5' => $postageData['delivery_id']
]);
- WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_DELIVER_SUCCESS,$group,$url);
+ WechatTemplateService::sendTemplate($openid, WechatTemplateService::ORDER_DELIVER_SUCCESS, $group, $url);
}
- }else if($postageData['delivery_type'] == 'express') {//发货
+ } else if ($postageData['delivery_type'] == 'express') {//发货
if ($order['is_channel'] == 1) {
//小程序发货模版消息
- RoutineTemplate::sendOrderPostage($order,1);
+ RoutineTemplate::sendOrderPostage($order, 1);
} else {//公众号
- $openid = WechatUser::where('uid',$order['uid'])->value('openid');
+ $openid = WechatUser::where('uid', $order['uid'])->value('openid');
$group = array_merge($group, [
'keyword1' => $order['order_id'],
'keyword2' => $postageData['delivery_name'],
@@ -1120,72 +1143,62 @@ HTML;
public static function orderTakeAfter($order)
{
$title = '';
- $cartInfo = StoreOrderCartInfo::where('oid', $order['id'])->column('cart_info','oid');
+ $cartInfo = StoreOrderCartInfo::where('oid', $order['id'])->column('cart_info', 'oid');
- if(count($cartInfo)){
- foreach ($cartInfo as $key=>&$cart){
- $cart = json_decode($cart,true);
- $title .= $cart['productInfo']['store_name'].',';
+ if (count($cartInfo)) {
+ foreach ($cartInfo as $key => &$cart) {
+ $cart = json_decode($cart, true);
+ $title .= $cart['productInfo']['store_name'] . ',';
}
}
- if(strlen(trim($title)))
- $title = substr($title,0,bcsub(strlen($title),1,0));
- else{
- $cartInfo = StoreCart::alias('a')->where('a.id','in',implode(',',json_decode($order['cart_id'],true)))->find();
- $title = StoreProduct::where('id',$cartInfo['product_id'])->value('store_name');
+ if (strlen(trim($title)))
+ $title = substr($title, 0, bcsub(strlen($title), 1, 0));
+ else {
+ $cartInfo = StoreCart::alias('a')->where('a.id', 'in', implode(',', json_decode($order['cart_id'], true)))->find();
+ $title = StoreProduct::where('id', $cartInfo['product_id'])->value('store_name');
}
- if($order['is_channel'] == 1){//小程序
- RoutineTemplate::sendOut('OREDER_TAKEVER',$order['uid'],[
- 'keyword1'=>$order['order_id'],
- 'keyword2'=>$title,
- 'keyword3'=>$order['pay_price'],
- 'keyword4'=>date('Y-m-d H:i:s',time()),
- ]);
- }else{
- $openid = WechatUser::where('uid',$order['uid'])->value('openid');
- WechatTemplateService::sendTemplate($openid,WechatTemplateService::ORDER_TAKE_SUCCESS,[
- 'first'=>'亲,您的订单已收货',
- 'keyword1'=>$order['order_id'],
- 'keyword2'=>'已收货',
- 'keyword3'=>date('Y-m-d H:i:s',time()),
- 'keyword4'=>$title,
- 'remark'=>'感谢您的光临!'
+ if ($order['is_channel'] == 1) {//小程序
+ RoutineTemplate::sendOrderTakeOver($order, $title);
+ } else {
+ $openid = WechatUser::where('uid', $order['uid'])->value('openid');
+ WechatTemplateService::sendTemplate($openid, WechatTemplateService::ORDER_TAKE_SUCCESS, [
+ 'first' => '亲,您的订单已收货',
+ 'keyword1' => $order['order_id'],
+ 'keyword2' => '已收货',
+ 'keyword3' => date('Y-m-d H:i:s', time()),
+ 'keyword4' => $title,
+ 'remark' => '感谢您的光临!'
]);
}
}
- /*
+ /**
* 不退款发送模板消息
* @param int $id 订单id
* @param array $data 退款详情
* */
- public static function refundNoPrieTemplate($id,$data)
+ public static function refundNoPrieTemplate($id, $data)
{
- $order=self::get($id);
- if($order) return false;
+ $order = self::get($id);
+ if ($order) return false;
//小程序模板消息
- $cartInfo = StoreOrderCartInfo::where('oid', $order['id'])->column('product_id','oid') ?: [];
- $title='';
+ $cartInfo = StoreOrderCartInfo::where('oid', $order['id'])->column('product_id', 'oid') ?: [];
+ $title = '';
foreach ($cartInfo as $k => $productId) {
- $store_name = StoreProduct::where('id',$productId)->value('store_name');
- $title.=$store_name.',';
+ $store_name = StoreProduct::where('id', $productId)->value('store_name');
+ $title .= $store_name . ',';
}
- if($order->is_channel == 1){
- RoutineTemplate::sendOut('ORDER_REFUND_FILE',$order->uid,[
- 'keyword1'=>$order->order_id,
- 'keyword2'=>$title,
- 'keyword3'=>$order->pay_price,
- 'keyword4'=>$data,
- ]);
- }else{
- WechatTemplateService::sendTemplate(WechatUser::where('uid', $order->uid)->value('openid'),WechatTemplateService::ORDER_REFUND_STATUS,[
- 'first'=>'很抱歉您的订单退款失败,失败原因:'.$data,
- 'keyword1'=>$order->order_id,
- 'keyword2'=>$order->pay_price,
- 'keyword3'=>date('Y-m-d H:i:s',time()),
- 'remark'=>'给您带来的不便,请谅解!'
- ],Url::buildUrl('/order/detail/'.$order['order_id'])->suffix('')->domain(true)->build());
+ if ($order->is_channel == 1) {
+ RoutineTemplate::sendOrderRefundFail($order, $title);
+ } else {
+ WechatTemplateService::sendTemplate(WechatUser::where('uid', $order->uid)->value('openid'), WechatTemplateService::ORDER_REFUND_STATUS, [
+ 'first' => '很抱歉您的订单退款失败,失败原因:' . $data,
+ 'keyword1' => $order->order_id,
+ 'keyword2' => $order->pay_price,
+ 'keyword3' => date('Y-m-d H:i:s', time()),
+ 'remark' => '给您带来的不便,请谅解!'
+ ], Url::buildUrl('/order/detail/' . $order['order_id'])->suffix('')->domain(true)->build());
}
}
@@ -1194,17 +1207,20 @@ HTML;
* @param int $uid
* @return int|string
*/
- public static function getOrderCount($uid = 0){
- if(!$uid) return 0;
- return self::where('uid',$uid)->where('paid',1)->where('refund_status',0)->where('status',2)->count();
- }
+ public static function getOrderCount($uid = 0)
+ {
+ if (!$uid) return 0;
+ return self::where('uid', $uid)->where('paid', 1)->where('refund_status', 0)->where('status', 2)->count();
+ }
+
/**
* 获取已支付的订单
* @param int $is_promoter
* @return int|string
*/
- public static function getOrderPayCount($is_promoter = 0){
- return self::where('o.paid',1)->alias('o')->join('User u','u.uid=o.uid')->where('u.is_promoter',$is_promoter)->count();
+ public static function getOrderPayCount($is_promoter = 0)
+ {
+ return self::where('o.paid', 1)->alias('o')->join('User u', 'u.uid=o.uid')->where('u.is_promoter', $is_promoter)->count();
}
/**
@@ -1212,47 +1228,51 @@ HTML;
* @param int $is_promoter
* @return int|string
*/
- public static function getOrderPayMonthCount($is_promoter = 0){
- return self::where('o.paid',1)->alias('o')->whereTime('o.pay_time','last month')->join('User u','u.uid=o.uid')->where('u.is_promoter',$is_promoter)->count();
+ public static function getOrderPayMonthCount($is_promoter = 0)
+ {
+ return self::where('o.paid', 1)->alias('o')->whereTime('o.pay_time', 'last month')->join('User u', 'u.uid=o.uid')->where('u.is_promoter', $is_promoter)->count();
}
/** 订单收货处理积分
* @param $order
* @return bool
*/
- public static function gainUserIntegral($order)
+ public static function gainUserIntegral($order, bool $open = true)
{
- if($order['gain_integral'] > 0){
+ if ($order['gain_integral'] > 0) {
$userInfo = User::get($order['uid']);
- BaseModel::beginTrans();
- $res1 = false != User::where('uid',$userInfo['uid'])->update(['integral'=>bcadd($userInfo['integral'],$order['gain_integral'],2)]);
- $res2 = false != UserBill::income('购买商品赠送积分',$order['uid'],'integral','gain',$order['gain_integral'],$order['id'],bcadd($userInfo['integral'],$order['gain_integral'],2),'购买商品赠送'.floatval($order['gain_integral']).'积分');
+ $open && BaseModel::beginTrans();
+ $integral = bcadd($userInfo['integral'], $order['gain_integral'], 2);
+ $res1 = false != User::where('uid', $userInfo['uid'])->update(['integral' => $integral]);
+ $res2 = false != UserBill::income('购买商品赠送积分', $order['uid'], 'integral', 'gain', $order['gain_integral'], $order['id'], bcadd($userInfo['integral'], $order['gain_integral'], 2), '购买商品赠送' . floatval($order['gain_integral']) . '积分');
$res = $res1 && $res2;
- BaseModel::checkTrans($res);
+ $open && BaseModel::checkTrans($res);
+ RoutineTemplate::sendUserIntegral($order['uid'], $order, $order['gain_integral'], $integral);
return $res;
}
return true;
}
- public static function integralBack($id){
+ public static function integralBack($id)
+ {
$order = self::get($id)->toArray();
- if(!(float)bcsub($order['use_integral'],0,2) && !$order['back_integral']) return true;
- if($order['back_integral'] && !(int)$order['use_integral']) return true;
+ if (!(float)bcsub($order['use_integral'], 0, 2) && !$order['back_integral']) return true;
+ if ($order['back_integral'] && !(int)$order['use_integral']) return true;
BaseModel::beginTrans();
- $data['back_integral'] = bcsub($order['use_integral'],$order['use_integral'],0);
- if(!$data['back_integral']) return true;
+ $data['back_integral'] = bcsub($order['use_integral'], $order['use_integral'], 0);
+ if (!$data['back_integral']) return true;
$data['use_integral'] = 0;
$data['deduction_price'] = 0.00;
$data['pay_price'] = 0.00;
$data['coupon_id'] = 0.00;
$data['coupon_price'] = 0.00;
$res4 = true;
- $integral = User::where('uid',$order['uid'])->value('integral');
- $res1 = User::bcInc($order['uid'],'integral',$data['back_integral'],'uid');
- $res2 = UserBill::income('商品退积分',$order['uid'],'integral','pay_product_integral_back',$data['back_integral'],$order['id'],bcadd($integral,$data['back_integral'],2),'订单退积分'.floatval($data['back_integral']).'积分到用户积分');
- $res3 = self::edit($data,$id);
- if($order['coupon_id']) $res4 = StoreCouponUser::recoverCoupon($order['coupon_id']);
- StoreOrderStatus::setStatus($id,'integral_back','商品退积分:'.$data['back_integral']);
+ $integral = User::where('uid', $order['uid'])->value('integral');
+ $res1 = User::bcInc($order['uid'], 'integral', $data['back_integral'], 'uid');
+ $res2 = UserBill::income('商品退积分', $order['uid'], 'integral', 'pay_product_integral_back', $data['back_integral'], $order['id'], bcadd($integral, $data['back_integral'], 2), '订单退积分' . floatval($data['back_integral']) . '积分到用户积分');
+ $res3 = self::edit($data, $id);
+ if ($order['coupon_id']) $res4 = StoreCouponUser::recoverCoupon($order['coupon_id']);
+ StoreOrderStatus::setStatus($id, 'integral_back', '商品退积分:' . $data['back_integral']);
$res = $res1 && $res2 && $res3 && $res4;
BaseModel::checkTrans($res);
return $res;
@@ -1271,11 +1291,11 @@ HTML;
$where['type'] = '';
$where['order'] = '';
$where['pay_type'] = 1;
- $weixin = self::getOrderWhere($where,new self)->count();
+ $weixin = self::getOrderWhere($where, new self)->count();
$where['pay_type'] = 2;
- $yue = self::getOrderWhere($where,new self)->count();
+ $yue = self::getOrderWhere($where, new self)->count();
$where['pay_type'] = 3;
- $offline = self::getOrderWhere($where,new self)->count();
+ $offline = self::getOrderWhere($where, new self)->count();
return compact('weixin', 'yue', 'offline');
}
}
\ No newline at end of file
diff --git a/crmeb/app/admin/model/user/User.php b/crmeb/app/admin/model/user/User.php
index a5e0946c..3da9dc2e 100644
--- a/crmeb/app/admin/model/user/User.php
+++ b/crmeb/app/admin/model/user/User.php
@@ -43,551 +43,587 @@ class User extends BaseModel
* @param array $uid
* @return float
* */
- public static function getextractPrice($uid,$where=[])
+ public static function getextractPrice($uid, $where = [])
{
- if(is_array($uid)) {
+ if (is_array($uid)) {
if (!count($uid)) return 0;
- }else
+ } else
$uid = [$uid];
- $brokerage= UserBill::getBrokerage($uid,'now_money','brokerage',$where);//获取总佣金
- $recharge = UserBill::getBrokerage($uid,'now_money','recharge',$where);//累计充值
- $extractTotalPrice = UserExtract::userExtractTotalPrice($uid,1,$where);//累计提现
- if($brokerage > $extractTotalPrice) {
- $orderYuePrice = self::getModelTime($where,StoreOrder::where('uid','in',$uid)->where(['is_del'=>0,'paid'=>1]))->sum('pay_price');//余额累计消费
- $systemAdd = UserBill::getBrokerage($uid,'now_money','system_add',$where);//后台添加余额
- $yueCount = bcadd($recharge,$systemAdd,2);// 后台添加余额 + 累计充值 = 非佣金的总金额
- $orderYuePrice = $yueCount > $orderYuePrice ? 0 : bcsub($orderYuePrice,$yueCount,2);// 余额累计消费(使用佣金消费的金额)
- $brokerage = bcsub($brokerage,$extractTotalPrice,2);//减去已提现金额
- $extract_price = UserExtract::userExtractTotalPrice($uid,0,$where);
- $brokerage = $extract_price < $brokerage ? bcsub($brokerage,$extract_price,2) : 0;//减去审核中的提现金额
- $brokerage = $brokerage > $orderYuePrice ? bcsub($brokerage,$orderYuePrice,2) : 0;//减掉余额支付
- }else{
- $brokerage=0;
+ $brokerage = UserBill::getBrokerage($uid, 'now_money', 'brokerage', $where);//获取总佣金
+ $recharge = UserBill::getBrokerage($uid, 'now_money', 'recharge', $where);//累计充值
+ $extractTotalPrice = UserExtract::userExtractTotalPrice($uid, 1, $where);//累计提现
+ if ($brokerage > $extractTotalPrice) {
+ $orderYuePrice = self::getModelTime($where, StoreOrder::where('uid', 'in', $uid)->where(['is_del' => 0, 'paid' => 1]))->sum('pay_price');//余额累计消费
+ $systemAdd = UserBill::getBrokerage($uid, 'now_money', 'system_add', $where);//后台添加余额
+ $yueCount = bcadd($recharge, $systemAdd, 2);// 后台添加余额 + 累计充值 = 非佣金的总金额
+ $orderYuePrice = $yueCount > $orderYuePrice ? 0 : bcsub($orderYuePrice, $yueCount, 2);// 余额累计消费(使用佣金消费的金额)
+ $brokerage = bcsub($brokerage, $extractTotalPrice, 2);//减去已提现金额
+ $extract_price = UserExtract::userExtractTotalPrice($uid, 0, $where);
+ $brokerage = $extract_price < $brokerage ? bcsub($brokerage, $extract_price, 2) : 0;//减去审核中的提现金额
+ $brokerage = $brokerage > $orderYuePrice ? bcsub($brokerage, $orderYuePrice, 2) : 0;//减掉余额支付
+ } else {
+ $brokerage = 0;
}
- $num = (float)bcsub($brokerage,$extractTotalPrice,2);
+ $num = (float)bcsub($brokerage, $extractTotalPrice, 2);
return $num > 0 ? $num : 0;//可提现
}
+
/**
* @param $where
* @return array
*/
- public static function systemPage($where){
+ public static function systemPage($where)
+ {
$model = new self;
- if($where['status'] != '') $model = $model->where('status',$where['status']);
- if($where['is_promoter'] != '') $model = $model->where('is_promoter',$where['is_promoter']);
- if(isset($where['user_type']) && $where['user_type'] != '') $model = $model->where('user_type',$where['user_type']);
- if($where['nickname'] != '') $model = $model->where('nickname|uid','like',"%$where[nickname]%");
+ if ($where['status'] != '') $model = $model->where('status', $where['status']);
+ if ($where['is_promoter'] != '') $model = $model->where('is_promoter', $where['is_promoter']);
+ if (isset($where['user_type']) && $where['user_type'] != '') $model = $model->where('user_type', $where['user_type']);
+ if ($where['nickname'] != '') $model = $model->where('nickname|uid', 'like', "%$where[nickname]%");
$model = $model->order('uid desc');
- return self::page($model,function ($item){
- if($item['spread_uid']){
- $item['spread_uid_nickname'] = self::where('uid',$item['spread_uid'])->value('nickname');
- }else{
+ return self::page($model, function ($item) {
+ if ($item['spread_uid']) {
+ $item['spread_uid_nickname'] = self::where('uid', $item['spread_uid'])->value('nickname');
+ } else {
$item['spread_uid_nickname'] = '无';
}
- },$where);
+ }, $where);
}
+
/*
* 设置搜索条件
*
*/
public static function setWhere($where)
{
- if($where['order']!=''){
- $model=self::order(self::setOrder($where['order']));
- }else{
- $model=self::order('u.uid desc');
+ if ($where['order'] != '') {
+ $model = self::order(self::setOrder($where['order']));
+ } else {
+ $model = self::order('u.uid desc');
}
- if($where['user_time_type'] == 'visitno' && $where['user_time'] != ''){
+ if ($where['user_time_type'] == 'visitno' && $where['user_time'] != '') {
list($startTime, $endTime) = explode(' - ', $where['user_time']);
- $endTime = strtotime($endTime)+24*3600;
- $model = $model->where("u.last_time < ".strtotime($startTime)." OR u.last_time > ".$endTime);
+ $endTime = strtotime($endTime) + 24 * 3600;
+ $model = $model->where("u.last_time < " . strtotime($startTime) . " OR u.last_time > " . $endTime);
}
- if($where['user_time_type'] == 'visit' && $where['user_time'] != ''){
+ if ($where['user_time_type'] == 'visit' && $where['user_time'] != '') {
list($startTime, $endTime) = explode(' - ', $where['user_time']);
$model = $model->where('u.last_time', '>', strtotime($startTime));
- $model = $model->where('u.last_time', '<', strtotime($endTime)+24*3600);
+ $model = $model->where('u.last_time', '<', strtotime($endTime) + 24 * 3600);
}
- if($where['user_time_type'] == 'add_time' && $where['user_time'] != ''){
+ if ($where['user_time_type'] == 'add_time' && $where['user_time'] != '') {
list($startTime, $endTime) = explode(' - ', $where['user_time']);
$model = $model->where('u.add_time', '>', strtotime($startTime));
- $model = $model->where('u.add_time', '<', strtotime($endTime)+24*3600);
+ $model = $model->where('u.add_time', '<', strtotime($endTime) + 24 * 3600);
}
- if($where['pay_count'] !== '') {
- if($where['pay_count'] == '-1') $model = $model->where('pay_count',0);
- else $model = $model->where('pay_count','>',$where['pay_count']);
+ if ($where['pay_count'] !== '') {
+ if ($where['pay_count'] == '-1') $model = $model->where('pay_count', 0);
+ else $model = $model->where('pay_count', '>', $where['pay_count']);
}
- if($where['user_type'] != ''){
- if($where['user_type'] == 'routine') $model = $model->where('w.routine_openid','not null');
- else if($where['user_type'] == 'wechat') $model = $model->where('w.openid','not null');
- else $model = $model->where('u.user_type',$where['user_type']);
+ if ($where['user_type'] != '') {
+ if ($where['user_type'] == 'routine') $model = $model->where('w.routine_openid', 'not null');
+ else if ($where['user_type'] == 'wechat') $model = $model->where('w.openid', 'not null');
+ else $model = $model->where('u.user_type', $where['user_type']);
}
- if($where['country'] != ''){
- if($where['country'] == 'domestic') $model = $model->where('w.country','中国');
- else if($where['country'] == 'abroad') $model = $model->where('w.country','<>','中国');
+ if ($where['country'] != '') {
+ if ($where['country'] == 'domestic') $model = $model->where('w.country', '中国');
+ else if ($where['country'] == 'abroad') $model = $model->where('w.country', '<>', '中国');
}
return $model;
}
+
/**
* 异步获取当前用户 信息
* @param $where
* @return array
*/
- public static function getUserList($where){
- $model = self::setWherePage(self::setWhere($where),$where,['w.sex','w.province','w.city','u.status','u.is_promoter'],['u.nickname','u.uid','u.phone']);
+ public static function getUserList($where)
+ {
+ $model = self::setWherePage(self::setWhere($where), $where, ['w.sex', 'w.province', 'w.city', 'u.status', 'u.is_promoter'], ['u.nickname', 'u.uid', 'u.phone']);
$list = $model->alias('u')
- ->join('WechatUser w','u.uid=w.uid')
+ ->join('WechatUser w', 'u.uid=w.uid')
->field('u.*,w.country,w.province,w.city,w.sex,w.unionid,w.openid,w.routine_openid,w.groupid,w.tagid_list,w.subscribe,w.subscribe_time')
- ->page((int)$where['page'],(int)$where['limit'])
+ ->page((int)$where['page'], (int)$where['limit'])
->select()
- ->each(function ($item){
- $item['add_time']=date('Y-m-d H:i:s',$item['add_time']);
- if($item['last_time']) $item['last_time'] = date('Y-m-d H:i:s',$item['last_time']);//最近一次访问日期
+ ->each(function ($item) {
+ $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
+ if ($item['last_time']) $item['last_time'] = date('Y-m-d H:i:s', $item['last_time']);//最近一次访问日期
else $item['last_time'] = '无访问';//最近一次访问日期
- self::edit(['pay_count'=>StoreOrder::getUserCountPay($item['uid'])],$item['uid']);
+ self::edit(['pay_count' => StoreOrder::getUserCountPay($item['uid'])], $item['uid']);
$item['extract_count_price'] = UserExtract::getUserCountPrice($item['uid']);//累计提现
- if($item['spread_uid']){
- $item['spread_uid_nickname'] = self::where('uid',$item['spread_uid'])->value('nickname').'/'.$item['spread_uid'];
- }else{
+ if ($item['spread_uid']) {
+ $item['spread_uid_nickname'] = self::where('uid', $item['spread_uid'])->value('nickname') . '/' . $item['spread_uid'];
+ } else {
$item['spread_uid_nickname'] = '无';
}
- if($item['openid'] != '' && $item['routine_openid'] != ''){
- $item['user_type']='通用';
- }else if($item['openid'] == '' && $item['routine_openid'] != ''){
- $item['user_type']='小程序';
- }else if($item['openid'] != '' && $item['routine_openid'] == ''){
- $item['user_type']='公众号';
- }else if($item['user_type'] == 'h5') {
+ if ($item['openid'] != '' && $item['routine_openid'] != '') {
+ $item['user_type'] = '通用';
+ } else if ($item['openid'] == '' && $item['routine_openid'] != '') {
+ $item['user_type'] = '小程序';
+ } else if ($item['openid'] != '' && $item['routine_openid'] == '') {
+ $item['user_type'] = '公众号';
+ } else if ($item['user_type'] == 'h5') {
$item['user_type'] = 'H5';
- }else $item['user_type']='其他';
- if($item['sex'] == 1){
- $item['sex']='男';
- }else if($item['sex'] == 2){
- $item['sex']='女';
- }else $item['sex']='保密';
- $item['vip_name']=false;
- $levelinfo=UserLevel::where('uid', $item['uid'])->where('is_del', 0)->order('grade desc')->field('level_id,is_forever,valid_time')->find();
- if($levelinfo){
- if($levelinfo['is_forever']) $item['vip_name']=SystemUserLevel::where('id',$levelinfo['level_id'])->value('name');
- else if(time() > $levelinfo['valid_time']) $item['vip_name']=SystemUserLevel::where('id',$levelinfo['level_id'])->value('name');
+ } else $item['user_type'] = '其他';
+ if ($item['sex'] == 1) {
+ $item['sex'] = '男';
+ } else if ($item['sex'] == 2) {
+ $item['sex'] = '女';
+ } else $item['sex'] = '保密';
+ $item['vip_name'] = false;
+ $levelinfo = UserLevel::where('uid', $item['uid'])->where('level_id',$item['level'])->where('is_del', 0)->order('grade desc')->field('level_id,is_forever,valid_time')->find();
+ if ($levelinfo) {
+ if ($levelinfo['is_forever']) $item['vip_name'] = SystemUserLevel::where('id', $levelinfo['level_id'])->value('name');
+ else if (time() < $levelinfo['valid_time']) $item['vip_name'] = SystemUserLevel::where('id', $levelinfo['level_id'])->value('name');
}
});//->toArray();
- $count=self::setWherePage(self::setWhere($where),$where,['w.sex','w.province','w.city','u.status','u.is_promoter'],['u.nickname','u.uid'])->alias('u')->join('WechatUser w','u.uid=w.uid')->count();
- return ['count'=>$count,'data'=>$list];
+ $count = self::setWherePage(self::setWhere($where), $where, ['w.sex', 'w.province', 'w.city', 'u.status', 'u.is_promoter'], ['u.nickname', 'u.uid'])->alias('u')->join('WechatUser w', 'u.uid=w.uid')->count();
+ return ['count' => $count, 'data' => $list];
}
+
/**
* 修改用户状态
* @param $uids 用户uid
* @param $status 修改状态
* @return array
*/
- public static function destrSyatus($uids,$status){
- if(empty($uids) && !is_array($uids)) return false;
- if($status=='') return false;
+ public static function destrSyatus($uids, $status)
+ {
+ if (empty($uids) && !is_array($uids)) return false;
+ if ($status == '') return false;
self::beginTrans();
- try{
- $res=self::where('uid','in',$uids)->update(['status'=>$status]);
+ try {
+ $res = self::where('uid', 'in', $uids)->update(['status' => $status]);
self::checkTrans($res);
return true;
- }catch (\Exception $e){
+ } catch (\Exception $e) {
self::rollbackTrans();
return Json::fail($e->getMessage());
}
}
+
/*
* 获取某季度,某年某年后的时间戳
*
* self::getMonth('n',1) 获取当前季度的上个季度的时间戳
* self::getMonth('n') 获取当前季度的时间戳
*/
- public static function getMonth($time='',$ceil=0){
- if(empty($time)){
- $firstday = date("Y-m-01",time());
- $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day"));
- }else if($time=='n'){
- if($ceil!=0)
- $season = ceil(date('n') /3)-$ceil;
+ public static function getMonth($time = '', $ceil = 0)
+ {
+ if (empty($time)) {
+ $firstday = date("Y-m-01", time());
+ $lastday = date("Y-m-d", strtotime("$firstday +1 month -1 day"));
+ } else if ($time == 'n') {
+ if ($ceil != 0)
+ $season = ceil(date('n') / 3) - $ceil;
else
- $season = ceil(date('n') /3);
- $firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
- $lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y')));
- }else if($time=='y'){
- $firstday=date('Y-01-01');
- $lastday=date('Y-12-31');
- }else if($time=='h'){
- $firstday = date('Y-m-d', strtotime('this week +'.$ceil.' day')) . ' 00:00:00';
- $lastday = date('Y-m-d', strtotime('this week +'.($ceil+1).' day')) . ' 23:59:59';
+ $season = ceil(date('n') / 3);
+ $firstday = date('Y-m-01', mktime(0, 0, 0, ($season - 1) * 3 + 1, 1, date('Y')));
+ $lastday = date('Y-m-t', mktime(0, 0, 0, $season * 3, 1, date('Y')));
+ } else if ($time == 'y') {
+ $firstday = date('Y-01-01');
+ $lastday = date('Y-12-31');
+ } else if ($time == 'h') {
+ $firstday = date('Y-m-d', strtotime('this week +' . $ceil . ' day')) . ' 00:00:00';
+ $lastday = date('Y-m-d', strtotime('this week +' . ($ceil + 1) . ' day')) . ' 23:59:59';
}
- return array($firstday,$lastday);
+ return array($firstday, $lastday);
}
- public static function getcount(){
+
+ public static function getcount()
+ {
return self::count();
}
+
/*
*获取用户某个时间段的消费信息
*
* reutrn Array || number
*/
- public static function consume($where,$status='',$keep=''){
+ public static function consume($where, $status = '', $keep = '')
+ {
$model = new self;
- $user_id=[];
- if(is_array($where)){
- if($where['is_promoter']!='') $model=$model->where('is_promoter',$where['is_promoter']);
- if($where['status']!='') $model=$model->where('status',$where['status']);
- switch ($where['date']){
- case null:case 'today':case 'week':case 'year':
- if($where['date']==null){
- $where['date']='month';
- }
- if($keep){
- $model=$model->whereTime('add_time',$where['date'])->whereTime('last_time',$where['date']);
- }else{
- $model=$model->whereTime('add_time',$where['date']);
- }
- break;
+ $user_id = [];
+ if (is_array($where)) {
+ if ($where['is_promoter'] != '') $model = $model->where('is_promoter', $where['is_promoter']);
+ if ($where['status'] != '') $model = $model->where('status', $where['status']);
+ switch ($where['date']) {
+ case null:
+ case 'today':
+ case 'week':
+ case 'year':
+ if ($where['date'] == null) {
+ $where['date'] = 'month';
+ }
+ if ($keep) {
+ $model = $model->whereTime('add_time', $where['date'])->whereTime('last_time', $where['date']);
+ } else {
+ $model = $model->whereTime('add_time', $where['date']);
+ }
+ break;
case 'quarter':
- $quarter=self::getMonth('n');
- $startTime=strtotime($quarter[0]);
- $endTime=strtotime($quarter[1]);
- if($keep){
- $model = $model->where('add_time','>',$startTime)->where('add_time','<',$endTime)->where('last_time','>',$startTime)->where('last_time','<',$endTime);
- }else{
- $model = $model->where('add_time','>',$startTime)->where('add_time','<',$endTime);
+ $quarter = self::getMonth('n');
+ $startTime = strtotime($quarter[0]);
+ $endTime = strtotime($quarter[1]);
+ if ($keep) {
+ $model = $model->where('add_time', '>', $startTime)->where('add_time', '<', $endTime)->where('last_time', '>', $startTime)->where('last_time', '<', $endTime);
+ } else {
+ $model = $model->where('add_time', '>', $startTime)->where('add_time', '<', $endTime);
}
break;
default:
//自定义时间
- if(strstr($where['date'],'-')!==FALSE){
- list($startTime,$endTime)=explode('-',$where['date']);
- $model = $model->where('add_time','>',strtotime($startTime))->where('add_time','<',bcadd(strtotime($endTime),86400,0));
- }else{
- $model=$model->whereTime('add_time','month');
+ if (strstr($where['date'], '-') !== FALSE) {
+ list($startTime, $endTime) = explode('-', $where['date']);
+ $model = $model->where('add_time', '>', strtotime($startTime))->where('add_time', '<', bcadd(strtotime($endTime), 86400, 0));
+ } else {
+ $model = $model->whereTime('add_time', 'month');
}
break;
}
- }else{
- if(is_array($status)){
- $model=$model->where('add_time','>',$status[0])->where('add_time','<',$status[1]);
+ } else {
+ if (is_array($status)) {
+ $model = $model->where('add_time', '>', $status[0])->where('add_time', '<', $status[1]);
}
}
- if($keep===true){
+ if ($keep === true) {
return $model->count();
}
- if($status==='default'){
+ if ($status === 'default') {
return $model->group('from_unixtime(add_time,\'%Y-%m-%d\')')->field('count(uid) num,from_unixtime(add_time,\'%Y-%m-%d\') add_time,uid')->select()->toArray();
}
- if($status==='grouping'){
+ if ($status === 'grouping') {
return $model->group('user_type')->field('user_type')->select()->toArray();
}
- $uid=$model->field('uid')->select()->toArray();
- foreach ($uid as $val){
- $user_id[]=$val['uid'];
+ $uid = $model->field('uid')->select()->toArray();
+ foreach ($uid as $val) {
+ $user_id[] = $val['uid'];
}
- if(empty($user_id)){
- $user_id=[0];
+ if (empty($user_id)) {
+ $user_id = [0];
}
- if($status==='xiaofei'){
- $list=UserBill::where('uid','in',$user_id)
+ if ($status === 'xiaofei') {
+ $list = UserBill::where('uid', 'in', $user_id)
->group('type')
->field('sum(number) as top_number,title')
->select()
->toArray();
- $series=[
- 'name'=>isset($list[0]['title'])?$list[0]['title']:'',
- 'type'=>'pie',
- 'radius'=> ['40%', '50%'],
- 'data'=>[]
+ $series = [
+ 'name' => isset($list[0]['title']) ? $list[0]['title'] : '',
+ 'type' => 'pie',
+ 'radius' => ['40%', '50%'],
+ 'data' => []
];
- foreach($list as $key=>$val){
- $series['data'][$key]['value']=$val['top_number'];
- $series['data'][$key]['name']=$val['title'];
+ foreach ($list as $key => $val) {
+ $series['data'][$key]['value'] = $val['top_number'];
+ $series['data'][$key]['name'] = $val['title'];
}
return $series;
- }else if($status==='form'){
- $list=WechatUser::where('uid','in',$user_id)->group('city')->field('count(city) as top_city,city')->limit(0,10)->select()->toArray();
- $count=self::getcount();
- $option=[
- 'legend_date'=>[],
- 'series_date'=>[]
+ } else if ($status === 'form') {
+ $list = WechatUser::where('uid', 'in', $user_id)->group('city')->field('count(city) as top_city,city')->limit(0, 10)->select()->toArray();
+ $count = self::getcount();
+ $option = [
+ 'legend_date' => [],
+ 'series_date' => []
];
- foreach($list as $key=>$val){
- $num=$count!=0?(bcdiv($val['top_city'],$count,2))*100:0;
- $t=['name'=>$num.'% '.(empty($val['city'])?'未知':$val['city']),'icon'=>'circle'];
- $option['legend_date'][$key]=$t;
- $option['series_date'][$key]=['value'=>$num,'name'=>$t['name']];
+ foreach ($list as $key => $val) {
+ $num = $count != 0 ? (bcdiv($val['top_city'], $count, 2)) * 100 : 0;
+ $t = ['name' => $num . '% ' . (empty($val['city']) ? '未知' : $val['city']), 'icon' => 'circle'];
+ $option['legend_date'][$key] = $t;
+ $option['series_date'][$key] = ['value' => $num, 'name' => $t['name']];
}
return $option;
- }else{
- $number=UserBill::where('uid','in',$user_id)->where('type','pay_product')->sum('number');
+ } else {
+ $number = UserBill::where('uid', 'in', $user_id)->where('type', 'pay_product')->sum('number');
return $number;
}
}
+
/*
* 获取 用户某个时间段的钱数或者TOP20排行
*
* return Array || number
*/
- public static function getUserSpend($date,$status=''){
- $model=new self();
- $model=$model->alias('A');
- switch ($date){
- case null:case 'today':case 'week':case 'year':
- if($date==null) $date='month';
- $model=$model->whereTime('A.add_time',$date);
- break;
+ public static function getUserSpend($date, $status = '')
+ {
+ $model = new self();
+ $model = $model->alias('A');
+ switch ($date) {
+ case null:
+ case 'today':
+ case 'week':
+ case 'year':
+ if ($date == null) $date = 'month';
+ $model = $model->whereTime('A.add_time', $date);
+ break;
case 'quarter':
- list($startTime,$endTime)=User::getMonth('n');
- $model = $model->where('A.add_time','>',strtotime($startTime));
- $model = $model->where('A.add_time','<',bcadd(strtotime($endTime),86400,0));
+ list($startTime, $endTime) = User::getMonth('n');
+ $model = $model->where('A.add_time', '>', strtotime($startTime));
+ $model = $model->where('A.add_time', '<', bcadd(strtotime($endTime), 86400, 0));
break;
default:
- list($startTime,$endTime)=explode('-',$date);
- $model = $model->where('A.add_time','>',strtotime($startTime));
- $model = $model->where('A.add_time','<',bcadd(strtotime($endTime),86400,0));
+ list($startTime, $endTime) = explode('-', $date);
+ $model = $model->where('A.add_time', '>', strtotime($startTime));
+ $model = $model->where('A.add_time', '<', bcadd(strtotime($endTime), 86400, 0));
break;
}
- if($status===true){
- return $model->join('user_bill B','B.uid=A.uid')->where('B.type','pay_product')->where('B.pm',0)->sum('B.number');
+ if ($status === true) {
+ return $model->join('user_bill B', 'B.uid=A.uid')->where('B.type', 'pay_product')->where('B.pm', 0)->sum('B.number');
}
- $list=$model->join('user_bill B','B.uid=A.uid')
- ->where('B.type','pay_product')
- ->where('B.pm',0)
+ $list = $model->join('user_bill B', 'B.uid=A.uid')
+ ->where('B.type', 'pay_product')
+ ->where('B.pm', 0)
->field('sum(B.number) as totel_number,A.nickname,A.avatar,A.now_money,A.uid,A.add_time')
->order('totel_number desc')
- ->limit(0,20)
+ ->limit(0, 20)
->select()
->toArray();
- if(!isset($list[0]['totel_number'])){
- $list=[];
+ if (!isset($list[0]['totel_number'])) {
+ $list = [];
}
return $list;
}
+
/*
* 获取 相对于上月或者其他的数据
*
* return Array
*/
- public static function getPostNumber($date,$status=false,$field='A.add_time',$t='消费'){
- $model=new self();
- if(!$status) $model=$model->alias('A');
- switch ($date){
- case null:case 'today':case 'week':case 'year':
- if($date==null) {
- $date='last month';
- $title='相比上月用户'.$t.'增长';
- }
- if($date=='today') {
- $date='yesterday';
- $title='相比昨天用户'.$t.'增长';
- }
- if($date=='week') {
- $date='last week';
- $title='相比上周用户'.$t.'增长';
- }
- if($date=='year') {
- $date='last year';
- $title='相比去年用户'.$t.'增长';
- }
- $model=$model->whereTime($field,$date);
- break;
+ public static function getPostNumber($date, $status = false, $field = 'A.add_time', $t = '消费')
+ {
+ $model = new self();
+ if (!$status) $model = $model->alias('A');
+ switch ($date) {
+ case null:
+ case 'today':
+ case 'week':
+ case 'year':
+ if ($date == null) {
+ $date = 'last month';
+ $title = '相比上月用户' . $t . '增长';
+ }
+ if ($date == 'today') {
+ $date = 'yesterday';
+ $title = '相比昨天用户' . $t . '增长';
+ }
+ if ($date == 'week') {
+ $date = 'last week';
+ $title = '相比上周用户' . $t . '增长';
+ }
+ if ($date == 'year') {
+ $date = 'last year';
+ $title = '相比去年用户' . $t . '增长';
+ }
+ $model = $model->whereTime($field, $date);
+ break;
case 'quarter':
- $title='相比上季度用户'.$t.'增长';
- list($startTime,$endTime)=User::getMonth('n',1);
- $model = $model->where($field,'>',$startTime);
- $model = $model->where($field,'<',$endTime);
+ $title = '相比上季度用户' . $t . '增长';
+ list($startTime, $endTime) = User::getMonth('n', 1);
+ $model = $model->where($field, '>', $startTime);
+ $model = $model->where($field, '<', $endTime);
break;
default:
- list($startTime,$endTime)=explode('-',$date);
- $title='相比'.$startTime.'-'.$endTime.'时间段用户'.$t.'增长';
- $Time=strtotime($endTime)-strtotime($startTime);
- $model = $model->where($field,'>',strtotime($startTime)+$Time);
- $model = $model->where($field,'<',strtotime($endTime)+$Time);
+ list($startTime, $endTime) = explode('-', $date);
+ $title = '相比' . $startTime . '-' . $endTime . '时间段用户' . $t . '增长';
+ $Time = strtotime($endTime) - strtotime($startTime);
+ $model = $model->where($field, '>', strtotime($startTime) + $Time);
+ $model = $model->where($field, '<', strtotime($endTime) + $Time);
break;
}
- if($status){
- return [$model->count(),$title];
+ if ($status) {
+ return [$model->count(), $title];
}
- $number=$model->join('user_bill B','B.uid=A.uid')->where('B.type','pay_product')->where('B.pm',0)->sum('B.number');
- return [$number,$title];
+ $number = $model->join('user_bill B', 'B.uid=A.uid')->where('B.type', 'pay_product')->where('B.pm', 0)->sum('B.number');
+ return [$number, $title];
}
+
//获取用户新增,头部信息
- public static function getBadgeList($where){
- $user_count = self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status'])->count();
- $user_count_old = self::getOldDate($where)->count();
- $store_brokerage_statu = sysConfig('store_brokerage_statu');
- if($store_brokerage_statu == 1)
- $fenxiao = self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status'])->where('spread_uid','<>',0)->count();
+ public static function getBadgeList($where)
+ {
+ $user_count = self::setWherePage(self::getModelTime($where, new self), $where, ['is_promoter', 'status'])->count();
+ $user_count_old = self::getOldDate($where)->count();
+ $store_brokerage_statu = sys_config('store_brokerage_statu');
+ if ($store_brokerage_statu == 1)
+ $fenxiao = self::setWherePage(self::getModelTime($where, new self), $where, ['is_promoter', 'status'])->where('spread_uid', '<>', 0)->count();
else
- $fenxiao = self::count();
- $fenxiao_count = self::getOldDate($where)->where('spread_uid','<>',0)->count();
- $newFemxiao_count = bcsub($fenxiao,$fenxiao_count,0);
- $order_count = bcsub($user_count,$user_count_old,0);
+ $fenxiao = self::count();
+ $fenxiao_count = self::getOldDate($where)->where('spread_uid', '<>', 0)->count();
+ $newFemxiao_count = bcsub($fenxiao, $fenxiao_count, 0);
+ $order_count = bcsub($user_count, $user_count_old, 0);
return [
[
- 'name'=>'会员人数',
- 'field'=>'个',
- 'count'=>$user_count,
- 'content'=>'会员总人数',
- 'background_color'=>'layui-bg-blue',
- 'sum'=>self::count(),
- 'class'=>'fa fa-bar-chart',
+ 'name' => '会员人数',
+ 'field' => '个',
+ 'count' => $user_count,
+ 'content' => '会员总人数',
+ 'background_color' => 'layui-bg-blue',
+ 'sum' => self::count(),
+ 'class' => 'fa fa-bar-chart',
],
[
- 'name'=>'会员增长',
- 'field'=>'个',
- 'count'=>$order_count,
- 'content'=>'会员增长率',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>$user_count_old ? bcdiv($order_count,$user_count_old,2)*100:0,
- 'class'=>'fa fa-line-chart',
+ 'name' => '会员增长',
+ 'field' => '个',
+ 'count' => $order_count,
+ 'content' => '会员增长率',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => $user_count_old ? bcdiv($order_count, $user_count_old, 2) * 100 : 0,
+ 'class' => 'fa fa-line-chart',
],
[
- 'name'=>'分销人数',
- 'field'=>'个',
- 'count'=>$fenxiao,
- 'content'=>'分销总人数',
- 'background_color'=>'layui-bg-green',
- 'sum'=>$store_brokerage_statu == 1 ? self::where('spread_uid','<>',0)->count() : $fenxiao,
- 'class'=>'fa fa-bar-chart',
+ 'name' => '分销人数',
+ 'field' => '个',
+ 'count' => $fenxiao,
+ 'content' => '分销总人数',
+ 'background_color' => 'layui-bg-green',
+ 'sum' => $store_brokerage_statu == 1 ? self::where('spread_uid', '<>', 0)->count() : $fenxiao,
+ 'class' => 'fa fa-bar-chart',
],
[
- 'name'=>'分销增长',
- 'field'=>'个',
- 'count'=>$newFemxiao_count,
- 'content'=>'分销总人数',
- 'background_color'=>'layui-bg-orange',
- 'sum'=>$fenxiao_count ? bcdiv($newFemxiao_count,$fenxiao_count,2)*100:0,
- 'class'=>'fa fa-cube',
+ 'name' => '分销增长',
+ 'field' => '个',
+ 'count' => $newFemxiao_count,
+ 'content' => '分销总人数',
+ 'background_color' => 'layui-bg-orange',
+ 'sum' => $fenxiao_count ? bcdiv($newFemxiao_count, $fenxiao_count, 2) * 100 : 0,
+ 'class' => 'fa fa-cube',
],
];
}
+
/*
* 获取会员增长曲线图和分布图
* $where 查询条件
* $limit 显示条数,是否有滚动条
*/
- public static function getUserChartList($where,$limit=20){
- $list = self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter','status'])
- ->where('add_time','<>',0)
+ public static function getUserChartList($where, $limit = 20)
+ {
+ $list = self::setWherePage(self::getModelTime($where, new self), $where, ['is_promoter', 'status'])
+ ->where('add_time', '<>', 0)
->field('FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time,count(uid) as num')
->order('_add_time asc')
->group('_add_time')
->select();
- count($list) && $list = $list->toArray();
- $seriesdata = [];
- $xdata = [];
- $Zoom = '';
- foreach ($list as $item){
- $seriesdata[] = $item['num'];
- $xdata[] = $item['_add_time'];
- }
- (count($xdata) > $limit) && $Zoom = $xdata[$limit-5];
+ count($list) && $list = $list->toArray();
+ $seriesdata = [];
+ $xdata = [];
+ $Zoom = '';
+ foreach ($list as $item) {
+ $seriesdata[] = $item['num'];
+ $xdata[] = $item['_add_time'];
+ }
+ (count($xdata) > $limit) && $Zoom = $xdata[$limit - 5];
//多次购物会员数量饼状图
- $count = self::setWherePage(self::getModelTime($where,new self),$where,['is_promoter'])->count();
- $user_count = self::setWherePage(self::getModelTime($where,self::alias('a')->join('store_order r','r.uid=a.uid'),'a.add_time'),$where,['is_promoter'])
- ->where('r.paid',1)->count('a.uid');
- $shop_xdata = ['多次购买数量占比','无购买数量占比'];
+ $count = self::setWherePage(self::getModelTime($where, new self), $where, ['is_promoter'])->count();
+ $user_count = self::setWherePage(self::getModelTime($where, self::alias('a')->join('store_order r', 'r.uid=a.uid'), 'a.add_time'), $where, ['is_promoter'])
+ ->where('r.paid', 1)->count('a.uid');
+ $shop_xdata = ['多次购买数量占比', '无购买数量占比'];
$shop_data = [];
- $count >0 && $shop_data = [
+ $count > 0 && $shop_data = [
[
- 'value'=>bcdiv($user_count,$count,2)*100,
- 'name'=>$shop_xdata[0],
- 'itemStyle'=>[
- 'color'=>'#D789FF',
+ 'value' => bcdiv($user_count, $count, 2) * 100,
+ 'name' => $shop_xdata[0],
+ 'itemStyle' => [
+ 'color' => '#D789FF',
]
],
[
- 'value'=>bcdiv($count-$user_count,$count,2)*100,
- 'name'=>$shop_xdata[1],
- 'itemStyle'=>[
- 'color'=>'#7EF0FB',
+ 'value' => bcdiv($count - $user_count, $count, 2) * 100,
+ 'name' => $shop_xdata[1],
+ 'itemStyle' => [
+ 'color' => '#7EF0FB',
]
]
];
- return compact('shop_data','shop_xdata','seriesdata','Zoom');
+ return compact('shop_data', 'shop_xdata', 'seriesdata', 'Zoom');
}
+
//获取$date的前一天或者其他的时间段
- public static function getOldDate($where,$moedls=null){
- $model=$moedls ===null ? self::setWherePage(new self(),$where,['is_promoter','status']) :$moedls;
- switch ($where['data']){
+ public static function getOldDate($where, $moedls = null)
+ {
+ $model = $moedls === null ? self::setWherePage(new self(), $where, ['is_promoter', 'status']) : $moedls;
+ switch ($where['data']) {
case 'today':
- $model=$model->whereTime('add_time','yesterday');
+ $model = $model->whereTime('add_time', 'yesterday');
break;
case 'week':
- $model=$model->whereTime('add_time','last week');
+ $model = $model->whereTime('add_time', 'last week');
break;
case 'month':
- $model=$model->whereTime('add_time','last month');
+ $model = $model->whereTime('add_time', 'last month');
break;
case 'year':
- $model=$model->whereTime('add_time','last year');
+ $model = $model->whereTime('add_time', 'last year');
break;
case 'quarter':
- $time=self::getMonth('n',1);
- $model=$model->where('add_time','between',$time);
+ $time = self::getMonth('n', 1);
+ $model = $model->where('add_time', 'between', $time);
break;
}
return $model;
}
+
//获取用户属性和性别分布图
- public static function getEchartsData($where){
- $model=self::alias('a');
- $data=self::getModelTime($where,$model,'a.add_time')
- ->join('wechat_user r','r.uid=a.uid')
+ public static function getEchartsData($where)
+ {
+ $model = self::alias('a');
+ $data = self::getModelTime($where, $model, 'a.add_time')
+ ->join('wechat_user r', 'r.uid=a.uid')
->group('r.province')
->field('count(r.province) as count,province')
->order('count desc')
->limit(15)
->select();
- if(count($data)) $data=$data->toArray();
- $legdata=[];
- $dataList=[];
- foreach ($data as $value){
- $value['province']=='' && $value['province']='未知省份';
- $legdata[]=$value['province'];
- $dataList[]=$value['count'];
+ if (count($data)) $data = $data->toArray();
+ $legdata = [];
+ $dataList = [];
+ foreach ($data as $value) {
+ $value['province'] == '' && $value['province'] = '未知省份';
+ $legdata[] = $value['province'];
+ $dataList[] = $value['count'];
}
- $model=self::alias('a');
- $sex=self::getModelTime($where,$model,'a.add_time')
- ->join('wechat_user r','r.uid=a.uid')
+ $model = self::alias('a');
+ $sex = self::getModelTime($where, $model, 'a.add_time')
+ ->join('wechat_user r', 'r.uid=a.uid')
->group('r.sex')
->field('count(r.uid) as count,sex')
->order('count desc')
->select();
- if(count($sex)) $sex=$sex->toArray();
- $sexlegdata=['男','女','未知'];
- $sexcount=self::getModelTime($where,new self())->count();
- $sexList=[];
- $color=['#FB7773','#81BCFE','#91F3FE'];
- foreach ($sex as $key=>$item){
- if($item['sex']==1){
- $item_date['name']='男';
- }else if($item['sex']==2){
- $item_date['name']='女';
- }else{
- $item_date['name']='未知性别';
+ if (count($sex)) $sex = $sex->toArray();
+ $sexlegdata = ['男', '女', '未知'];
+ $sexcount = self::getModelTime($where, new self())->count();
+ $sexList = [];
+ $color = ['#FB7773', '#81BCFE', '#91F3FE'];
+ foreach ($sex as $key => $item) {
+ if ($item['sex'] == 1) {
+ $item_date['name'] = '男';
+ } else if ($item['sex'] == 2) {
+ $item_date['name'] = '女';
+ } else {
+ $item_date['name'] = '未知性别';
}
- $item_date['value']=bcdiv($item['count'],$sexcount,2)*100;
- $item_date['itemStyle']['color']=$color[$key];
- $sexList[]=$item_date;
+ $item_date['value'] = bcdiv($item['count'], $sexcount, 2) * 100;
+ $item_date['itemStyle']['color'] = $color[$key];
+ $sexList[] = $item_date;
}
- return compact('sexList','sexlegdata','legdata','dataList');
+ return compact('sexList', 'sexlegdata', 'legdata', 'dataList');
}
+
//获取佣金记录列表
- public static function getCommissionList($where){
+ public static function getCommissionList($where)
+ {
$model = self::setCommissionWhere($where);
- if($where['excel'])
+ if ($where['excel'])
$list = $model->select();
else
- $list = $model->page((int)$where['page'],(int)$where['limit'])->select();
- count($list) && $list=$list->toArray();
- $export=[];
- foreach ($list as &$value){
- $value['ex_price']= Db::name('user_extract')->where('uid', $value['uid'])->sum('extract_price');
- $value['extract_price']= Db::name('user_extract')->where('uid',$value['uid'])->where('status', 1)->sum('extract_price');
- $cashPrice = Db::name('user_extract')->where('uid',$value['uid'])->where('status', 0)->sum('extract_price');
- $value['money'] = bcsub($value['ex_price'],$value['extract_price'],2);
- $value['money'] = bcsub($value['money'],$cashPrice,2);
- $export[]=[
+ $list = $model->page((int)$where['page'], (int)$where['limit'])->select();
+ count($list) && $list = $list->toArray();
+ $export = [];
+ foreach ($list as &$value) {
+ $value['ex_price'] = Db::name('user_extract')->where('uid', $value['uid'])->sum('extract_price');
+ $value['extract_price'] = Db::name('user_extract')->where('uid', $value['uid'])->where('status', 1)->sum('extract_price');
+ $cashPrice = Db::name('user_extract')->where('uid', $value['uid'])->where('status', 0)->sum('extract_price');
+ $value['money'] = bcsub($value['ex_price'], $value['extract_price'], 2);
+ $value['money'] = bcsub($value['money'], $cashPrice, 2);
+ $export[] = [
$value['nickname'],
$value['sum_number'],
$value['now_money'],
@@ -595,30 +631,32 @@ class User extends BaseModel
$value['extract_price'],
];
}
- if($where['excel']){
- PHPExcelService::setExcelHeader(['昵称/姓名','总佣金金额','账户余额','账户佣金','提现到账佣金'])
- ->setExcelTile('拥金记录','拥金记录'.time(),' 生成时间:'.date('Y-m-d H:i:s',time()))
+ if ($where['excel']) {
+ PHPExcelService::setExcelHeader(['昵称/姓名', '总佣金金额', '账户余额', '账户佣金', '提现到账佣金'])
+ ->setExcelTile('拥金记录', '拥金记录' . time(), ' 生成时间:' . date('Y-m-d H:i:s', time()))
->setExcelContent($export)
->ExcelSave();
}
- $count=self::setCommissionWhere($where)->count();
- return ['data'=>$list,'count'=>$count];
+ $count = self::setCommissionWhere($where)->count();
+ return ['data' => $list, 'count' => $count];
}
+
//获取佣金记录列表的查询条件
- public static function setCommissionWhere($where){
- $models=self::setWherePage(self::alias('A'),$where,[],['A.nickname','A.uid'])
- ->join('user_bill B','B.uid=A.uid')
+ public static function setCommissionWhere($where)
+ {
+ $models = self::setWherePage(self::alias('A'), $where, [], ['A.nickname', 'A.uid'])
+ ->join('user_bill B', 'B.uid=A.uid')
->group('A.uid')
->where('B.type', 'brokerage')
->where('B.category', 'now_money')
->field('sum(B.number) as sum_number,A.nickname,A.uid,A.now_money,A.brokerage_price');
- if($where['order']==''){
- $models=$models->order('sum_number desc');
- }else{
- $models=$models->order($where['order']==1 ? 'sum_number desc':'sum_number asc');
+ if ($where['order'] == '') {
+ $models = $models->order('sum_number desc');
+ } else {
+ $models = $models->order($where['order'] == 1 ? 'sum_number desc' : 'sum_number asc');
}
- if($where['price_max']!='' && $where['price_min']!=''){
- $models=$models->where('now_money','between',[$where['price_max'],$where['price_min']]);
+ if ($where['price_max'] != '' && $where['price_min'] != '') {
+ $models = $models->where('now_money', 'between', [$where['price_max'], $where['price_min']]);
}
return $models;
}
@@ -629,70 +667,76 @@ class User extends BaseModel
*/
public static function getUserInfos($uid)
{
- $userInfo = self::where('uid',$uid)->find();
- if(!$userInfo) exception('读取用户信息失败!');
+ $userInfo = self::where('uid', $uid)->find();
+ if (!$userInfo) exception('读取用户信息失败!');
return $userInfo->toArray();
}
//获取某人用户推广信息
- public static function getUserinfo($uid){
- $userinfo=self::where('uid', $uid)->field('nickname,spread_uid,now_money,add_time')->find()->toArray();
+ public static function getUserinfo($uid)
+ {
+ $userinfo = self::where('uid', $uid)->field('nickname,spread_uid,now_money,add_time')->find()->toArray();
$userinfo['number'] = (float)UserBill::where('category', 'now_money')->where('uid', $uid)->where('type', 'brokerage')->sum('number');
- $userinfo['spread_name'] = $userinfo['spread_uid'] ? self::where('uid', $userinfo['spread_uid'])->value('nickname') :'';
+ $userinfo['spread_name'] = $userinfo['spread_uid'] ? self::where('uid', $userinfo['spread_uid'])->value('nickname') : '';
return $userinfo;
}
+
//获取某用户的详细信息
- public static function getUserDetailed($uid){
- $key_field=['real_name','phone','province','city','district','detail','post_code'];
- $Address=($thisAddress= Db::name('user_address')->where('uid', $uid)->where('is_default', 1)->field($key_field)->find()) ?
- $thisAddress :
+ public static function getUserDetailed($uid)
+ {
+ $key_field = ['real_name', 'phone', 'province', 'city', 'district', 'detail', 'post_code'];
+ $Address = ($thisAddress = Db::name('user_address')->where('uid', $uid)->where('is_default', 1)->field($key_field)->find()) ?
+ $thisAddress :
Db::name('user_address')->where('uid', $uid)->field($key_field)->find();
- $UserInfo=self::get($uid);
+ $UserInfo = self::get($uid);
return [
- ['col'=>12,'name'=>'默认收货地址','value'=>$thisAddress ? '收货人:'.$thisAddress['real_name'].'邮编:'.$thisAddress['post_code'].' 收货人电话:'.$thisAddress['phone'].' 地址:'.$thisAddress['province'].' '.$thisAddress['city'].' '.$thisAddress['district'].' '.$thisAddress['detail'] : ''],
+ ['col' => 12, 'name' => '默认收货地址', 'value' => $thisAddress ? '收货人:' . $thisAddress['real_name'] . '邮编:' . $thisAddress['post_code'] . ' 收货人电话:' . $thisAddress['phone'] . ' 地址:' . $thisAddress['province'] . ' ' . $thisAddress['city'] . ' ' . $thisAddress['district'] . ' ' . $thisAddress['detail'] : ''],
// ['name'=>'微信OpenID','value'=>WechatUser::where('uid', $uid)->value('openid'),'col'=>8],
- ['name'=>'手机号码','value'=>$UserInfo['phone']],
+ ['name' => '手机号码', 'value' => $UserInfo['phone']],
// ['name'=>'ID','value'=>$uid],
- ['name'=>'姓名','value'=>''],
- ['name'=>'微信昵称','value'=>$UserInfo['nickname']],
- ['name'=>'邮箱','value'=>''],
- ['name'=>'生日','value'=>''],
- ['name'=>'积分','value'=>$UserInfo['integral']],
- ['name'=>'上级推广人','value'=>$UserInfo['spread_uid'] ? self::where('uid', $UserInfo['spread_uid'])->value('nickname'):''],
- ['name'=>'账户余额','value'=>$UserInfo['now_money']],
- ['name'=>'佣金总收入','value'=>UserBill::where('category','now_money')->where('type', 'brokerage')->where('uid', $uid)->sum('number')],
- ['name'=>'提现总金额','value'=> Db::name('user_extract')->where('uid', $uid)->where('status', 1)->sum('extract_price')],
+ ['name' => '姓名', 'value' => ''],
+ ['name' => '微信昵称', 'value' => $UserInfo['nickname']],
+ ['name' => '邮箱', 'value' => ''],
+ ['name' => '生日', 'value' => ''],
+ ['name' => '积分', 'value' => $UserInfo['integral']],
+ ['name' => '上级推广人', 'value' => $UserInfo['spread_uid'] ? self::where('uid', $UserInfo['spread_uid'])->value('nickname') : ''],
+ ['name' => '账户余额', 'value' => $UserInfo['now_money']],
+ ['name' => '佣金总收入', 'value' => UserBill::where('category', 'now_money')->where('type', 'brokerage')->where('uid', $uid)->sum('number')],
+ ['name' => '提现总金额', 'value' => Db::name('user_extract')->where('uid', $uid)->where('status', 1)->sum('extract_price')],
];
}
+
//获取某用户的订单个数,消费明细
- public static function getHeaderList($uid){
+ public static function getHeaderList($uid)
+ {
return [
[
- 'title'=>'总计订单',
- 'value'=>StoreOrder::where('uid',$uid)->count(),
- 'key'=>'笔',
- 'class'=>'',
+ 'title' => '总计订单',
+ 'value' => StoreOrder::where('uid', $uid)->count(),
+ 'key' => '笔',
+ 'class' => '',
],
[
- 'title'=>'总消费金额',
- 'value'=>StoreOrder::where('uid',$uid)->where('paid', 1)->sum('total_price'),
- 'key'=>'元',
- 'class'=>'',
+ 'title' => '总消费金额',
+ 'value' => StoreOrder::where('uid', $uid)->where('paid', 1)->sum('total_price'),
+ 'key' => '元',
+ 'class' => '',
],
[
- 'title'=>'本月订单',
- 'value'=>StoreOrder::where('uid',$uid)->whereTime('add_time','month')->count(),
- 'key'=>'笔',
- 'class'=>'',
+ 'title' => '本月订单',
+ 'value' => StoreOrder::where('uid', $uid)->whereTime('add_time', 'month')->count(),
+ 'key' => '笔',
+ 'class' => '',
],
[
- 'title'=>'本月消费金额',
- 'value'=>StoreOrder::where('uid',$uid)->where('paid',1)->whereTime('add_time','month')->sum('total_price'),
- 'key'=>'元',
- 'class'=>'',
+ 'title' => '本月消费金额',
+ 'value' => StoreOrder::where('uid', $uid)->where('paid', 1)->whereTime('add_time', 'month')->sum('total_price'),
+ 'key' => '元',
+ 'class' => '',
]
];
}
+
/*
* 获取 会员 订单个数,积分明细,优惠劵明细
*
@@ -700,17 +744,19 @@ class User extends BaseModel
*
* return array
*/
- public static function getCountInfo($uid){
- $order_count=StoreOrder::where('uid',$uid)->count();
- $integral_count=UserBill::where('uid', $uid)->where('category', 'integral')->where('type','in','deduction,system_add')->count();
- $sign_count=UserBill::where('type', 'sign')->where('uid', $uid)->where('category', 'integral')->count();
- $balanceChang_count=UserBill::where('category', 'now_money')->where('uid', $uid)
- ->where('type','in','system_add,pay_product,extract,pay_product_refund,system_sub')
+ public static function getCountInfo($uid)
+ {
+ $order_count = StoreOrder::where('uid', $uid)->count();
+ $integral_count = UserBill::where('uid', $uid)->where('category', 'integral')->where('type', 'in', 'deduction,system_add')->count();
+ $sign_count = UserBill::where('type', 'sign')->where('uid', $uid)->where('category', 'integral')->count();
+ $balanceChang_count = UserBill::where('category', 'now_money')->where('uid', $uid)
+ ->where('type', 'in', 'system_add,pay_product,extract,pay_product_refund,system_sub')
->count();
- $coupon_count=StoreCouponUser::where('uid', $uid)->count();
- $spread_count=self::where('spread_uid', $uid)->count();
- return compact('order_count','integral_count','sign_count','balanceChang_count','coupon_count','spread_count');
+ $coupon_count = StoreCouponUser::where('uid', $uid)->count();
+ $spread_count = self::where('spread_uid', $uid)->count();
+ return compact('order_count', 'integral_count', 'sign_count', 'balanceChang_count', 'coupon_count', 'spread_count');
}
+
/*
* 获取 会员业务的
* 购物会员统计
@@ -722,68 +768,70 @@ class User extends BaseModel
*
* return array
*/
- public static function getUserBusinessChart($where,$limit=20){
+ public static function getUserBusinessChart($where, $limit = 20)
+ {
//获取购物会员人数趋势图
- $list=self::getModelTime($where,self::where('a.status',1)->alias('a')->join('store_order r','r.uid=a.uid'),'a.add_time')
+ $list = self::getModelTime($where, self::where('a.status', 1)->alias('a')->join('store_order r', 'r.uid=a.uid'), 'a.add_time')
->where('r.paid', 1)
->where('a.is_promoter', 0)
- ->where('a.add_time','<>',0)
+ ->where('a.add_time', '<>', 0)
->field('FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time,count(r.uid) as count_user')
->group('_add_time')
->order('_add_time asc')
->select();
- count($list) && $list=$list->toArray();
- $seriesdata=[];
- $xdata=[];
- $zoom='';
- foreach ($list as $item){
- $seriesdata[]=$item['count_user'];
- $xdata[]=$item['_add_time'];
+ count($list) && $list = $list->toArray();
+ $seriesdata = [];
+ $xdata = [];
+ $zoom = '';
+ foreach ($list as $item) {
+ $seriesdata[] = $item['count_user'];
+ $xdata[] = $item['_add_time'];
}
- count($xdata) > $limit && $zoom=$xdata[$limit-5];
+ count($xdata) > $limit && $zoom = $xdata[$limit - 5];
//会员访问量
- $visit=self::getModelTime($where,self::alias('a')->join('store_visit t','t.uid=a.uid'),'t.add_time')
- ->where('a.is_promoter',0)
+ $visit = self::getModelTime($where, self::alias('a')->join('store_visit t', 't.uid=a.uid'), 't.add_time')
+ ->where('a.is_promoter', 0)
->field('FROM_UNIXTIME(t.add_time,"%Y-%m-%d") as _add_time,count(t.uid) as count_user')
->group('_add_time')
->order('_add_time asc')
->select();
- count($visit) && $visit=$visit->toArray();
- $visit_data=[];
- $visit_xdata=[];
- $visit_zoom='';
- foreach ($visit as $item){
- $visit_data[]=$item['count_user'];
- $visit_xdata[]=$item['_add_time'];
+ count($visit) && $visit = $visit->toArray();
+ $visit_data = [];
+ $visit_xdata = [];
+ $visit_zoom = '';
+ foreach ($visit as $item) {
+ $visit_data[] = $item['count_user'];
+ $visit_xdata[] = $item['_add_time'];
}
- count($visit_xdata) > $limit && $visit_zoom=$visit_xdata[$limit-5];
+ count($visit_xdata) > $limit && $visit_zoom = $visit_xdata[$limit - 5];
//多次购物会员数量饼状图
- $count=self::getModelTime($where,self::where('is_promoter',0))->count();
- $user_count=self::getModelTime($where,self::alias('a')->join('store_order r','r.uid=a.uid'),'a.add_time')
- ->where('a.is_promoter',0)
- ->where('r.paid',1)
+ $count = self::getModelTime($where, self::where('is_promoter', 0))->count();
+ $user_count = self::getModelTime($where, self::alias('a')->join('store_order r', 'r.uid=a.uid'), 'a.add_time')
+ ->where('a.is_promoter', 0)
+ ->where('r.paid', 1)
->group('a.uid')
->count();
- $shop_xdata=['多次购买数量占比','无购买数量占比'];
- $shop_data=[];
- $count >0 && $shop_data=[
+ $shop_xdata = ['多次购买数量占比', '无购买数量占比'];
+ $shop_data = [];
+ $count > 0 && $shop_data = [
[
- 'value'=>bcdiv($user_count,$count,2)*100,
- 'name'=>$shop_xdata[0],
- 'itemStyle'=>[
- 'color'=>'#D789FF',
+ 'value' => bcdiv($user_count, $count, 2) * 100,
+ 'name' => $shop_xdata[0],
+ 'itemStyle' => [
+ 'color' => '#D789FF',
]
],
[
- 'value'=>bcdiv($count-$user_count,$count,2)*100,
- 'name'=>$shop_xdata[1],
- 'itemStyle'=>[
- 'color'=>'#7EF0FB',
+ 'value' => bcdiv($count - $user_count, $count, 2) * 100,
+ 'name' => $shop_xdata[1],
+ 'itemStyle' => [
+ 'color' => '#7EF0FB',
]
]
];
- return compact('seriesdata','xdata','zoom','visit_data','visit_xdata','visit_zoom','shop_data','shop_xdata');
+ return compact('seriesdata', 'xdata', 'zoom', 'visit_data', 'visit_xdata', 'visit_zoom', 'shop_data', 'shop_xdata');
}
+
/*
* 获取用户
* 积分排行
@@ -796,28 +844,29 @@ class User extends BaseModel
* $limit 查询多少条
* return array
*/
- public static function getUserTop10List($limit=10,$is_promoter=0){
+ public static function getUserTop10List($limit = 10, $is_promoter = 0)
+ {
//积分排行
- $integral=self::where('status',1)
- ->where('is_promoter',$is_promoter)
+ $integral = self::where('status', 1)
+ ->where('is_promoter', $is_promoter)
->order('integral desc')
->field('nickname,phone,integral,FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time')
->limit($limit)
->select();
- count($integral) && $integral=$integral->toArray();
+ count($integral) && $integral = $integral->toArray();
//会员余额排行榜
- $now_money=self::where('status',1)
- ->where('is_promoter',$is_promoter)
+ $now_money = self::where('status', 1)
+ ->where('is_promoter', $is_promoter)
->order('now_money desc')
->field('nickname,phone,now_money,FROM_UNIXTIME(add_time,"%Y-%m-%d") as add_time')
->limit($limit)
->select();
- count($now_money) && $now_money=$now_money->toArray();
+ count($now_money) && $now_money = $now_money->toArray();
//购物笔数排行榜
$orderPayCount = StoreOrder::getOrderPayCount($is_promoter);
- if($orderPayCount){
- $shopcount=self::alias('a')
- ->join('store_order r','r.uid=a.uid')
+ if ($orderPayCount) {
+ $shopcount = self::alias('a')
+ ->join('store_order r', 'r.uid=a.uid')
->where('r.paid', 1)
->where('a.is_promoter', $is_promoter)
->group('r.uid')
@@ -825,12 +874,12 @@ class User extends BaseModel
->order('sum_count desc')
->limit($limit)
->select();
- }else $shopcount = [];
- count($shopcount) && $shopcount=$shopcount->toArray();
+ } else $shopcount = [];
+ count($shopcount) && $shopcount = $shopcount->toArray();
//购物金额排行榜
- if($orderPayCount){
- $order=self::alias('a')
- ->join('store_order r','r.uid=a.uid')
+ if ($orderPayCount) {
+ $order = self::alias('a')
+ ->join('store_order r', 'r.uid=a.uid')
->where('r.paid', 1)
->where('a.is_promoter', $is_promoter)
->group('r.uid')
@@ -838,26 +887,27 @@ class User extends BaseModel
->order('sum_price desc')
->limit($limit)
->select();
- }else $order = [];
- count($order) && $order=$order->toArray();
+ } else $order = [];
+ count($order) && $order = $order->toArray();
//上月消费排行
$orderPayCount = StoreOrder::getOrderPayMonthCount($is_promoter);
- if($orderPayCount){
- $lastorder=self::alias('a')
- ->join('store_order r','r.uid=a.uid')
+ if ($orderPayCount) {
+ $lastorder = self::alias('a')
+ ->join('store_order r', 'r.uid=a.uid')
->where('r.paid', 1)
->where('a.is_promoter', $is_promoter)
// ->whereTime('r.pay_time','last month')
- ->where('r.pay_time','between',[strtotime(date('Y-m',strtotime('-1 month'))),strtotime(date('Y-m'))])
+ ->where('r.pay_time', 'between', [strtotime(date('Y-m', strtotime('-1 month'))), strtotime(date('Y-m'))])
->group('r.uid')
->field('a.nickname,a.phone,sum(r.pay_price) as sum_price,FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as add_time,r.uid')
->order('sum_price desc')
->limit($limit)
->select();
- }else $lastorder = [];
- count($lastorder) && $lastorder=$lastorder->toArray();
- return compact('integral','now_money','shopcount','order','lastorder');
+ } else $lastorder = [];
+ count($lastorder) && $lastorder = $lastorder->toArray();
+ return compact('integral', 'now_money', 'shopcount', 'order', 'lastorder');
}
+
/*
* 获取 会员业务
* 会员总余额 会员总积分
@@ -865,24 +915,26 @@ class User extends BaseModel
*
* return array
*/
- public static function getUserBusinesHeade($where){
+ public static function getUserBusinesHeade($where)
+ {
return [
[
- 'name'=>'会员总余额',
- 'field'=>'元',
- 'count'=>self::getModelTime($where,self::where('status',1))->sum('now_money'),
- 'background_color'=>'layui-bg-cyan',
- 'col'=>6,
+ 'name' => '会员总余额',
+ 'field' => '元',
+ 'count' => self::getModelTime($where, self::where('status', 1))->sum('now_money'),
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 6,
],
[
- 'name'=>'会员总积分',
- 'field'=>'分',
- 'count'=>self::getModelTime($where,self::where('status',1))->sum('integral'),
- 'background_color'=>'layui-bg-cyan',
- 'col'=>6
+ 'name' => '会员总积分',
+ 'field' => '分',
+ 'count' => self::getModelTime($where, self::where('status', 1))->sum('integral'),
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 6
]
];
}
+
/*
* 分销会员头部信息查询获取
*
@@ -896,79 +948,81 @@ class User extends BaseModel
*
* return array
*/
- public static function getDistributionBadgeList($where){
+ public static function getDistributionBadgeList($where)
+ {
$timeList = [
- 'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]),
- 'week'=>implode(' - ',[
+ 'today' => implode(' - ', [date('Y/m/d'), date('Y/m/d', strtotime('+1 day'))]),
+ 'week' => implode(' - ', [
date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
]),
- 'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]),
- 'quarter'=>implode(' - ',[
- date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01',
- date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y')))
+ 'month' => implode(' - ', [date('Y/m') . '/01', date('Y/m') . '/' . date('t')]),
+ 'quarter' => implode(' - ', [
+ date('Y') . '/' . (ceil((date('n')) / 3) * 3 - 3 + 1) . '/01',
+ date('Y') . '/' . (ceil((date('n')) / 3) * 3) . '/' . date('t', mktime(0, 0, 0, (ceil((date('n')) / 3) * 3), 1, date('Y')))
]),
- 'year'=>implode(' - ',[
- date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day'))
+ 'year' => implode(' - ', [
+ date('Y') . '/01/01', date('Y/m/d', strtotime(date('Y') . '/01/01 + 1year -1 day'))
])
];
- $timeKey = ['today','week','month','quarter','year'];
- if(in_array($where['data'], $timeKey)) $where['data'] = $timeList[$where['data']];
- $uid = self::name('user')->where('status',1)->where('is_promoter',1)->whereOr('spread_uid','<>',0)->column('uid','uid');
+ $timeKey = ['today', 'week', 'month', 'quarter', 'year'];
+ if (in_array($where['data'], $timeKey)) $where['data'] = $timeList[$where['data']];
+ $uid = self::name('user')->where('status', 1)->where('is_promoter', 1)->whereOr('spread_uid', '<>', 0)->column('uid', 'uid');
return [
[
- 'name'=>'分销商总佣金',
- 'field'=>'元',
- 'count'=>count($uid) ? self::getModelTime($where,UserBill::where('category','now_money')->where('type','brokerage'))->where('uid','in',implode(',',$uid))->sum('number') : 0,
- 'background_color'=>'layui-bg-cyan',
- 'col'=>3,
+ 'name' => '分销商总佣金',
+ 'field' => '元',
+ 'count' => count($uid) ? self::getModelTime($where, UserBill::where('category', 'now_money')->where('type', 'brokerage'))->where('uid', 'in', implode(',', $uid))->sum('number') : 0,
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 3,
],
[
- 'name'=>'分销商总佣金余额',
- 'field'=>'元',
- 'count'=>self::getModelTime($where,self::where('status',1)->where('is_promoter',1))->sum('now_money'),
- 'background_color'=>'layui-bg-cyan',
- 'col'=>3,
+ 'name' => '分销商总佣金余额',
+ 'field' => '元',
+ 'count' => self::getModelTime($where, self::where('status', 1)->where('is_promoter', 1))->sum('now_money'),
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 3,
],
[
- 'name'=>'分销商总提现佣金',
- 'field'=>'元',
- 'count'=>self::getModelTime($where,UserExtract::where('status',1))->sum('extract_price'),
- 'background_color'=>'layui-bg-cyan',
- 'col'=>3,
+ 'name' => '分销商总提现佣金',
+ 'field' => '元',
+ 'count' => self::getModelTime($where, UserExtract::where('status', 1))->sum('extract_price'),
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 3,
],
[
- 'name'=>'本月分销商业务佣金',
- 'field'=>'元',
- 'count'=>count($uid) ? self::getModelTime(['data'=>'month'],UserBill::where('category','now_money')->where('type','brokerage'))
- ->where('uid','in',implode(',',$uid))->sum('number') : 0,
- 'background_color'=>'layui-bg-cyan',
- 'col'=>3,
+ 'name' => '本月分销商业务佣金',
+ 'field' => '元',
+ 'count' => count($uid) ? self::getModelTime(['data' => 'month'], UserBill::where('category', 'now_money')->where('type', 'brokerage'))
+ ->where('uid', 'in', implode(',', $uid))->sum('number') : 0,
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 3,
],
[
- 'name'=>'本月分销商佣金提现金额',
- 'field'=>'元',
- 'count'=>count($uid) ? self::getModelTime(['data'=>'month'],UserExtract::where('status',1))
- ->where('uid','in',implode(',',$uid))->sum('extract_price') : 0,
- 'background_color'=>'layui-bg-cyan',
- 'col'=>4,
+ 'name' => '本月分销商佣金提现金额',
+ 'field' => '元',
+ 'count' => count($uid) ? self::getModelTime(['data' => 'month'], UserExtract::where('status', 1))
+ ->where('uid', 'in', implode(',', $uid))->sum('extract_price') : 0,
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 4,
],
[
- 'name'=>'上月分销商业务佣金',
- 'field'=>'元',
- 'count'=>count($uid) ? self::getOldDate(['data'=>'year'],UserBill::where('category','now_money')->where('uid','in',implode(',',$uid))->where('type','brokerage'))->sum('number') : 0,
- 'background_color'=>'layui-bg-cyan',
- 'col'=>4,
+ 'name' => '上月分销商业务佣金',
+ 'field' => '元',
+ 'count' => count($uid) ? self::getOldDate(['data' => 'year'], UserBill::where('category', 'now_money')->where('uid', 'in', implode(',', $uid))->where('type', 'brokerage'))->sum('number') : 0,
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 4,
],
[
- 'name'=>'上月分销商佣金提现金额',
- 'field'=>'元',
- 'count'=>count($uid) ? self::getOldDate(['data'=>'year'],UserBill::where('category','now_money')->where('uid','in',implode(',',$uid))->where('type','brokerage'))->sum('number') : 0,
- 'background_color'=>'layui-bg-cyan',
- 'col'=>4,
+ 'name' => '上月分销商佣金提现金额',
+ 'field' => '元',
+ 'count' => count($uid) ? self::getOldDate(['data' => 'year'], UserBill::where('category', 'now_money')->where('uid', 'in', implode(',', $uid))->where('type', 'brokerage'))->sum('number') : 0,
+ 'background_color' => 'layui-bg-cyan',
+ 'col' => 4,
],
];
}
+
/*
* 分销会员
* 分销数量 饼状图
@@ -979,96 +1033,99 @@ class User extends BaseModel
* $limit int n条数据后出拖动条
* return array
*/
- public static function getUserDistributionChart($where,$limit=20){
+ public static function getUserDistributionChart($where, $limit = 20)
+ {
//分销数量
- $fenbu_user=self::getModelTime($where,new self)->field('count(uid) as num')->group('is_promoter')->select();
- count($fenbu_user) && $fenbu_user=$fenbu_user->toArray();
- $sum_user=0;
- $fenbu_data=[];
- $fenbu_xdata=['分销商','非分销商'];
- $color=['#81BCFE','#91F3FE'];
- foreach($fenbu_user as $item){
- $sum_user+=$item['num'];
+ $fenbu_user = self::getModelTime($where, new self)->field('count(uid) as num')->group('is_promoter')->select();
+ count($fenbu_user) && $fenbu_user = $fenbu_user->toArray();
+ $sum_user = 0;
+ $fenbu_data = [];
+ $fenbu_xdata = ['分销商', '非分销商'];
+ $color = ['#81BCFE', '#91F3FE'];
+ foreach ($fenbu_user as $item) {
+ $sum_user += $item['num'];
}
- foreach ($fenbu_user as $key=>$item){
- $value['value']=bcdiv($item['num'],$sum_user,2)*100;
- $value['name']=isset($fenbu_xdata[$key]) ?$fenbu_xdata[$key].' %'.$value['value'] :'';
- $value['itemStyle']['color']=$color[$key];
- $fenbu_data[]=$value;
+ foreach ($fenbu_user as $key => $item) {
+ $value['value'] = bcdiv($item['num'], $sum_user, 2) * 100;
+ $value['name'] = isset($fenbu_xdata[$key]) ? $fenbu_xdata[$key] . ' %' . $value['value'] : '';
+ $value['itemStyle']['color'] = $color[$key];
+ $fenbu_data[] = $value;
}
//分销商会员访问量
- $visit=self::getModelTime($where,self::alias('a')->join('store_visit t','t.uid=a.uid'),'t.add_time')
- ->where('a.is_promoter',1)
- ->field(['FROM_UNIXTIME(t.add_time,"%Y-%m-%d") as _add_time','count(t.uid) as count_user'])
+ $visit = self::getModelTime($where, self::alias('a')->join('store_visit t', 't.uid=a.uid'), 't.add_time')
+ ->where('a.is_promoter', 1)
+ ->field(['FROM_UNIXTIME(t.add_time,"%Y-%m-%d") as _add_time', 'count(t.uid) as count_user'])
->group('_add_time')
->order('_add_time asc')
->select();
// echo self::getLastSql();die;
- count($visit) && $visit=$visit->toArray();
- $visit_data=[];
- $visit_xdata=[];
- $visit_zoom='';
- foreach ($visit as $item){
- $visit_data[]=$item['count_user'];
- $visit_xdata[]=$item['_add_time'];
+ count($visit) && $visit = $visit->toArray();
+ $visit_data = [];
+ $visit_xdata = [];
+ $visit_zoom = '';
+ foreach ($visit as $item) {
+ $visit_data[] = $item['count_user'];
+ $visit_xdata[] = $item['_add_time'];
}
- count($visit_xdata) > $limit && $visit_zoom=$visit_xdata[$limit-5];
+ count($visit_xdata) > $limit && $visit_zoom = $visit_xdata[$limit - 5];
//获取购物会员人数趋势图
- $list=self::getModelTime($where,self::where('a.status',1)->alias('a')->join('store_order r','r.uid=a.uid'),'a.add_time')
+ $list = self::getModelTime($where, self::where('a.status', 1)->alias('a')->join('store_order r', 'r.uid=a.uid'), 'a.add_time')
->where('r.paid', 1)
->where('a.is_promoter', 1)
- ->where('a.add_time','<>',0)
+ ->where('a.add_time', '<>', 0)
->field('FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time,count(r.uid) as count_user')
->group('_add_time')
->order('_add_time asc')
->select();
- count($list) && $list=$list->toArray();
- $seriesdata=[];
- $xdata=[];
- $zoom='';
- foreach ($list as $item){
- $seriesdata[]=$item['count_user'];
- $xdata[]=$item['_add_time'];
+ count($list) && $list = $list->toArray();
+ $seriesdata = [];
+ $xdata = [];
+ $zoom = '';
+ foreach ($list as $item) {
+ $seriesdata[] = $item['count_user'];
+ $xdata[] = $item['_add_time'];
}
- count($xdata) > $limit && $zoom=$xdata[$limit-5];
+ count($xdata) > $limit && $zoom = $xdata[$limit - 5];
//多次购物分销会员数量饼状图
- $count=self::getModelTime($where,self::where('is_promoter',1))->count();
- $user_count=self::getModelTime($where,self::alias('a')
- ->join('store_order r','r.uid=a.uid'),'a.add_time')
- ->where('a.is_promoter',1)
- ->where('r.paid',1)
+ $count = self::getModelTime($where, self::where('is_promoter', 1))->count();
+ $user_count = self::getModelTime($where, self::alias('a')
+ ->join('store_order r', 'r.uid=a.uid'), 'a.add_time')
+ ->where('a.is_promoter', 1)
+ ->where('r.paid', 1)
->group('a.uid')
->count();
- $shop_xdata=['多次购买数量占比','无购买数量占比'];
- $shop_data=[];
- $count >0 && $shop_data=[
+ $shop_xdata = ['多次购买数量占比', '无购买数量占比'];
+ $shop_data = [];
+ $count > 0 && $shop_data = [
[
- 'value'=>bcdiv($user_count,$count,2)*100,
- 'name'=>$shop_xdata[0].$user_count.'人',
- 'itemStyle'=>[
- 'color'=>'#D789FF',
+ 'value' => bcdiv($user_count, $count, 2) * 100,
+ 'name' => $shop_xdata[0] . $user_count . '人',
+ 'itemStyle' => [
+ 'color' => '#D789FF',
]
],
[
- 'value'=>bcdiv($count-$user_count,$count,2)*100,
- 'name'=>$shop_xdata[1].($count-$user_count).'人',
- 'itemStyle'=>[
- 'color'=>'#7EF0FB',
+ 'value' => bcdiv($count - $user_count, $count, 2) * 100,
+ 'name' => $shop_xdata[1] . ($count - $user_count) . '人',
+ 'itemStyle' => [
+ 'color' => '#7EF0FB',
]
]
];
- return compact('fenbu_data','fenbu_xdata','visit_data','visit_xdata','visit_zoom','seriesdata','xdata','zoom','shop_xdata','shop_data');
+ return compact('fenbu_data', 'fenbu_xdata', 'visit_data', 'visit_xdata', 'visit_zoom', 'seriesdata', 'xdata', 'zoom', 'shop_xdata', 'shop_data');
}
+
/*
* 分销商佣金提现排行榜
* 分销商佣金总额排行榜
* $limit 截取条数
* return array
*/
- public static function getUserDistributionTop10List($limit){
+ public static function getUserDistributionTop10List($limit)
+ {
//分销商佣金提现排行榜
- $extract=self::alias('a')
- ->join('user_extract t','a.uid=t.uid')
+ $extract = self::alias('a')
+ ->join('user_extract t', 'a.uid=t.uid')
->where('t.status', 1)
->where('a.is_promoter', 1)
->group('t.uid')
@@ -1076,11 +1133,11 @@ class User extends BaseModel
->order('sum_price desc')
->limit($limit)
->select();
- count($extract) && $extract=$extract->toArray();
+ count($extract) && $extract = $extract->toArray();
//分销商佣金总额排行榜
- $commission=UserBill::alias('l')
- ->join('user a','l.uid=a.uid')
- ->where('l.status',1)
+ $commission = UserBill::alias('l')
+ ->join('user a', 'l.uid=a.uid')
+ ->where('l.status', 1)
->where('l.category', 'now_money')
->where('l.type', 'brokerage')
->where('a.is_promoter', 1)
@@ -1089,18 +1146,21 @@ class User extends BaseModel
->order('sum_number desc')
->limit($limit)
->select();
- count($commission) && $commission=$commission->toArray();
- return compact('extract','commission');
+ count($commission) && $commission = $commission->toArray();
+ return compact('extract', 'commission');
}
- public static function getSpreadList($uid,$page,$limit){
- $list=self::where('spread_uid', $uid)->field('uid,nickname,now_money,integral,add_time')
- ->order('uid desc')->page((int)$page,(int)$limit)->select();
- count($list) && $list=$list->toArray();
- foreach ($list as &$item){
- $item['add_time']=date('Y-m-d H',$item['add_time']);
+
+ public static function getSpreadList($uid, $page, $limit)
+ {
+ $list = self::where('spread_uid', $uid)->field('uid,nickname,now_money,integral,add_time')
+ ->order('uid desc')->page((int)$page, (int)$limit)->select();
+ count($list) && $list = $list->toArray();
+ foreach ($list as &$item) {
+ $item['add_time'] = date('Y-m-d H', $item['add_time']);
}
return $list;
}
+
/**
* 一级分销
* @param $orderInfo
@@ -1109,27 +1169,27 @@ class User extends BaseModel
public static function backOrderBrokerage($orderInfo)
{
$userInfo = User::getUserInfo($orderInfo['uid']);
- if(!$userInfo || !$userInfo['spread_uid']) return true;
- $storeBrokerageStatu = sysConfig('store_brokerage_statu') ? : 1;//获取后台分销类型
- if($storeBrokerageStatu == 1){
- if(!User::be(['uid'=>$userInfo['spread_uid'],'is_promoter'=>1])) return true;
+ if (!$userInfo || !$userInfo['spread_uid']) return true;
+ $storeBrokerageStatu = sys_config('store_brokerage_statu') ?: 1;//获取后台分销类型
+ if ($storeBrokerageStatu == 1) {
+ if (!User::be(['uid' => $userInfo['spread_uid'], 'is_promoter' => 1])) return true;
}
- $brokerageRatio = (sysConfig('store_brokerage_ratio') ?: 0)/100;
- if($brokerageRatio <= 0) return true;
+ $brokerageRatio = (sys_config('store_brokerage_ratio') ?: 0) / 100;
+ if ($brokerageRatio <= 0) return true;
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
- if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
- $brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
+ if ($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
+ $brokeragePrice = bcmul(bcsub($orderInfo['pay_price'], $cost, 2), $brokerageRatio, 2);
//返佣之后余额
$spNow_money = User::where('uid', $userInfo['spread_uid'])->value('now_money');
- $balance = bcadd($spNow_money,$brokeragePrice,2);
- if($brokeragePrice <= 0) return true;
- $mark = $userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
+ $balance = bcadd($spNow_money, $brokeragePrice, 2);
+ if ($brokeragePrice <= 0) return true;
+ $mark = $userInfo['nickname'] . '成功消费' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokeragePrice);
self::beginTrans();
- $res1 = UserBill::income('获得推广佣金',$userInfo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],$balance,$mark);
- $res2 = self::bcInc($userInfo['spread_uid'],'now_money',$brokeragePrice,'uid');
+ $res1 = UserBill::income('获得推广佣金', $userInfo['spread_uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id'], $balance, $mark);
+ $res2 = self::bcInc($userInfo['spread_uid'], 'now_money', $brokeragePrice, 'uid');
$res = $res1 && $res2;
self::checkTrans($res);
- if($res) self::backOrderBrokerageTwo($orderInfo);
+ if ($res) self::backOrderBrokerageTwo($orderInfo);
return $res;
}
@@ -1138,27 +1198,28 @@ class User extends BaseModel
* @param $orderInfo
* @return bool
*/
- public static function backOrderBrokerageTwo($orderInfo){
+ public static function backOrderBrokerageTwo($orderInfo)
+ {
$userInfo = User::getUserInfo($orderInfo['uid']);
$userInfoTwo = User::getUserInfo($userInfo['spread_uid']);
- if(!$userInfoTwo || !$userInfoTwo['spread_uid']) return true;
- $storeBrokerageStatu = sysConfig('store_brokerage_statu') ? : 1;//获取后台分销类型
- if($storeBrokerageStatu == 1){
- if(!User::be(['uid'=>$userInfoTwo['spread_uid'],'is_promoter'=>1])) return true;
+ if (!$userInfoTwo || !$userInfoTwo['spread_uid']) return true;
+ $storeBrokerageStatu = sys_config('store_brokerage_statu') ?: 1;//获取后台分销类型
+ if ($storeBrokerageStatu == 1) {
+ if (!User::be(['uid' => $userInfoTwo['spread_uid'], 'is_promoter' => 1])) return true;
}
- $brokerageRatio = (sysConfig('store_brokerage_two') ?: 0)/100;
- if($brokerageRatio <= 0) return true;
+ $brokerageRatio = (sys_config('store_brokerage_two') ?: 0) / 100;
+ if ($brokerageRatio <= 0) return true;
$cost = isset($orderInfo['cost']) ? $orderInfo['cost'] : 0;//成本价
- if($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
- $brokeragePrice = bcmul(bcsub($orderInfo['pay_price'],$cost,2),$brokerageRatio,2);
+ if ($cost > $orderInfo['pay_price']) return true;//成本价大于支付价格时直接返回
+ $brokeragePrice = bcmul(bcsub($orderInfo['pay_price'], $cost, 2), $brokerageRatio, 2);
//返佣之后余额
$spNow_money = User::where('uid', $userInfo['spread_uid'])->value('now_money');
- $balance = bcadd($spNow_money,$brokeragePrice,2);
- if($brokeragePrice <= 0) return true;
- $mark = '二级推广人'.$userInfo['nickname'].'成功消费'.floatval($orderInfo['pay_price']).'元,奖励推广佣金'.floatval($brokeragePrice);
+ $balance = bcadd($spNow_money, $brokeragePrice, 2);
+ if ($brokeragePrice <= 0) return true;
+ $mark = '二级推广人' . $userInfo['nickname'] . '成功消费' . floatval($orderInfo['pay_price']) . '元,奖励推广佣金' . floatval($brokeragePrice);
self::beginTrans();
- $res1 = UserBill::income('获得推广佣金',$userInfoTwo['spread_uid'],'now_money','brokerage',$brokeragePrice,$orderInfo['id'],$balance,$mark);
- $res2 = self::bcInc($userInfoTwo['spread_uid'],'now_money',$brokeragePrice,'uid');
+ $res1 = UserBill::income('获得推广佣金', $userInfoTwo['spread_uid'], 'now_money', 'brokerage', $brokeragePrice, $orderInfo['id'], $balance, $mark);
+ $res2 = self::bcInc($userInfoTwo['spread_uid'], 'now_money', $brokeragePrice, 'uid');
$res = $res1 && $res2;
self::checkTrans($res);
return $res;
diff --git a/crmeb/app/admin/model/user/UserExtract.php b/crmeb/app/admin/model/user/UserExtract.php
index 8550e425..86ccfd6d 100644
--- a/crmeb/app/admin/model/user/UserExtract.php
+++ b/crmeb/app/admin/model/user/UserExtract.php
@@ -5,6 +5,7 @@
* Date: 2018-03-03
* Time: 16:47
*/
+
namespace app\admin\model\user;
use app\admin\model\wechat\WechatUser;
@@ -40,9 +41,9 @@ class UserExtract extends BaseModel
* @param $uid
* @return mixed
*/
- public static function userExtractTotalPrice($uid,$status=1,$where=[])
+ public static function userExtractTotalPrice($uid, $status = 1, $where = [])
{
- return self::getModelTime($where,self::where('uid','in',$uid)->where('status',$status))->sum('extract_price')?:0;
+ return self::getModelTime($where, self::where('uid', 'in', $uid)->where('status', $status))->sum('extract_price') ?: 0;
}
public static function extractStatistics()
@@ -54,7 +55,7 @@ class UserExtract extends BaseModel
//已提现金额
$data['priced'] = floatval(self::where('status', 1)->sum('extract_price'));
//未提现金额
- $data['brokerage_not'] = bcsub(bcsub($data['brokerage_count'], $data['priced'], 2), $data['price'], 2);
+ $data['brokerage_not'] = bcsub(bcsub($data['brokerage_count'], $data['priced'], 2), $data['price'], 2);
return compact('data');
}
@@ -65,61 +66,56 @@ class UserExtract extends BaseModel
public static function systemPage($where)
{
$model = new self;
- if($where['date'] != '') {
+ if ($where['date'] != '') {
list($startTime, $endTime) = explode(' - ', $where['date']);
$model = $model->where('a.add_time', '>', strtotime($startTime));
$model = $model->where('a.add_time', '<', (int)bcadd(strtotime($endTime), 86400, 0));
}
- if($where['status'] != '') $model = $model->where('a.status',$where['status']);
- if($where['extract_type'] != '') $model = $model->where('a.extract_type',$where['extract_type']);
- if($where['nireid'] != '') $model = $model->where('a.real_name|a.id|b.nickname|a.bank_code|a.alipay_code','like',"%$where[nireid]%");
+ if ($where['status'] != '') $model = $model->where('a.status', $where['status']);
+ if ($where['extract_type'] != '') $model = $model->where('a.extract_type', $where['extract_type']);
+ if ($where['nireid'] != '') $model = $model->where('a.real_name|a.id|b.nickname|a.bank_code|a.alipay_code', 'like', "%$where[nireid]%");
$model = $model->alias('a');
$model = $model->field('a.*,b.nickname');
- $model = $model->join('user b','b.uid=a.uid','LEFT');
+ $model = $model->join('user b', 'b.uid=a.uid', 'LEFT');
$model = $model->order('a.id desc');
return self::page($model, $where);
}
- public static function changeFail($id,$fail_msg)
+ public static function changeFail($id, $fail_msg)
{
$fail_time = time();
- $data =self::get($id);
- $extract_number=$data['extract_price'];
- $mark='提现失败,退回佣金'.$extract_number.'元';
- $uid=$data['uid'];
+ $data = self::get($id);
+ $extract_number = $data['extract_price'];
+ $mark = '提现失败,退回佣金' . $extract_number . '元';
+ $uid = $data['uid'];
$status = -1;
- $User= User::where('uid', $uid)->find()->toArray();
- UserBill::income('提现失败',$uid,'now_money','extract',$extract_number,$id,bcadd($User['now_money'],$extract_number,2),$mark);
- User::bcInc($uid,'brokerage_price',$extract_number,'uid');
- $extract_type='未知方式';
- switch ($data['extract_type']){
+ $User = User::where('uid', $uid)->find()->toArray();
+ UserBill::income('提现失败', $uid, 'now_money', 'extract', $extract_number, $id, bcadd($User['now_money'], $extract_number, 2), $mark);
+ User::bcInc($uid, 'brokerage_price', $extract_number, 'uid');
+ $extract_type = '未知方式';
+ switch ($data['extract_type']) {
case 'alipay':
- $extract_type='支付宝';
+ $extract_type = '支付宝';
break;
case 'bank':
- $extract_type='银行卡';
+ $extract_type = '银行卡';
break;
case 'weixin':
- $extract_type='微信';
+ $extract_type = '微信';
break;
}
- if(strtolower($User['user_type']) == 'wechat'){
- WechatTemplateService::sendTemplate(WechatUser::where('uid',$uid)->value('openid'),WechatTemplateService::USER_BALANCE_CHANGE,[
- 'first'=> $mark,
- 'keyword1'=>'佣金提现',
- 'keyword2'=>date('Y-m-d H:i:s',time()),
- 'keyword3'=>$extract_number,
- 'remark'=>'错误原因:'.$fail_msg
- ],Url::buildUrl('/user/cashrecord')->suffix('')->domain(true)->build());
- }else if(strtolower($User['user_type'])=='routine'){
- RoutineTemplate::sendOut('USER_EXTRACT_FALSE',$uid,[
- 'keyword1'=>$fail_msg,
- 'keyword2'=>$extract_number,
- 'keyword3'=>$extract_type,
- 'keyword4'=>date('Y-m-d H:i:s',time()),
- ]);
+ if (strtolower($User['user_type']) == 'wechat') {
+ WechatTemplateService::sendTemplate(WechatUser::where('uid', $uid)->value('openid'), WechatTemplateService::USER_BALANCE_CHANGE, [
+ 'first' => $mark,
+ 'keyword1' => '佣金提现',
+ 'keyword2' => date('Y-m-d H:i:s', time()),
+ 'keyword3' => $extract_number,
+ 'remark' => '错误原因:' . $fail_msg
+ ], Url::buildUrl('/user/cashrecord')->suffix('')->domain(true)->build());
+ } else if (strtolower($User['user_type']) == 'routine') {
+ RoutineTemplate::sendExtractFail($uid, $fail_msg, $extract_number, $User['nickname']);
}
- return self::edit(compact('fail_time','fail_msg','status'),$id);
+ return self::edit(compact('fail_time', 'fail_msg', 'status'), $id);
}
public static function changeSuccess($id)
@@ -127,29 +123,24 @@ class UserExtract extends BaseModel
$data = self::get($id);
$extractNumber = $data['extract_price'];
- $mark = '成功提现佣金'.$extractNumber.'元';
- $wechatUserInfo = WechatUser::where('uid',$data['uid'])->field('openid,user_type,routine_openid')->find();
- $extract_type='未知方式';
- switch ($data['extract_type']){
+ $mark = '成功提现佣金' . $extractNumber . '元';
+ $wechatUserInfo = WechatUser::where('uid', $data['uid'])->field('openid,user_type,routine_openid,nickname')->find();
+ $extract_type = '未知方式';
+ switch ($data['extract_type']) {
case 'alipay':
- $extract_type='支付宝';
+ $extract_type = '支付宝';
break;
case 'bank':
- $extract_type='银行卡';
+ $extract_type = '银行卡';
break;
case 'weixin':
- $extract_type='微信';
+ $extract_type = '微信';
break;
}
- if($wechatUserInfo){
- if(strtolower($wechatUserInfo->user_type)=='routine'){
- RoutineTemplate::sendOut('USER_EXTRACT_TRUE',$data['uid'],[
- 'keyword1'=>$extractNumber.'元',
- 'keyword2'=>'审核成功',
- 'keyword3'=>date('Y-m-d H:i:s', time()),
- 'keyword4'=>$extract_type,
- ]);
- }else if(strtolower($wechatUserInfo->user_type)=='wechat'){
+ if ($wechatUserInfo) {
+ if (strtolower($wechatUserInfo->user_type) == 'routine') {
+ RoutineTemplate::sendExtractSuccess($data['uid'], $extractNumber, $wechatUserInfo->nickname);
+ } else if (strtolower($wechatUserInfo->user_type) == 'wechat') {
WechatTemplateService::sendTemplate($wechatUserInfo->openid, WechatTemplateService::USER_BALANCE_CHANGE, [
'first' => $mark,
'keyword1' => '佣金提现',
@@ -159,163 +150,169 @@ class UserExtract extends BaseModel
], Url::buildUrl('/user/cashrecord')->suffix('')->domain(true)->build());
}
}
- return self::edit(['status'=>1],$id);
+ return self::edit(['status' => 1], $id);
}
+
//测试数据
- public static function test(){
- $uids=User::order('uid desc')->limit(2,20)->field(['uid','nickname'])->select()->toArray();
- $type=['bank','alipay','weixin'];
- foreach ($uids as $item){
- $data=[
- 'uid'=>$item['uid'],
- 'real_name'=>$item['nickname'],
- 'extract_type'=>isset($type[rand(0,2)]) ? $type[rand(0,2)] :'alipay',
- 'bank_code'=>rand(1000000,999999999),
- 'bank_address'=>'中国',
- 'alipay_code'=>rand(1000,9999999),
- 'extract_price'=>rand(100,9999),
- 'mark'=>'测试数据',
- 'add_time'=>time(),
- 'status'=>1,
- 'wechat'=>rand(999,878788).$item['uid'],
+ public static function test()
+ {
+ $uids = User::order('uid desc')->limit(2, 20)->field(['uid', 'nickname'])->select()->toArray();
+ $type = ['bank', 'alipay', 'weixin'];
+ foreach ($uids as $item) {
+ $data = [
+ 'uid' => $item['uid'],
+ 'real_name' => $item['nickname'],
+ 'extract_type' => isset($type[rand(0, 2)]) ? $type[rand(0, 2)] : 'alipay',
+ 'bank_code' => rand(1000000, 999999999),
+ 'bank_address' => '中国',
+ 'alipay_code' => rand(1000, 9999999),
+ 'extract_price' => rand(100, 9999),
+ 'mark' => '测试数据',
+ 'add_time' => time(),
+ 'status' => 1,
+ 'wechat' => rand(999, 878788) . $item['uid'],
];
self::create($data);
}
}
+
//获取头部提现信息
- public static function getExtractHead(){
+ public static function getExtractHead()
+ {
//本月提现人数
- $month=self::getModelTime(['data'=>'month'],self::where('status', 1))->group('uid')->count();
+ $month = self::getModelTime(['data' => 'month'], self::where('status', 1))->group('uid')->count();
//本月提现笔数
- $new_month=self::getModelTime(['data'=>'month'],self::where('status', 1))->distinct(true)->count();
+ $new_month = self::getModelTime(['data' => 'month'], self::where('status', 1))->distinct(true)->count();
//上月提现人数
- $last_month=self::whereTime('add_time','last month')->where('status',1)->group('uid')->distinct(true)->count();
+ $last_month = self::whereTime('add_time', 'last month')->where('status', 1)->group('uid')->distinct(true)->count();
//上月提现笔数
- $last_count=self::whereTime('add_time','last month')->where('status',1)->count();
+ $last_count = self::whereTime('add_time', 'last month')->where('status', 1)->count();
//本月提现金额
- $extract_price=self::getModelTime(['data'=>'month'],self::where('status', 1))->sum('extract_price');
+ $extract_price = self::getModelTime(['data' => 'month'], self::where('status', 1))->sum('extract_price');
//上月提现金额
- $last_extract_price=self::whereTime('add_time','last month')->where('status',1)->sum('extract_price');
+ $last_extract_price = self::whereTime('add_time', 'last month')->where('status', 1)->sum('extract_price');
return [
[
- 'name'=>'总提现人数',
- 'field'=>'个',
- 'count'=>self::where('status', 1)->group('uid')->count(),
- 'content'=>'',
- 'background_color'=>'layui-bg-blue',
- 'sum'=>'',
- 'class'=>'fa fa-bar-chart',
+ 'name' => '总提现人数',
+ 'field' => '个',
+ 'count' => self::where('status', 1)->group('uid')->count(),
+ 'content' => '',
+ 'background_color' => 'layui-bg-blue',
+ 'sum' => '',
+ 'class' => 'fa fa-bar-chart',
],
[
- 'name'=>'总提现笔数',
- 'field'=>'笔',
- 'count'=>self::where('status', 1)->distinct(true)->count(),
- 'content'=>'',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>'',
- 'class'=>'fa fa-line-chart',
+ 'name' => '总提现笔数',
+ 'field' => '笔',
+ 'count' => self::where('status', 1)->distinct(true)->count(),
+ 'content' => '',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => '',
+ 'class' => 'fa fa-line-chart',
],
[
- 'name'=>'本月提现人数',
- 'field'=>'人',
- 'count'=>$month,
- 'content'=>'',
- 'background_color'=>'layui-bg-orange',
- 'sum'=>'',
- 'class'=>'fa fa-line-chart',
+ 'name' => '本月提现人数',
+ 'field' => '人',
+ 'count' => $month,
+ 'content' => '',
+ 'background_color' => 'layui-bg-orange',
+ 'sum' => '',
+ 'class' => 'fa fa-line-chart',
],
[
- 'name'=>'本月提现笔数',
- 'field'=>'笔',
- 'count'=>$new_month,
- 'content'=>'',
- 'background_color'=>'layui-bg-green',
- 'sum'=>'',
- 'class'=>'fa fa-line-chart',
+ 'name' => '本月提现笔数',
+ 'field' => '笔',
+ 'count' => $new_month,
+ 'content' => '',
+ 'background_color' => 'layui-bg-green',
+ 'sum' => '',
+ 'class' => 'fa fa-line-chart',
],
[
- 'name'=>'本月提现金额',
- 'field'=>'元',
- 'count'=>$extract_price,
- 'content'=>'提现总金额',
- 'background_color'=>'layui-bg-cyan',
- 'sum'=>self::where('status', 1)->sum('extract_price'),
- 'class'=>'fa fa-line-chart',
+ 'name' => '本月提现金额',
+ 'field' => '元',
+ 'count' => $extract_price,
+ 'content' => '提现总金额',
+ 'background_color' => 'layui-bg-cyan',
+ 'sum' => self::where('status', 1)->sum('extract_price'),
+ 'class' => 'fa fa-line-chart',
],
[
- 'name'=>'上月提现人数',
- 'field'=>'个',
- 'count'=>$last_month,
- 'content'=>'环比增幅',
- 'background_color'=>'layui-bg-blue',
- 'sum'=>$last_month==0 ? '100%' :bcdiv($month,$last_month,2)*100,
- 'class'=>$last_month==0 ? 'fa fa-level-up':'fa fa-level-down',
+ 'name' => '上月提现人数',
+ 'field' => '个',
+ 'count' => $last_month,
+ 'content' => '环比增幅',
+ 'background_color' => 'layui-bg-blue',
+ 'sum' => $last_month == 0 ? '100%' : bcdiv($month, $last_month, 2) * 100,
+ 'class' => $last_month == 0 ? 'fa fa-level-up' : 'fa fa-level-down',
],
[
- 'name'=>'上月提现笔数',
- 'field'=>'笔',
- 'count'=>$last_count,
- 'content'=>'环比增幅',
- 'background_color'=>'layui-bg-black',
- 'sum'=>$last_count==0 ? '100%':bcdiv($new_month,$last_count,2)*100,
- 'class'=>$last_count==0 ? 'fa fa-level-up':'fa fa-level-down',
+ 'name' => '上月提现笔数',
+ 'field' => '笔',
+ 'count' => $last_count,
+ 'content' => '环比增幅',
+ 'background_color' => 'layui-bg-black',
+ 'sum' => $last_count == 0 ? '100%' : bcdiv($new_month, $last_count, 2) * 100,
+ 'class' => $last_count == 0 ? 'fa fa-level-up' : 'fa fa-level-down',
],
[
- 'name'=>'上月提现金额',
- 'field'=>'元',
- 'count'=>$last_extract_price,
- 'content'=>'环比增幅',
- 'background_color'=>'layui-bg-gray',
- 'sum'=>$last_extract_price==0 ? '100%':bcdiv($extract_price,$last_extract_price,2)*100,
- 'class'=>$last_extract_price==0 ? 'fa fa-level-up':'fa fa-level-down',
+ 'name' => '上月提现金额',
+ 'field' => '元',
+ 'count' => $last_extract_price,
+ 'content' => '环比增幅',
+ 'background_color' => 'layui-bg-gray',
+ 'sum' => $last_extract_price == 0 ? '100%' : bcdiv($extract_price, $last_extract_price, 2) * 100,
+ 'class' => $last_extract_price == 0 ? 'fa fa-level-up' : 'fa fa-level-down',
],
];
}
+
//获取提现分布图和提现人数金额曲线图
- public static function getExtractList($where,$limit=15){
- $legdata=['提现人数','提现金额'];
- $list=self::getModelTime($where,self::where('status',1))
+ public static function getExtractList($where, $limit = 15)
+ {
+ $legdata = ['提现人数', '提现金额'];
+ $list = self::getModelTime($where, self::where('status', 1))
->field('FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time,count(uid) as count,sum(extract_price) as sum_price')->group('un_time')->order('un_time asc')->select();
- if(count($list)) $list=$list->toArray();
+ if (count($list)) $list = $list->toArray();
$xdata = [];
- $itemList = [0=>[],1=>[]];
+ $itemList = [0 => [], 1 => []];
$chatrList = [];
$zoom = '';
- foreach ($list as $value){
- $xdata[]=$value['un_time'];
- $itemList[0][]=$value['count'];
- $itemList[1][]=$value['sum_price'];
+ foreach ($list as $value) {
+ $xdata[] = $value['un_time'];
+ $itemList[0][] = $value['count'];
+ $itemList[1][] = $value['sum_price'];
}
- foreach ($legdata as $key=>$name){
- $item['name']=$name;
- $item['type']='line';
- $item['data']=$itemList[$key];
- $chatrList[]=$item;
+ foreach ($legdata as $key => $name) {
+ $item['name'] = $name;
+ $item['type'] = 'line';
+ $item['data'] = $itemList[$key];
+ $chatrList[] = $item;
}
- unset($item,$name,$key);
- if(count($xdata)>$limit) $zoom=$xdata[$limit-5];
+ unset($item, $name, $key);
+ if (count($xdata) > $limit) $zoom = $xdata[$limit - 5];
//饼状图
- $cake=['支付宝','银行卡','微信'];
- $fenbulist=self::getModelTime($where,self::where('status',1))
+ $cake = ['支付宝', '银行卡', '微信'];
+ $fenbulist = self::getModelTime($where, self::where('status', 1))
->field('count(uid) as count,extract_type')->group('extract_type')->order('count asc')->select();
- if(count($fenbulist)) $fenbulist = $fenbulist->toArray();
- $sum_count = self::getModelTime($where,self::where('status',1))->count();
- $color = ['#FB7773','#81BCFE','#91F3FE'];
+ if (count($fenbulist)) $fenbulist = $fenbulist->toArray();
+ $sum_count = self::getModelTime($where, self::where('status', 1))->count();
+ $color = ['#FB7773', '#81BCFE', '#91F3FE'];
$fenbudata = [];
- foreach ($fenbulist as $key=>$item){
- if($item['extract_type']=='bank'){
- $item_date['name']='银行卡';
- }else if($item['extract_type']=='alipay'){
- $item_date['name']='支付宝';
- }else if($item['extract_type']=='weixin'){
- $item_date['name']='微信';
+ foreach ($fenbulist as $key => $item) {
+ if ($item['extract_type'] == 'bank') {
+ $item_date['name'] = '银行卡';
+ } else if ($item['extract_type'] == 'alipay') {
+ $item_date['name'] = '支付宝';
+ } else if ($item['extract_type'] == 'weixin') {
+ $item_date['name'] = '微信';
}
- $item_date['value']=bcdiv($item['count'],$sum_count,2)*100;
- $item_date['itemStyle']['color']=$color[$key];
- $fenbudata[]=$item_date;
+ $item_date['value'] = bcdiv($item['count'], $sum_count, 2) * 100;
+ $item_date['itemStyle']['color'] = $color[$key];
+ $fenbudata[] = $item_date;
}
- return compact('xdata','chatrList','legdata','zoom','cake','fenbudata');
+ return compact('xdata', 'chatrList', 'legdata', 'zoom', 'cake', 'fenbudata');
}
/**
@@ -323,9 +320,10 @@ class UserExtract extends BaseModel
* @param int $uid
* @return int|mixed
*/
- public static function getUserCountPrice($uid = 0){
- if(!$uid) return 0;
- $price = self::where('uid',$uid)->where('status',1)->sum('extract_price');
+ public static function getUserCountPrice($uid = 0)
+ {
+ if (!$uid) return 0;
+ $price = self::where('uid', $uid)->where('status', 1)->sum('extract_price');
return $price ? $price : 0;
}
@@ -334,8 +332,9 @@ class UserExtract extends BaseModel
* @param int $uid
* @return int|string
*/
- public static function getUserCountNum($uid = 0){
- if(!$uid) return 0;
- return self::where('uid',$uid)->count();
+ public static function getUserCountNum($uid = 0)
+ {
+ if (!$uid) return 0;
+ return self::where('uid', $uid)->count();
}
}
\ No newline at end of file
diff --git a/crmeb/app/admin/view/index/index.php b/crmeb/app/admin/view/index/index.php
index 74c4aab5..dccfa6ff 100644
--- a/crmeb/app/admin/view/index/index.php
+++ b/crmeb/app/admin/view/index/index.php
@@ -266,6 +266,7 @@
{include file="public/style"}