temp_905
This commit is contained in:
@@ -16,6 +16,116 @@ class Temp extends HD_Controller
|
||||
$this->log_file = 'temp.log';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 '<br>本次更新车主完成了:';
|
||||
echo '<br><br>成功更新 <span style="color: red;">' . $counts . '</span> 条';
|
||||
echo '<br><br><a href="/plan/temp/add_owners">点击将再次更新车主>>></a>';
|
||||
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 '<br>成功更新:';
|
||||
$log && print_r($log);
|
||||
echo '<br><br>数据库获取:';
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user