Files
liche/api/controllers/plan/Liche.php
T
2022-06-21 17:11:32 +08:00

231 lines
9.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Notes:博饼任务
* Created on: 2021/8/20 17:15
* Created by: dengbw
*/
class Liche extends HD_Controller
{
public function __construct()
{
parent::__construct();
}
/**
* Notes:更新车主企业微信
* Created on: 2022/6/21 16:00
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/plan/liche/owners_wxqy?rds=1
* https://api.liche.cn/plan/liche/owners_wxqy
*/
public function owners_wxqy()
{
$params = $this->input->get();
$size = 100;//每次最多处理多少条
$rds = intval($this->input->get('rds'));
$redis = &load_cache('redis');
$redisKey = 'update_owners_wxqy_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 = [];
$this->load->model('app/app_lichene_qy_log_model', 'mdWechatqyLog');
$this->load->model('app/app_lichene_qy_model', 'mdWechatqy');
$this->load->model('receiver/receiver_owners_model', 'mdOwners');
$this->load->model('app/liche/app_liche_users_model', 'mdUsers');
$res = $this->mdWechatqyLog->select(["c_time>=" => $c_time, "change_type in('add_external_contact','edit_external_contact')" => null]
, 'c_time asc', 1, $size, 'change_type,external_userid,c_time');
if (!$res) {
if ($params['rds']) {
echo '1执行到当前c_time' . date('Y-m-d H:i:s', $c_time) . '暂无数据';
}
return;
}
foreach ($res as $key => $value) {
$c_time = $value['c_time'];
if ($value['external_userid']) {
$re_qy = $this->mdWechatqy->get(['external_userid' => $value['external_userid']]);
$mobile = $re_qy['mobile'];
$type = 1;
if (!$mobile && $re_qy['unionid']) {
$re_use = $this->mdUsers->get(['unionid' => $re_qy['unionid']]);
if ($re_use['mobile']) {
$type = 2;
$mobile = $re_use['mobile'];
}
}
if ($mobile) {
$re_own = $this->mdOwners->get(['mobile' => $mobile]);
if ($re_own) {
$this->mdOwners->update(['wxqy' => 1], ['id' => $re_own['id']]);
if ($params['rds']) {
$log[] = ['mobile' => $mobile, 'type' => $type];
}
}
}
}
}
$redis->save($redisKey, $c_time);
if ($params['rds']) {
echo '<br>2执行到当前c_time' . date('Y-m-d H:i:s', $c_time);
echo '<br>成功新增:<br>';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
echo '<br>';
}
echo '数据库获取:<br>';
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');
$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,{$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];
$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 && $params['rds']) {
$log[] = ['id' => $id, 'name' => $data['name'], 'mobile' => $data['mobile']];
}
}
}
$redis->save($redisKey, $c_time);
if ($params['rds']) {
echo '<br>2执行到当前c_time' . date('Y-m-d H:i:s', $c_time);
echo '<br>成功新增:<br>';
if ($log) {
echo json_encode($log, JSON_UNESCAPED_UNICODE);
echo '<br>';
}
echo '数据库获取:<br>';
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));
}
}
}
}