customer_415_4

This commit is contained in:
dengbw
2022-04-15 17:11:30 +08:00
parent 7aab9d981c
commit 88efd15fdc
+40 -37
View File
@@ -51,6 +51,7 @@ class Licheb extends HD_Controller
}
$id = $redis->get($redisKey);
!$id && $id = 0;
$id = 19;
$log = [];
$where = ['id >' => $id, 'group_id < 4' => null, 'status' => 1];
$res = $this->mdUsers->select($where, 'id asc', 1, $size, 'id,biz_id');
@@ -63,50 +64,52 @@ class Licheb extends HD_Controller
$this->load->model("biz/biz_model", 'mdBiz');
$offlineSources = $this->mdCustomers->offlineSources();
$str_biz_ids = implode(',', array_unique(array_column($res, 'biz_id')));
$map_biz = $this->mdBiz->map('id', 'city_id,type', ["id in({$str_biz_ids})" => null]);
$map_biz = $this->mdBiz->map('id', 'city_id,type,status', ["id in({$str_biz_ids})" => null]);
foreach ($res as $key => $value) {
$sale_id = $id = $value['id'];
$biz_id = intval($value['biz_id']);
$re_log = $this->mdUsersLog->get(['log_date' => $log_date, 'sale_id' => $sale_id, 'biz_id' => $biz_id]);
if (!$re_log) {//判断当天是否已加入
$s_time = strtotime($log_date . ' 00:00:00');
$e_time = strtotime($log_date . ' 23:59:59');
$city_id = intval($map_biz[$biz_id]['city_id']);
$type = intval($map_biz[$biz_id]['type']);
$a_num = $this->mdCustomerOpLogs->count(['uid' => $sale_id, 'type' => 4, 'c_time>=' => $s_time, 'c_time<=' => $e_time,
"customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null]
);
$follows = $this->mdCustomerOpLogs->count(['uid' => $sale_id, 'type<>' => 3, 'c_time>=' => $s_time, 'c_time<=' => $e_time,
"customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null], 'distinct(customer_id)'
);
$orders = $this->mdOrdersV2->count(['sale_id' => $sale_id, 'biz_id' => $biz_id, 'status>=' => 0,
'order_time>=' => "{$log_date} 00:00:00", 'order_time<=' => "{$log_date} 23:59:59"]
);
$bills = $this->mdOrdersV2->count(['sale_id' => $sale_id, 'biz_id' => $biz_id, 'status>=' => 0,
'bill_time>=' => "{$log_date} 00:00:00", 'bill_time<=' => "{$log_date} 23:59:59"]
);
$add_item = ['sale_id' => $sale_id, 'biz_id' => $biz_id, 'type' => $type, 'city_id' => $city_id, 'a_num' => $a_num
, 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'log_date' => $log_date, 'c_time' => time()];
$customer_json = '';
foreach ($offlineSources as $key1 => $value1) {
$customer_num1 = $this->mdCustomers->count(['of_id' => $key1, 'admin_id' => $sale_id
, 'status>=' => 0, 'c_time>=' => $s_time, 'c_time<=' => $e_time]);
if ($customer_num1) {//一级
$add_item["customer_{$key1}"] = $customer_num1;
$list = '';
foreach ($value1['list'] as $key2 => $value2) {
$customer_num2 = $this->mdCustomers->count(['of_id' => $key1, 'of2_id' => $key2, 'admin_id' => $sale_id
, 'status>=' => 0, 'c_time>=' => $s_time, 'c_time<=' => $e_time]);
if ($customer_num2) {//二级
$list[$key2] = ['name' => $value2, 'num' => $customer_num2];
if ($map_biz[$biz_id]['status'] == 1) {//判断门店状态
$re_log = $this->mdUsersLog->get(['log_date' => $log_date, 'sale_id' => $sale_id, 'biz_id' => $biz_id]);
if (!$re_log) {//判断当天是否已加入
$s_time = strtotime($log_date . ' 00:00:00');
$e_time = strtotime($log_date . ' 23:59:59');
$city_id = intval($map_biz[$biz_id]['city_id']);
$type = intval($map_biz[$biz_id]['type']);
$a_num = $this->mdCustomerOpLogs->count(['uid' => $sale_id, 'type' => 4, 'c_time>=' => $s_time, 'c_time<=' => $e_time,
"customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null]
);
$follows = $this->mdCustomerOpLogs->count(['uid' => $sale_id, 'type<>' => 3, 'c_time>=' => $s_time, 'c_time<=' => $e_time,
"customer_id in(select id from lc_receiver_customers where admin_id={$sale_id} and biz_id={$biz_id})" => null], 'distinct(customer_id)'
);
$orders = $this->mdOrdersV2->count(['sale_id' => $sale_id, 'biz_id' => $biz_id, 'status>=' => 0,
'order_time>=' => "{$log_date} 00:00:00", 'order_time<=' => "{$log_date} 23:59:59"]
);
$bills = $this->mdOrdersV2->count(['sale_id' => $sale_id, 'biz_id' => $biz_id, 'status>=' => 0,
'bill_time>=' => "{$log_date} 00:00:00", 'bill_time<=' => "{$log_date} 23:59:59"]
);
$add_item = ['sale_id' => $sale_id, 'biz_id' => $biz_id, 'type' => $type, 'city_id' => $city_id, 'a_num' => $a_num
, 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'log_date' => $log_date, 'c_time' => time()];
$customer_json = '';
foreach ($offlineSources as $key1 => $value1) {
$customer_num1 = $this->mdCustomers->count(['of_id' => $key1, 'admin_id' => $sale_id
, 'status>=' => 0, 'c_time>=' => $s_time, 'c_time<=' => $e_time]);
if ($customer_num1) {//一级
$add_item["customer_{$key1}"] = $customer_num1;
$list = '';
foreach ($value1['list'] as $key2 => $value2) {
$customer_num2 = $this->mdCustomers->count(['of_id' => $key1, 'of2_id' => $key2, 'admin_id' => $sale_id
, 'status>=' => 0, 'c_time>=' => $s_time, 'c_time<=' => $e_time]);
if ($customer_num2) {//二级
$list[$key2] = ['name' => $value2, 'num' => $customer_num2];
}
}
$customer_json[$key1] = ['name' => $value1['name'], 'num' => $customer_num1, 'list' => $list];
}
$customer_json[$key1] = ['name' => $value1['name'], 'num' => $customer_num1, 'list' => $list];
}
$customer_json && $add_item['customer_json'] = json_encode($customer_json, JSON_UNESCAPED_UNICODE);
$add_id = $this->mdUsersLog->add($add_item);
$add_id && $log[] = array('id' => $sale_id, 'addDate' => $add_item);
}
$customer_json && $add_item['customer_json'] = json_encode($customer_json, JSON_UNESCAPED_UNICODE);
$add_id = $this->mdUsersLog->add($add_item);
$add_id && $log[] = array('id' => $sale_id, 'addDate' => $add_item);
}
}
$redis->save($redisKey, $id, 24 * 3600);//保存最后id