input->get();
$hour = date('H.i');
if (($hour > 22.00 && $hour < 23.55) || $params['sd']) {
if ($params['sd']) {
echo "开始执行车主[{$hour}]";
}
} else {
echo '[22.00-23.55]执行车主[' . $hour . ']';
return;
}
$size = 200;//每次最多处理多少条
$rds = intval($this->input->get('rds'));
$redis = &load_cache('redis');
$log_date = date('Y-m-d');
$redisKey = 'lc_receiver_owners_id_' . $log_date;
if ($rds) {
$redis->delete($redisKey);
}
$id = $redis->get($redisKey);
!$id && $id = 0;
$log = [];
$where = ['a.id>' => $id, 'a.wxqy' => 0];
$res = $this->db->select('a.id,a.mobile,a.u_time,b.admin_id,b.biz_id')
->from('lc_receiver_owners as a')
->join('lc_receiver_orders_v2 as b', "b.id=a.o_id", 'left')
->where($where)
->order_by('a.id asc')
->limit($size, 0)
->get()->result_array();
if (!$res) {
echo '执行到车主id:' . $id . '暂无数据';
return;
}
$this->load->model('receiver/receiver_owners_model', 'mdOwners');
$this->load->model("biz/biz_model", 'mdBiz');
$this->load->model('app/licheb/app_licheb_users_model', 'mdUsers');
$this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
$this->load->model('app/app_different_qy_model', 'mdDifferentQy');
$str_biz_ids = implode(',', array_unique(array_column($res, 'biz_id')));
$map_biz = $this->mdBiz->map('id', 'city_id,type,status', ["id in({$str_biz_ids})" => null]);
$str_user_ids = implode(',', array_unique(array_column($res, 'admin_id')));
$map_user = $this->mdUsers->map('id', 'userid', ["id in({$str_user_ids})" => null]);
foreach ($res as $key => $value) {
$id = $value['id'];
$biz_type = intval($map_biz[$value['biz_id']]['type']);
$userid = $map_user[$value['admin_id']];
if ($userid) {
if ($biz_type == 5) {//异业店
$re = $this->mdDifferentQy->get(['userid' => $userid, 'mobile' => $value['mobile']]);
} else {
$re = $this->mdWechatqy->get(['userid' => $userid, 'mobile' => $value['mobile']]);
}
if ($re) {//更新企微好友
$this->mdOwners->update(['wxqy' => 1, 'u_time' => $value['u_time']], ['id' => $id]);
$params['sd'] && $log[] = ['id' => $id, 'mobile' => $value['mobile']];
}
}
}
$redis->save($redisKey, $id, 24 * 3600);//保存最后id
if ($params['sd']) {
echo '
执行到当前车主id:' . $redis->get($redisKey);
echo '
成功新增:
';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
echo '
';
}
echo '数据库获取:
';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
}
}
/**
* Notes:新增车主信息
* Created on: 2022/6/14 17:15
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/liche/add_owners?rds=1
* https://api.liche.cn/plan/liche/add_owners
*/
public function add_owners()
{
$params = $this->input->get();
$size = 5000;//每次最多处理多少条
$rds = intval($this->input->get('rds'));
$redis = &load_cache('redis');
$redisKey = 'receiver_owners_c_time';
if ($rds) {
$redis->delete($redisKey);
}
$c_time = $redis->get($redisKey);
!$c_time && $c_time = strtotime(date('Y-m-d') . ' 00:00:00');
$log = array();
$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');
$t1 = 'lc_receiver_orders_v2';
$t2 = 'lc_receiver_order_status';
$where = ["{$t2}.c_time>=" => $c_time, "{$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,{$t1}.biz_id,{$t2}.c_time";
$res = $this->mdOrders->selectOrders($where, $orderby, 1, $size, '', $fileds, $having);
if (!$res) {
if ($params['rds']) {
echo '1执行到当前c_time:' . date('Y-m-d H:i:s', $c_time) . '暂无数据';
}
return;
}
$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']] : '';
$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];
$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 && $params['rds']) {
$log[] = ['id' => $id, 'name' => $data['name'], 'mobile' => $data['mobile']];
}
}
}
$redis->save($redisKey, $c_time);
if ($params['rds']) {
echo '
2执行到当前c_time:' . date('Y-m-d H:i:s', $c_time);
echo '
成功新增:
';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
echo '
';
}
echo '数据库获取:
';
echo json_encode($res, JSON_UNESCAPED_UNICODE);
}
}
//获取未签名pdf
public function un_sign_pdf()
{
$this->load->model('receiver/order/receiver_order_contracts_model');
$this->load->model('receiver/order/receiver_orders_v2_model');
$this->load->library('receiver/orders_v2_entity');
$row = $this->receiver_order_contracts_model->get(['o_id>=' => Orders_v2_entity::V2_START_ID, 'flag' => 0, 'file !=' => '', 'status' => 1]);
$receiver = $this->receiver_orders_v2_model->get(['id' => $row['o_id']]);
if (file_exists(FCPATH . $row['file']) && $receiver) {
$companys = $this->orders_v2_entity->get_biz_mchid($receiver['biz_id'], $receiver['brand_id']);
$url = http_host_com();
$width = 130;
$s_img = build_qiniu_image_url($companys['company']['img_seal']);
if ($row['type'] == 1) {
$page = 2;
$height = 380;
$s_img = build_qiniu_image_url($companys['srv_company']['img_seal']);
} elseif ($row['type'] == 3) {
$page = 1;
$height = 620;
} else {
$page = 3;
$height = 160;
}
$data = [
'id' => $row['id'],
'o_id' => $row['o_id'],
's_page' => $page,
'width' => $width,
'height' => $height,
's_img' => $s_img,
'file_url' => $url . '/' . $row['file']
];
die(json_encode($data, JSON_UNESCAPED_UNICODE));
} else {
$this->receiver_order_contracts_model->update(['flag' => 1], ['id' => $row['id']]);
}
}
//覆盖pdf文件
public function up_pdf()
{
$this->load->model('receiver/order/receiver_order_contracts_model');
$id = $this->input->post('id');
$row = $this->receiver_order_contracts_model->get(['id' => $id, 'flag' => 0]);
if ($row) {
$file_path_arr = explode('/', $row['file']);
// $file_name = array_pop($file_path_arr);
// $file_name = 'test.pdf';
// $file_path = implode('/',$file_path_arr);
// $res = move_uploaded_file($_FILES['file']['tmp_name'],FCPATH.$file_path.'/'.$file_name);
move_uploaded_file($_FILES['file']['tmp_name'], FCPATH . $row['file']);
$res = $this->receiver_order_contracts_model->update(['flag' => 1], ['id' => $row['id']]);
if ($res) {
$data = [
'code' => 1,
'msg' => '保存成功'
];
die(json_encode($data, JSON_UNESCAPED_UNICODE));
}
}
}
}