维护客户业务统计

This commit is contained in:
wanyongkang
2020-11-23 17:00:11 +08:00
parent 9f654db2aa
commit ce48d318e8

View File

@@ -2,9 +2,9 @@
namespace app\manager\controller;
use app\manager\model\Manager;
use app\manager\model\ProductOrder;
use app\manager\model\User;
use app\manager\model\Manager;
use fastphp\base\Controller;
class SellInfo extends Controller
@@ -34,21 +34,19 @@ class SellInfo extends Controller
$time_where_today = '';
$time_where2_today = '';
$date1 = date("Y-m-01", time());
$date2 = date("Y-m-d H:i:s", time());
$flag = date("d", time()) == date("t", time());
$date3 = date("Y-m-01", strtotime("-1 month"));
$date4 = $flag ? date("Y-m-t H:i:s", strtotime("-1 month")) : date("Y-m-d H:i:s", strtotime("-1 month"));
if(isset($_GET['sell_month'])){
if (isset($_GET['sell_month'])) {
$date1 = date('Y-m-01', strtotime($_GET['sell_month']));
$date2 = date("Y-m-t 23:59:59", strtotime($_GET['sell_month']));
$date3 = date("Y-m-01", strtotime($_GET['sell_month']." -1 month"));
$date4 = date("Y-m-t 23:59:59", strtotime($_GET['sell_month']." -1 month"));
$date3 = date("Y-m-01", strtotime($_GET['sell_month'] . " -1 month"));
$date4 = date("Y-m-t 23:59:59", strtotime($_GET['sell_month'] . " -1 month"));
}
//本月
$time_where1 .= " UpdateTime>='" . $date1 . "' and UpdateTime<='" . $date2 . "' ";
$time_where2 .= " UpdateTime>='" . $date3 . "' and UpdateTime<='" . $date4 . "' ";
@@ -81,33 +79,33 @@ class SellInfo extends Controller
//获取本月总退款
$refund_cost_data = $product_order_model->getRefund($time_where1, $user_where);
//总消费营业额
$all_cost = $all_cost_data['money']??0;
$user_cost = $user_cost_data['money']??0;
$all_cost_num = $all_cost_data['num']??0;
$user_cost_num = $user_cost_data['num']??0;
$all_cost = $all_cost_data['money'] ?? 0;
$user_cost = $user_cost_data['money'] ?? 0;
$all_cost_num = $all_cost_data['num'] ?? 0;
$user_cost_num = $user_cost_data['num'] ?? 0;
//上月
$user_last_month_cost = $user_last_month_cost_data['money']??0;
$user_last_month_cost = $user_last_month_cost_data['money'] ?? 0;
//注册
$user_register_count = count($register_id_list);
$user_register_cost_count = $register_cost_data?$register_cost_data['num']:0;
$user_register_cost_count = $register_cost_data ? $register_cost_data['num'] : 0;
$sell_percent = ($all_cost?round($user_cost / $all_cost * 100, 2):0);
$cost_percent = ($all_cost_num?round($user_cost_num / $all_cost_num * 100, 2):0);
$cost_register = ($user_register_count?round($user_register_cost_count / $user_register_count * 100, 2):0);
$cost_old_user = (($all_cost_num - $user_register_count)?round(($user_cost_num - $user_register_cost_count) / ($all_cost_num - $user_register_count) * 100, 2):0);
$com_cost = ($user_cost - $user_last_month_cost);
$com_percent = ($user_last_month_cost?round(($user_cost - $user_last_month_cost) / $user_last_month_cost * 100, 2):0);
$today_new_user = ($user_today_cost_data?$user_today_cost_data['num']:0)."/".count($today_register_id_list);
$refund = ($refund_cost_data?$refund_cost_data['money']:0);
$sell_percent = ($all_cost ? round($user_cost / $all_cost * 100, 2) : 0);
$cost_percent = ($all_cost_num ? round($user_cost_num / $all_cost_num * 100, 2) : 0);
$cost_register = ($user_register_count ? round($user_register_cost_count / $user_register_count * 100, 2) : 0);
$cost_old_user = (($all_cost_num - $user_register_count) ? round(($user_cost_num - $user_register_cost_count) / ($all_cost_num - $user_register_count) * 100, 2) : 0);
$com_cost = round(($user_cost - $user_last_month_cost), 2);
$com_percent = ($user_last_month_cost ? round(($user_cost - $user_last_month_cost) / $user_last_month_cost * 100, 2) : 0);
$today_new_user = ($user_today_cost_data ? $user_today_cost_data['num'] : 0) . "/" . count($today_register_id_list);
$refund = ($refund_cost_data ? $refund_cost_data['money'] : 0);
$data['sell_percent'] = "我的营业额($user_cost)/总营业额($all_cost)=" . $sell_percent . '%';
$data['cost_percent'] = "消费客户数($user_cost_num)/所有客户($all_cost_num)=" . $cost_percent . '%';
$data['cost_register'] = "注册且购买过的客户($user_register_cost_count)/当月新注册客户总数($user_register_count)=" . $cost_register . '%';
$data['cost_old_user'] = "老客户在本月再次购买(" . ($user_cost_num - $user_register_cost_count) . ")/所有老客户(" . $cost_old_user . '%';
$data['com_cost'] = "同比增加金额=" . $com_cost;
$data['com_percent'] = "同比增加百分比=" . $com_percent.'%';
$data['today_new_user'] = "今日新赠客户".$today_new_user;
$data['refund'] = "总退款金额".$refund;
$data['com_percent'] = "同比增加百分比=" . $com_percent . '%';
$data['today_new_user'] = "今日新赠客户" . $today_new_user;
$data['refund'] = "总退款金额" . $refund;
\result($data);
}
@@ -122,7 +120,7 @@ class SellInfo extends Controller
$manager_model = new Manager;
$manager_list = $manager_model->getAllList();
$list = [];
foreach($manager_list as $info){
foreach ($manager_list as $info) {
$temp = $this->getInfo($info['id']);
$temp['name'] = $info['RealName'];
$list[] = $temp;
@@ -135,7 +133,7 @@ class SellInfo extends Controller
$user_model = new User;
$product_order_model = new ProductOrder;
$where['ManagerId'] = $manager_id;
$user_id_list = [];
$register_id_list = [];
$today_register_id_list = [];
@@ -146,21 +144,19 @@ class SellInfo extends Controller
$time_where2_today = '';
$data = [];
$date1 = date("Y-m-01", time());
$date2 = date("Y-m-d H:i:s", time());
$flag = date("d", time()) == date("t", time());
$date3 = date("Y-m-01", strtotime("-1 month"));
$date4 = $flag ? date("Y-m-t H:i:s", strtotime("-1 month")) : date("Y-m-d H:i:s", strtotime("-1 month"));
if(isset($_GET['sell_month'])){
if (isset($_GET['sell_month'])) {
$date1 = date('Y-m-01', strtotime($_GET['sell_month']));
$date2 = date("Y-m-t 23:59:59", strtotime($_GET['sell_month']));
$date3 = date("Y-m-01", strtotime($_GET['sell_month']." -1 month"));
$date4 = date("Y-m-t 23:59:59", strtotime($_GET['sell_month']." -1 month"));
$date3 = date("Y-m-01", strtotime($_GET['sell_month'] . " -1 month"));
$date4 = date("Y-m-t 23:59:59", strtotime($_GET['sell_month'] . " -1 month"));
}
//本月
$time_where1 .= " UpdateTime>='" . $date1 . "' and UpdateTime<='" . $date2 . "' ";
$time_where2 .= " UpdateTime>='" . $date3 . "' and UpdateTime<='" . $date4 . "' ";
@@ -193,24 +189,24 @@ class SellInfo extends Controller
//获取本月总退款
$refund_cost_data = $product_order_model->getRefund($time_where1, $user_where);
//总消费营业额
$all_cost = $all_cost_data['money']??0;
$user_cost = $user_cost_data['money']??0;
$all_cost_num = $all_cost_data['num']??0;
$user_cost_num = $user_cost_data['num']??0;
$all_cost = $all_cost_data['money'] ?? 0;
$user_cost = $user_cost_data['money'] ?? 0;
$all_cost_num = $all_cost_data['num'] ?? 0;
$user_cost_num = $user_cost_data['num'] ?? 0;
//上月
$user_last_month_cost = $user_last_month_cost_data['money']??0;
$user_last_month_cost = $user_last_month_cost_data['money'] ?? 0;
//注册
$user_register_count = count($register_id_list);
$user_register_cost_count = $register_cost_data?$register_cost_data['num']:0;
$user_register_cost_count = $register_cost_data ? $register_cost_data['num'] : 0;
$data['sell_percent'] = ($all_cost?round($user_cost / $all_cost * 100, 2):0).'%';
$data['cost_percent'] = ($all_cost_num?round($user_cost_num / $all_cost_num * 100, 2):0).'%';
$data['cost_register'] = ($user_register_count?round($user_register_cost_count / $user_register_count * 100, 2):0);
$data['cost_old_user'] = (($all_cost_num - $user_register_count)?round(($user_cost_num - $user_register_cost_count) / ($all_cost_num - $user_register_count) * 100, 2):0);
$data['com_cost'] = ($user_cost - $user_last_month_cost);
$data['com_percent'] = ($user_last_month_cost?round(($user_cost - $user_last_month_cost) / $user_last_month_cost * 100, 2):0).'%';
$data['today_new_user'] = ($user_today_cost_data?$user_today_cost_data['num']:0)."/".count($today_register_id_list);
$data['refund'] = ($refund_cost_data?$refund_cost_data['money']:0);
$data['sell_percent'] = ($all_cost ? round($user_cost / $all_cost * 100, 2) : 0) . '%';
$data['cost_percent'] = ($all_cost_num ? round($user_cost_num / $all_cost_num * 100, 2) : 0) . '%';
$data['cost_register'] = ($user_register_count ? round($user_register_cost_count / $user_register_count * 100, 2) : 0) . '%';
$data['cost_old_user'] = (($all_cost_num - $user_register_count) ? round(($user_cost_num - $user_register_cost_count) / ($all_cost_num - $user_register_count) * 100, 2) : 0) . '%';
$data['com_cost'] = round(($user_cost - $user_last_month_cost), 2);
$data['com_percent'] = ($user_last_month_cost ? round(($user_cost - $user_last_month_cost) / $user_last_month_cost * 100, 2) : 0) . '%';
$data['today_new_user'] = ($user_today_cost_data ? $user_today_cost_data['num'] : 0) . "/" . count($today_register_id_list);
$data['refund'] = ($refund_cost_data ? $refund_cost_data['money'] : 0);
return $data;
}