log_file = 'temp.log';
}
/**
* Notes:更新私域直播_用户门店
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/market_sylive_user
* https://api.liche.cn/plan/temp/market_sylive_user
*/
public function market_sylive_user()
{
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 100;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ["organizationId>" => 0];
$res = $this->mdSyliveUser->select($where, 'userId ASC', $param['page'], $param['size'], 'userId,organizationId');
if (!$res) {
echo '
本次更新用户门店完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新用户门店>>>';
exit;
}
$log = [];
foreach ($res as $key => $v) {
$re = $this->mdSyliveOrganization->get(['organizationId' => $v['organizationId']]
, 'organizationId,organizationType,parentId');
$bizId = 0;
if ($re) {
if ($re['organizationType'] == 4 && $re['parentId']) {
$bizId = $re['parentId'];
} else if ($re['organizationType'] == 3) {
$bizId = $re['organizationId'];
}
}
if ($bizId) {
$ret = $this->mdSyliveUser->update(['bizId' => $bizId], ['userId' => $v['userId']]);
if ($ret) {
$log[] = ['userId' => $v['userId'], 'bizId' => $bizId];
$counts++;
}
}
}
echo '
成功更新:';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
}
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/market_sylive_user?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新门店日志
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_bizs_log_5
* https://api.liche.cn/plan/temp/receiver_bizs_log_5
*/
public function receiver_bizs_log_5()
{
$param = $this->input->get();
$page = intval($param['page']);
!$page && $page = 0;
ob_start(); //打开缓冲区
$log_date = date("Y-m-d", strtotime("+{$page} day", strtotime("2022-04-15")));
echo "log_date={$log_date}
";
if ($log_date >= date("Y-m-d")) {
echo '
本次更新门店日志完成了:';
echo '
成功更新 ' . $param['page'] . ' 次';
echo '
点击将再次更新门店日志>>>';
exit;
}
$log = [];
$this->load->model('app/licheb/app_licheb_bizs_log_model', 'mdBizsLog');
$res = $this->mdBizsLog->select(['log_date' => $log_date], 'id asc', 0, 0, 'id,c_num_json,order_json,customer_json');
foreach ($res as $k => $v) {
$customer_json = $v['customer_json'] ? json_decode($v['customer_json'], true) : [];
$c_num_json = $v['c_num_json'] ? json_decode($v['c_num_json'], true) : [];
$order_json = $v['order_json'] ? json_decode($v['order_json'], true) : [];
$upData = [];
if ($customer_json[5]['num']) {
$upData['customer_5'] = $customer_json[5]['num'];
}
if ($c_num_json[5]['num']) {
$upData['c_num_5'] = $c_num_json[5]['num'];
}
if ($order_json[5]['num']) {
$upData['order_5'] = $order_json[5]['num'];
}
if ($upData) {
$ret = $this->mdBizsLog->update($upData, ['id' => $v['id']]);
if ($ret) {
$log[] = $upData;
}
}
}
echo '
成功更新:';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
}
echo '
数据库获取:';
//echo json_encode($res, JSON_UNESCAPED_UNICODE);
echo 'count=' . count($res);
header('refresh:3;url=/plan/temp/receiver_bizs_log_5?page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新客户初始销售
* Created on: 2022/7/26 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/add_owners
* https://api.liche.cn/plan/temp/add_owners
*/
public function add_owners()
{
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders');
$this->load->model('receiver/order/receiver_order_agents_model', 'mdOrdersAgents');
$this->load->model('app/liche/app_liche_users_model', 'mdUsers');
$this->load->model('receiver/receiver_owners_model', 'mdOwners');
$this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
$this->load->model('app/app_different_qy_model', 'mdDifferentQy');
$this->load->model("biz/biz_model", 'mdBiz');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$t1 = 'lc_receiver_orders_v2';
$t2 = 'lc_receiver_order_status';
$where = ["{$t2}.c_time=" => 0, "{$t1}.status>=" => 0, "{$t1}.owner_name<>" => '', "{$t1}.owner_mobile<>" => '',
"{$t2}.pid_status" => 5, "{$t2}.status" => 1];
$having = "total >= 1";
$orderby = "{$t2}.id asc";
$fileds = "{$t1}.id,{$t1}.brand_id,{$t1}.s_id,{$t1}.v_id,{$t1}.owner_name,{$t1}.owner_mobile,{$t1}.order_time,{$t1}.ck_time
,{$t1}.bill_time,{$t1}.info_json,{$t1}.biz_id,{$t2}.c_time";
$res = $this->mdOrders->selectOrders($where, $orderby, $param['page'], $param['size'], '', $fileds, $having);
if (!$res) {
echo '
本次更新车主完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新车主>>>';
exit;
}
$log = array();
$str_o_ids = implode(',', array_unique(array_column($res, 'id')));
$map_agents = $this->mdOrdersAgents->map('o_id', 'car_num', ["o_id in({$str_o_ids})" => null]);
$str_mobiles = implode(',', array_unique(array_column($res, 'owner_mobile')));
$map_users = $this->mdUsers->map('mobile', 'id', ["mobile in({$str_mobiles})" => null]);
foreach ($res as $key => $value) {
$c_time = $value['c_time'];
$birth_day = '0000-00-00';
$sex = 0;
if ($value['info_json']) {
$info_json = json_decode($value['info_json'], true);
if ($info_json['c_owner_cardid']) {
$cardid = $info_json['c_owner_cardid'];
$birth_day = date('Y-m-d', strtotime(substr($cardid, 6, 8)));
$sex = substr($cardid, -2, 1) % 2 == 0 ? 2 : 1; //1为男 2为女
}
}
$uid = intval($map_users[$value['owner_mobile']]);
$car_num = $map_agents[$value['id']] ? $map_agents[$value['id']] : '';
$ck_time = $value['ck_time'] != '0000-00-00 00:00:00' ? $value['ck_time'] : $value['bill_time'];
$data = ['o_id' => $value['id'], 'uid' => $uid, 'name' => $value['owner_name'], 'mobile' => $value['owner_mobile'],
'birth_day' => $birth_day, 'sex' => $sex, 'brand_id' => $value['brand_id'], 's_id' => $value['s_id'],
'v_id' => $value['v_id'], 'order_time' => $value['order_time'], 'ck_time' => $ck_time, 'car_num' => $car_num];
$biz_type = 0;
if ($value['biz_id']) {
$re_biz = $this->mdBiz->get(['id' => $value['biz_id']]);
if ($re_biz) {
$biz_type = $re_biz['type'];
$data['province_id'] = $re_biz['province_id'];
$data['city_id'] = $re_biz['city_id'];
$data['county_id'] = $re_biz['county_id'];
}
}
if ($value['owner_mobile']) {//查找企微
if ($biz_type == 5) {//异业店
$re_qy = $this->mdDifferentQy->get(['mobile' => $value['owner_mobile']]);
$re_qy && $data['wxqy'] = 1;
} else {
$re_qy = $this->mdWechatqy->get(['mobile' => $value['owner_mobile']]);
if ($re_qy) {
$data['wxqy'] = 1;
} else {
$re_use = $this->mdUsers->get(['mobile' => $value['owner_mobile'], 'status<>' => -1]);
if ($re_use['unionid']) {
$re_qy = $this->mdWechatqy->get(['unionid' => $re_use['unionid']]);
$re_qy && $data['wxqy'] = 1;
}
}
}
}
$re = $this->mdOwners->get(['o_id' => $value['id']]);
if ($re) {
//$data['u_time'] = $re['u_time'];
// $this->mdOwners->update($data, ['id' => $re['id']]);
} else {
$data['c_time'] = time();
$data['u_time'] = '0000-00-00 00:00:00';
$id = $this->mdOwners->add($data);
if ($id) {
$log[] = ['id' => $id, 'name' => $data['name'], 'mobile' => $data['mobile']];
$counts++;
}
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/add_owners?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新客户初始销售
* Created on: 2022/7/26 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_customer_sales
* https://api.liche.cn/plan/temp/receiver_customer_sales
*/
public function receiver_customer_sales()
{
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = array("admin_id>" => 0);
$res = $this->mdCustomers->select($where, 'id ASC', $param['page'], $param['size'], 'id,admin_id,sales_id');
if (!$res) {
echo '
本次更新客户初始销售完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新客户初始销售>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
if (!$value['sales_id']) {
$this->mdCustomers->update(['sales_id' => $value['admin_id']], ['id' => $value['id']]);
$log[] = array('id' => $value['id'], 'sales_id' => $value['admin_id']);
$counts++;
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_customer_sales?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新订单初始销售
* Created on: 2022/7/26 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_ordersv2_sales
* https://api.liche.cn/plan/temp/receiver_ordersv2_sales
*/
public function receiver_ordersv2_sales()
{
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrdersV2');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = array("sale_id>" => 0);
$res = $this->mdOrdersV2->select($where, 'id ASC', $param['page'], $param['size'], 'id,admin_id,sale_id');
if (!$res) {
echo '
本次更新订单初始销售完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新订单初始销售>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
if (!$value['admin_id']) {
$this->mdOrdersV2->update(['admin_id' => $value['sale_id']], ['id' => $value['id']]);
$log[] = array('id' => $value['id'], 'admin_id' => $value['sale_id']);
$counts++;
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_ordersv2_sales?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新顾问日志
* Created on: 2022/7/11 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_users_log
* https://api.liche.cn/plan/temp/receiver_users_log
*/
public function receiver_users_log()
{
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog');
$this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomerOpLogs');
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrdersV2');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 100;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ['c_num>0 or orders>0' => null];
$res = $this->mdUsersLog->select($where, 'id asc', $param['page'], $param['size'], 'id,sale_id,biz_id,log_date');
if (!$res) {
echo '
本次更新完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新>>>';
exit;
}
$log = array();
$offlineSources = $this->mdCustomers->offlineSources();
foreach ($res as $key => $value) {
$sale_id = $value['sale_id'];
$biz_id = $value['biz_id'];
$log_date = $value['log_date'];
$s_time = strtotime($log_date . ' 00:00:00');
$e_time = strtotime($log_date . ' 23:59:59');
$c_num_json = $order_json = '';
$update_item = [];
foreach ($offlineSources as $key1 => $value1) {
//进店人数
$c_num1 = $this->mdCustomerOpLogs->count(['uid' => $sale_id, 'type' => 4, 'log' => '客户到店', 'c_time>=' => $s_time, 'c_time<=' => $e_time,
"customer_id in(select id from lc_receiver_customers where of_id={$key1} and admin_id={$sale_id}
and biz_id={$biz_id} and cs_biz_id!=-1)" => null], 'distinct(customer_id)');
if ($c_num1) {//一级
$update_item["c_num_{$key1}"] = $c_num1;
$list = '';
foreach ($value1['list'] as $key2 => $value2) {
$c_num2 = $this->mdCustomerOpLogs->count(['uid' => $sale_id, 'type' => 4, 'log' => '客户到店', 'c_time>=' => $s_time, 'c_time<=' => $e_time,
"customer_id in(select id from lc_receiver_customers where of_id={$key1} and of2_id={$key2}
and admin_id={$sale_id} and biz_id={$biz_id} and cs_biz_id!=-1)" => null], 'distinct(customer_id)');
if ($c_num2) {//二级
$list[$key2] = ['name' => $value2, 'num' => $c_num2];
}
}
$c_num_json[$key1] = ['name' => $value1['name'], 'num' => $c_num1, 'list' => $list];
}
//订单数
$orders1 = $this->mdOrdersV2->count(['sale_id' => $sale_id, 'biz_id' => $biz_id, 'status>=' => 0,
'order_time>=' => "{$value['log_date']} 00:00:00", 'order_time<=' => "{$value['log_date']} 23:59:59",
"customer_id in(select id from lc_receiver_customers where of_id={$key1} and admin_id={$sale_id}
and biz_id={$biz_id} and cs_biz_id!=-1)" => null]);
if ($orders1) {//一级
$update_item["order_{$key1}"] = $orders1;
$list = '';
foreach ($value1['list'] as $key2 => $value2) {
$orders2 = $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",
"customer_id in(select id from lc_receiver_customers where of_id={$key1} and of2_id={$key2}
and admin_id={$sale_id} and biz_id={$biz_id} and cs_biz_id!=-1)" => null]);
if ($orders2) {//二级
$list[$key2] = ['name' => $value2, 'num' => $orders2];
}
}
$order_json[$key1] = ['name' => $value1['name'], 'num' => $orders1, 'list' => $list];
}
}
$c_num_json && $update_item['c_num_json'] = json_encode($c_num_json, JSON_UNESCAPED_UNICODE);
$order_json && $update_item['order_json'] = json_encode($order_json, JSON_UNESCAPED_UNICODE);
if ($update_item) {
$this->mdUsersLog->update($update_item, ['id' => $value['id']]);
$log[] = ['id' => $value['id'], 'biz_id' => $value['biz_id'], 'log_date' => $value['log_date']];
$counts++;
}
}
echo '
成功更新:';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
}
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_users_log?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新门店日志
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_bizs_log
* https://api.liche.cn/plan/temp/receiver_bizs_log
*/
public function receiver_bizs_log()
{
$param = $this->input->get();
$page = intval($param['page']);
!$page && $page = 0;
ob_start(); //打开缓冲区
$log_date = date("Y-m-d", strtotime("+{$page} day", strtotime("2022-04-15")));
echo "log_date={$log_date}
";
if ($log_date >= date("Y-m-d")) {
echo '
本次更新门店日志完成了:';
echo '
成功更新 ' . $param['page'] . ' 次';
echo '
点击将再次更新门店日志>>>';
exit;
}
$log = [];
$this->load->model("biz/biz_model", 'mdBiz');
$this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog');
$this->load->model('app/licheb/app_licheb_bizs_log_model', 'mdBizsLog');
$res = $this->mdBiz->select(['status' => 1], 'id asc', 0, 0, 'id,type,city_id');
foreach ($res as $key => $value) {
$biz_id = $value['id'];
if ($biz_id == 1 || $biz_id == 110) {//门店不写入
continue;
}
$re = $this->mdBizsLog->get(['biz_id' => $biz_id, 'log_date' => $log_date]);
if ($re) {
continue;
}
$a_num = $t_num = $bills = $follows = $defeats = $qy_adds = $qy_dels = $reassigns = $receives = 0;
$c_num = $orders = $customers = 0;
$c_num_ary = $order_ary = $customer_ary = [];
$c_num_json = $order_json = $customer_json = '';
$res2 = $this->mdUsersLog->select(['biz_id' => $biz_id, 'log_date' => $log_date], 'id asc');
foreach ($res2 as $key2 => $value2) {
$c_num += $value2['c_num'];
$orders += $value2['orders'];
$customers += $value2['customers'];
$a_num += $value2['a_num'];
$t_num += $value2['t_num'];
$bills += $value2['bills'];
$follows += $value2['follows'];
$defeats += $value2['defeats'];
$qy_adds += $value2['qy_adds'];
$qy_dels += $value2['qy_dels'];
$reassigns += $value2['reassigns'];
$receives += $value2['receives'];
//一级统计
for ($ii = 1; $ii < 5; ++$ii) {
$c_num_ary[$ii] += $value2['c_num_' . $ii];
$order_ary[$ii] += $value2['order_' . $ii];
$customer_ary[$ii] += $value2['customer_' . $ii];
}
//详情统计
if ($value2['c_num_json']) {
$c_num_json_u = json_decode($value2['c_num_json'], true);
foreach ($c_num_json_u as $k1 => $v1) {
$list = '';
foreach ($v1['list'] as $k2 => $v2) {
$num2 = intval($c_num_json[$k1]['list'][$k2]['num']) + $v2['num'];
//二级
$num2 && $list[$k2] = ['name' => $v2['name'], 'num' => $num2];
}
$num1 = intval($c_num_json[$k1]['num']) + $v1['num'];
$c_num_json[$k1] = ['name' => $v1['name'], 'num' => $num1, 'list' => $list];
}
}
if ($value2['order_json']) {
$order_json_u = json_decode($value2['order_json'], true);
foreach ($order_json_u as $k1 => $v1) {
$list = '';
foreach ($v1['list'] as $k2 => $v2) {
$num2 = intval($order_json[$k1]['list'][$k2]['num']) + $v2['num'];
//二级
$num2 && $list[$k2] = ['name' => $v2['name'], 'num' => $num2];
}
$num1 = intval($order_json[$k1]['num']) + $v1['num'];
$order_json[$k1] = ['name' => $v1['name'], 'num' => $num1, 'list' => $list];
}
}
if ($value2['customer_json']) {
$customer_json_u = json_decode($value2['customer_json'], true);
foreach ($customer_json_u as $k1 => $v1) {
$list = '';
foreach ($v1['list'] as $k2 => $v2) {
$num2 = intval($customer_json[$k1]['list'][$k2]['num']) + $v2['num'];
//二级
$num2 && $list[$k2] = ['name' => $v2['name'], 'num' => $num2];
}
$num1 = intval($customer_json[$k1]['num']) + $v1['num'];
$customer_json[$k1] = ['name' => $v1['name'], 'num' => $num1, 'list' => $list];
}
}
}
$add_item = ['biz_id' => $biz_id, 'type' => $value['type'], 'city_id' => $value['city_id'], 'c_num' => $c_num
, 'a_num' => $a_num, 't_num' => $t_num, 'orders' => $orders, 'bills' => $bills, 'follows' => $follows, 'defeats' => $defeats
, 'log_date' => $log_date, 'qy_adds' => $qy_adds, 'qy_dels' => $qy_dels, 'reassigns' => $reassigns, 'receives' => $receives, 'c_time' => time()];
for ($ii = 1; $ii < 5; ++$ii) {
$add_item['c_num_' . $ii] = intval($c_num_ary[$ii]);
$add_item['order_' . $ii] = intval($order_ary[$ii]);
$add_item['customer_' . $ii] = intval($customer_ary[$ii]);
}
$c_num_json && $add_item['c_num_json'] = json_encode($c_num_json, JSON_UNESCAPED_UNICODE);
$order_json && $add_item['order_json'] = json_encode($order_json, JSON_UNESCAPED_UNICODE);
$customer_json && $add_item['customer_json'] = json_encode($customer_json, JSON_UNESCAPED_UNICODE);
$id = $this->mdBizsLog->add($add_item);
if ($id) {
$log[] = ['id' => $id, 'biz_id' => $biz_id, 'mobile' => $log_date];
}
}
echo '
成功新增:';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
}
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_bizs_log?page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:车主企业微信/城市
* Created on: 2022/6/21 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_owners_wxqy
* https://api.liche.cn/plan/temp/receiver_owners_wxqy
*/
public function receiver_owners_wxqy()
{
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders');
$this->load->model("biz/biz_model", 'mdBiz');
$this->load->model('app/liche/app_liche_users_model', 'mdUsers');
$this->load->model('receiver/receiver_owners_model', 'mdOwners');
$this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 100;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ['status>=' => 0];
$id = intval($param['id']);
if ($id) {
$where['id>='] = $id;
}
$res = $this->mdOwners->select($where, 'id asc', $param['page'], $param['size'], 'id,o_id,mobile');
if (!$res) {
echo '
本次更新完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
$update = '';
if ($value['o_id']) {//查找门店城市
$re_ord = $this->mdOrders->get(['id' => $value['o_id']]);
if ($re_ord['biz_id']) {
$re_biz = $this->mdBiz->get(['id' => $re_ord['biz_id']]);
if ($re_biz) {
$update['province_id'] = $re_biz['province_id'];
$update['city_id'] = $re_biz['city_id'];
$update['county_id'] = $re_biz['county_id'];
}
}
}
if ($value['mobile']) {//查找企微
$re_qy = $this->mdWechatqy->get(['mobile' => $value['mobile']]);
if ($re_qy) {
$update['wxqy'] = 1;
} else {
$re_use = $this->mdUsers->get(['mobile' => $value['mobile'], 'status<>' => -1]);
if ($re_use['unionid']) {
$re_qy = $this->mdWechatqy->get(['unionid' => $re_use['unionid']]);
$re_qy && $update['wxqy'] = 1;
}
}
}
if ($update) {
$this->mdOwners->update($update, ['id' => $value['id']]);
$log[] = array_merge($update, ['mobile' => $value['mobile']]);
$counts++;
}
}
echo '
成功更新:';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
}
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_owners_wxqy?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:加车主(状态交易完成)
* Created on: 2022/5/27 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_owners
* https://api.liche.cn/plan/temp/receiver_owners
*/
public function receiver_owners()
{
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders');
$this->load->model('receiver/order/receiver_order_agents_model', 'mdOrdersAgents');
$this->load->model('app/liche/app_liche_users_model', 'mdUsers');
$this->load->model('receiver/receiver_owners_model', 'mdOwners');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 100;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$t1 = 'lc_receiver_orders_v2';
$t2 = 'lc_receiver_order_status';
$where = ["{$t1}.status>=" => 0, "{$t1}.owner_name<>" => '', "{$t1}.owner_mobile<>" => '', "{$t2}.pid_status" => 5, "{$t2}.status" => 1];
$having = "total >= 1";
$orderby = "{$t2}.c_time asc";
$fileds = "{$t1}.id,{$t1}.brand_id,{$t1}.s_id,{$t1}.v_id,{$t1}.owner_name,{$t1}.owner_mobile,{$t1}.order_time,{$t1}.ck_time
,{$t1}.info_json";
//$count = $this->mdOrders->selectOrders($where, '', '', '', 1, '', $having);
$res = $this->mdOrders->selectOrders($where, $orderby, $param['page'], $param['size'], '', $fileds, $having);
if (!$res) {
echo '
本次更新完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新>>>';
exit;
}
$str_o_ids = implode(',', array_unique(array_column($res, 'id')));
$map_agents = $this->mdOrdersAgents->map('o_id', 'car_num', ["o_id in({$str_o_ids})" => null]);
$str_mobiles = implode(',', array_unique(array_column($res, 'owner_mobile')));
$map_users = $this->mdUsers->map('mobile', 'id', ["mobile in({$str_mobiles})" => null]);
$log = array();
foreach ($res as $key => $value) {
$birth_day = '0000-00-00';
$sex = 0;
if ($value['info_json']) {
$info_json = json_decode($value['info_json'], true);
if ($info_json['c_owner_cardid']) {
$cardid = $info_json['c_owner_cardid'];
$birth_day = date('Y-m-d', strtotime(substr($cardid, 6, 8)));
$sex = substr($cardid, -2, 1) % 2 == 0 ? 2 : 1; //1为男 2为女
}
}
$uid = intval($map_users[$value['owner_mobile']]);
$car_num = $map_agents[$value['id']] ? $map_agents[$value['id']] : '';
$data = ['o_id' => $value['id'], 'uid' => $uid, 'name' => $value['owner_name'], 'mobile' => $value['owner_mobile'],
'birth_day' => $birth_day, 'sex' => $sex, 'brand_id' => $value['brand_id'], 's_id' => $value['s_id'],
'v_id' => $value['v_id'], 'order_time' => $value['order_time'], 'ck_time' => $value['ck_time'], 'car_num' => $car_num];
$re = $this->mdOwners->get(['o_id' => $value['id']]);
if ($re) {
$this->mdOwners->update($data, ['id' => $re['id']]);
} else {
$data['c_time'] = time();
$id = $this->mdOwners->add($data);
if ($id) {
$log[] = ['id' => $id, 'name' => $data['name'], 'mobile' => $data['mobile']];
$counts++;
}
}
}
echo '
成功新增:';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
}
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_owners?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新企微好友
* Created on: 2022/5/27 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/customers_wxqy
* https://api.liche.cn/plan/temp/customers_wxqy
*/
public function customers_wxqy()
{
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$this->load->model('app/licheb/App_licheb_users_model', 'mdUsers');
$this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 100;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ["status" => 1];
$res = $this->mdWechatqy->select($where, 'id ASC', $param['page'], $param['size'], 'userid,mobile');
if (!$res) {
echo '
本次更新完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
if ($value['userid'] && $value['mobile']) {
$mobile = $value['mobile'];
$re_use = $this->mdUsers->get(array('userid' => $value['userid']));
$biz_id = $re_use && $re_use['biz_id'] ? intval($re_use['biz_id']) : 0;
if ($biz_id) {
$where_cust = ['biz_id' => $biz_id, 'mobile' => $mobile, 'wxqy' => 0];
$re_cust = $this->mdCustomers->get($where_cust);
if ($re_cust) {
$this->mdCustomers->update(['wxqy' => 1], $where_cust);
$log[] = ['mobile' => $value['mobile'], 'biz_id' => $biz_id];
$counts++;
}
}
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/customers_wxqy?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新下架门店人员
* Created on: 2022/5/27 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/biz_users
* https://api.liche.cn/plan/temp/biz_users
*/
public function biz_users()
{
$this->load->model("biz/biz_model", 'mdBiz');
$this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 100;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ["status<>" => 1];
$res = $this->mdBiz->select($where, 'id ASC', $param['page'], $param['size'], 'id,status');
if (!$res) {
echo '
本次更新完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
$ret = $this->mdUsers->update(['status' => $value['status']], ['biz_id' => $value['id'], 'group_id < 4' => null]);//更新用户下架
if ($ret == 1) {
$log[] = ['id' => $value['id']];
$counts++;
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/biz_users?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新战败客户到店
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/material_template
* https://api.liche.cn/plan/temp/material_template
*/
public function material_template()
{
$this->load->model('app/material/Material_template_model', 'mdTemplate');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 100;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ["id>" => 0];
$res = $this->mdTemplate->select($where, 'id ASC', $param['page'], $param['size'], 'id,brand_ids');
if (!$res) {
echo '
本次更新完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
$brand_ids = $value['brand_ids'];
if ($brand_ids) {
if (!strstr($brand_ids, '0,')) {
$brand_ids = '0,' . $brand_ids;
$ret = $this->mdTemplate->update(['brand_ids' => $brand_ids], ['id' => $value['id']]);
if ($ret == 1) {
$log[] = ['id' => $value['id'], 'brand_ids' => $brand_ids];
$counts++;
}
}
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/material_template?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新战败客户到店
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_customers_wxqy
* https://api.liche.cn/plan/temp/receiver_customers_wxqy
*/
public function receiver_customers_wxqy()
{
$this->load->model('app/app_lichene_qy_log_model', 'mdWechatqyLog');
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$this->load->model('app/licheb/App_licheb_users_model', 'mdUsers');
$this->load->library('wx_qyapi', ['app' => 'lichene']);
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 2;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ["change_type<>" => 'edit_external_contact'];
$res = $this->mdWechatqyLog->select($where, 'c_time ASC', $param['page'], $param['size']);
if (!$res) {
echo '
本次更新完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
if ($value['userid'] && $value['external_userid']) {
$re_wx = $this->wx_qyapi->get_external_contact(array('url' => 'user_get', 'userid' => $value['userid']));
if ($re_wx['errcode'] == 0 && $re_wx['mobile']) {//获取企业成员手机
$re_use = $this->mdUsers->get(array('mobile' => $re_wx['mobile']));
$biz_id = intval($re_use['biz_id']);
if ($biz_id) {
$re_wx = $this->wx_qyapi->get_external_contact(array('url' => 'get', 'external_userid' => $value['external_userid']));
if ($re_wx['errcode'] == 0) {
$follow_user = [];
foreach ($re_wx['follow_user'] as $key => $val) {
if ($val['userid'] == $value['userid']) {//找出当前企业员工
$follow_user = $val;
break;
}
}
$remark_mobiles = $follow_user['remark_mobiles'];//用户手机
if ($remark_mobiles && $remark_mobiles != '[]' && is_array($remark_mobiles)) {
$mobile = $remark_mobiles[0];//取第一个手机号
if ($mobile) {
if ($value['change_type'] == 'add_external_contact') {//新增
$wxqy = 1;
} else {//删除
$wxqy = -1;
}
$ret = $this->mdCustomers->update(['wxqy' => $wxqy], ['mobile' => $mobile, 'biz_id' => $biz_id]);
if ($ret == 1) {
$log[] = ['mobile' => $mobile, 'biz_id' => $biz_id, 'wxqy' => $wxqy];
$counts++;
}
}
}
}
}
}
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_customers_wxqy?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新战败客户到店
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/users_log_t_num
* https://api.liche.cn/plan/temp/users_log_t_num
*/
public function users_log_t_num()
{
$this->load->model('receiver/receiver_customer_oplogs_model', 'mdCustomerOplogs');
$this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 200;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = ["log_date>=" => '2022-04-15', 'a_num>0 OR follows>0' => null];
$res = $this->mdUsersLog->select($where, 'id ASC', $param['page'], $param['size'], 'id,sale_id,biz_id,log_date');
if (!$res) {
echo '
本次更新完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
$sale_id = $value['sale_id'];
$biz_id = $value['biz_id'];
$s_time = strtotime($value['log_date'] . ' 00:00:00');
$e_time = strtotime($value['log_date'] . ' 23:59:59');
$t_num = $this->mdCustomerOplogs->count(['uid' => $sale_id, 'type' => 5, '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]);
if ($t_num) {
$this->mdUsersLog->update(['t_num' => $t_num], ['id' => $value['id']]);
$log[] = ['id' => $value['id'], 't_num' => $t_num];
$counts++;
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/users_log_t_num?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新车辆调拨状态
* Created on: 2022/2/28 17:15
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/licheb/inventory_log
* https://api.liche.cn/plan/licheb/inventory_log
*/
public function inventory_log()
{
$params = $this->input->get();
$size = 100;//每次最多处理多少条
$rds = intval($this->input->get('rds'));
$redis = &load_cache('redis');
$redisKey = 'inventory_log_id';
$id = $redis->get($redisKey);
!$id && $id = 0;
if ($rds) {//手动清除缓存
$id = 0;
$redis->delete($redisKey);
}
$log = array();
$this->load->model('items/Items_inventory_log_model', 'mdInventoryLog');
$this->load->model('items/items_model', 'mdItems');
$where = array('id >' => $id, 'status' => 0);
$res_log = $this->mdInventoryLog->select($where, 'id asc', 1, $size, 'id,item_id,biz_id,addr_id');
if (!$res_log) {
echo '执行到当前id:' . $id . '暂无数据';
$redis->delete($redisKey);
return;
}
foreach ($res_log as $key => $value) {
$id = $value['id'];
$res_item = $this->mdItems->get(['id' => $value['item_id']]);
if ($res_item) {
$status = '';
if ($res_item['bill_time'] != '0000-00-00 00:00:00') {//已售
$status = -2;
} else if ($res_item['biz_id'] != $value['biz_id'] || $res_item['addr_id'] != $value['addr_id']) {//已调拨
$status = -1;
}
if ($status) {
$ret = $this->mdInventoryLog->update(['status' => $status], ['id' => $id]);
if ($ret) {
$log[] = array('id' => $id, 'status' => $status);
}
}
}
}
$redis->save($redisKey, $id);//保存最后id
if ($params['sd']) {
echo '
执行到当前id:' . $id;
echo '
成功更新:
';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
echo '
';
}
echo '数据库获取:
';
echo json_encode($res_log, JSON_UNESCAPED_UNICODE);
}
}
/**
* Notes:更新车辆调拨异常
* Created on: 2022/1/4 13:53
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/licheb/transfer_abnormal
* https://api.liche.cn/plan/licheb/transfer_abnormal
*/
public function transfer_abnormal()
{
$this->load->model('items/items_transfer_model', 'mdTransfer');
$params = $this->input->get();
$ret = '';
if ($params['id']) {
$abnormal = intval($params['abnormal']);
$ret = $this->mdTransfer->update(['abnormal' => $abnormal], ['id' => $params['id']]);
}
if ($ret) {
echo "更新异常成功_{$params['id']}_$abnormal";
} else {
echo "更新异常失败";
}
}
/**
* Notes:更新客户线下来源
* Created on: 2022/3/09 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_customer_of
* https://api.liche.cn/plan/temp/receiver_customer_of
*/
public function receiver_customer_of()
{
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$param = $this->input->get();
if ($param['up_id']) {
$ret = $this->mdCustomers->update(['of_id' => 3, 'of2_id' => 37], ['id' => $param['up_id']]);
echo $ret ? '
更新成功:' : '
更新失败:';
exit;
}
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = array("cf_id" => 29);
$res = $this->mdCustomers->select($where, 'id ASC', $param['page'], $param['size'], 'id,of_id');
if (!$res) {
echo '
本次更新客户线下来源完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新客户线下来源>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
if (!$value['of_id']) {
$this->mdCustomers->update(['of_id' => 5, 'of2_id' => 53], ['id' => $value['id']]);
$log[] = array('id' => $value['id'], 'of_id' => 5);
$counts++;
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_customer_of?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:新增街道
* Created on: 2021/12/14 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/add_street
* https://api.liche.cn/plan/temp/add_street
*/
public function add_street()
{
$this->load->model('sys/Sys_area_model', 'mdSysArea');
$this->load->model('sys/Sys_street_model', 'mdSysStreet');
$this->load->model('sys/Bs_street_model', 'mdBsStreet');//表已经删除
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 5;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$res = $this->mdSysArea->select(['status' => 1], 'id ASC', $param['page'], $param['size'], 'county_id');
if (!$res) {
echo '
本次新增街道完成了:';
echo '
成功新增街道 ' . $counts . ' 条';
echo '
点击将再次新增街道>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
$res_bs = $this->mdBsStreet->select(['AREA_CODE' => $value['county_id']], 'STREET_ID ASC', 0, 0, 'STREET_CODE,STREET_NAME');
$add = [];
foreach ($res_bs as $key2 => $value2) {
$add[] = ['county_id' => $value['county_id'], 'street_id' => $value2['STREET_CODE'], 'street_name' => $value2['STREET_NAME']];
$log[] = array('street_name' => $value2['STREET_NAME'], 'street_id' => $value2['STREET_CODE']);
$counts++;
}
if ($add) {
$this->mdSysStreet->add_batch($add);
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/add_street?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新狸车宝渠道门店
* Created on: 2021/9/18 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/channel_biz
* https://api.liche.cn/plan/temp/channel_biz
*/
public function channel_biz()
{
$this->load->model('app/licheb/App_licheb_users_model', 'mdUsers');
$this->load->model('app/licheb/App_licheb_channel_biz_model', 'mdChannelBiz');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = array('status ' => 1, 'group_id' => 4);
$res = $this->mdUsers->select($where, 'id ASC', $param['page'], $param['size'], 'id,biz_id,uname');
if (!$res) {
echo '
本次更新狸车宝渠道门店完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新狸车宝渠道门店>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
if ($value['biz_id']) {
$biz_id_arr = explode(',', $value['biz_id']);
foreach ($biz_id_arr as $key2 => $value2) {
$where = ["uid" => $value['id'], 'biz_id' => $value2];
$re_cb = $this->mdChannelBiz->get($where);
if (!$re_cb) {
$where['c_time'] = time();
$this->mdChannelBiz->add($where);
}
}
$log[] = array('uname' => $value['uname'], 'biz_id' => $value['biz_id']);
$counts++;
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/channel_biz?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新商品操作日志
* Created on: 2021/9/18 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/items_oplogs
* https://api.liche.cn/plan/temp/items_oplogs
*/
public function items_oplogs()
{
$this->load->model('items/items_model', 'mdItems');
$this->load->model('items/items_oplogs_model', 'mdItemsOplogs');
$this->load->library('entity/items_entity');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = array('status >' => 0, 'in_time <>' => '0000-00-00 00:00:00');
$res = $this->mdItems->select($where, 'id ASC', $param['page'], $param['size'], 'id,biz_id,addr_id,in_time');
if (!$res) {
echo '
本次更新商品操作日志完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新商品操作日志>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
$re_c = $this->mdItemsOplogs->get(array('item_id' => $value['id'], 'biz_id' => $value['biz_id'], 'type' => 1));
if (!$re_c['id']) {
if ($value['biz_id'] == -1 && !$value['addr_id']) {
continue;
}
$params = array('item_id' => $value['id'], 'type' => 1, 'uid' => 0, 'uname' => '系统'
, 'com_time' => $value['in_time'], 'biz_id' => $value['biz_id'], 'addr_id' => $value['addr_id']);
$this->items_entity->add_log($params);
$log[] = array('id' => $value['id']);
$counts++;
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/items_oplogs?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
/**
* Notes:更新客户表来源id
* Created on: 2021/9/18 11:58
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/temp/receiver_customer
* https://api.liche.cn/plan/temp/receiver_customer
*/
public function receiver_customer()
{
$this->load->model('receiver/receiver_clues_model', 'mdClues');
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$counts = intval($param['counts']);
ob_start(); //打开缓冲区
$where = array('rid >' => 0);
$res = $this->mdCustomers->select($where, 'id ASC', $param['page'], $param['size'], 'id,rid,cf_id');
if (!$res) {
echo '
本次更新客户来源id完成了:';
echo '
成功更新 ' . $counts . ' 条';
echo '
点击将再次更新客户来源id>>>';
exit;
}
$log = array();
foreach ($res as $key => $value) {
$re_c = $this->mdClues->get(array('id' => $value['rid']));
if ($re_c['cf_id']) {
$this->mdCustomers->update(array('cf_id' => $re_c['cf_id']), array('id' => $value['id']));
$log[] = array('id' => $value['id'], 'cf_id' => $re_c['cf_id']);
$counts++;
}
}
echo '
成功更新:';
$log && print_r($log);
echo '
数据库获取:';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
header('refresh:3;url=/plan/temp/receiver_customer?counts=' . $counts . '&size=' . $param['size'] . '&page=' . ($param['page'] + 1));
ob_end_flush();//输出全部内容到浏览器
}
//更新下定时间
public function order_time()
{
$this->load->model('receiver/order/receiver_orders_model');
$this->load->model('app/liche/app_liche_orders_model');
$param = $this->input->get();
$param['page'] = intval($param['page']);
$param['size'] = intval($param['size']);
!$param['size'] && $param['size'] = 50;
!$param['page'] && $param['page'] = 1;
$where = [
'status>' => 0,
'order_time' => '0000-00-00 00:00:00',
];
$rows = $this->receiver_orders_model->select($where, 'id ASC', $param['page'], $param['size'], 'id');
if ($rows) {
foreach ($rows as $key => $val) {
$pay_row = $this->app_liche_orders_model->get(['o_id' => $val['id'], 'status' => 1, 'type' => 1]);
if (!$pay_row) {
$pay_row = $this->app_liche_orders_model->get(['o_id' => $val['id'], 'status' => 1, 'type' => 4]);
}
if ($pay_row) {
$this->receiver_orders_model->update(['order_time' => $pay_row['pay_time']], ['id' => $val['id']]);
}
}
$ids = implode(',', array_column($rows, 'id'));
echo "do:{$ids} ";
} else {
echo 'finish';
}
}
//创建支付订单
public function c_payorder()
{
$this->load->model('receiver/order/receiver_orders_model');
$this->load->model('app/liche/app_liche_users_model');
$this->load->model('app/liche/app_liche_orders_model');
$this->load->library('receiver/orders_entity');
$params = $this->input->get();
$params['page'] = intval($params['page']);
$params['size'] = intval($params['size']);
!$params['size'] && $params['size'] = 10;
!$params['page'] && $params['page'] = 1;
if ($params['id']) {
$where = [
'id' => $params['id']
];
} else {
$where = [
'status>' => 0,
'status<' => 3,
'biz_id !=' => 1
];
}
$rows = $this->receiver_orders_model->select($where, 'id asc', $params['page'], $params['size']);
if ($rows) {
$data = [];
foreach ($rows as $key => $val) {
$userinfo = $this->app_liche_users_model->get(['mobile' => $val['mobile']]);
$result = $this->orders_entity->check_finish_v2($val['id'], $userinfo);
$data[] = [
'id' => $val['id'],
'result' => $result,
];
}
echo json_encode($data, JSON_UNESCAPED_UNICODE);
} else {
echo 'finish';
}
}
}