495 lines
21 KiB
PHP
495 lines
21 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
require_once APPPATH.'controllers/wxapp/Wxapp.php';
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Date: 2021.06.23
|
|
* Time: 14:08
|
|
*/
|
|
class User extends Wxapp{
|
|
|
|
function __construct($inputs, $app_key){
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array('get_ukey');//登录白名单
|
|
$this->majia_white = array('get_ukey', 'get', 'get_my');//超级管理员披上马甲可操作权限
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg =array();//授权微信信息
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_attr_model');
|
|
|
|
$this->load->model('receiver/order/receiver_orders_model','orders_model');
|
|
$this->load->model('receiver/order/receiver_orders_v2_model');
|
|
$this->load->model('app/liche/app_liche_orders_model');
|
|
}
|
|
|
|
/**
|
|
* 获取ukey
|
|
* @return array
|
|
* @throws Exception
|
|
*/
|
|
protected function get_ukey(){
|
|
$code = $this->input_param('code');
|
|
|
|
if(!$code){
|
|
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
|
|
}
|
|
$session = $this->wx_session($code);
|
|
if(!$session['session_key']){
|
|
throw new Exception('登录失败', API_CODE_FAIL);
|
|
}
|
|
$where = array('openid' => $session['openid'], "status <>-1" => null);
|
|
$user = $this->app_user_model->get($where);
|
|
if($user){
|
|
$upd = array();
|
|
!$user['unionid'] && $session['unionid'] && $upd['unionid'] = $session['unionid'];
|
|
$uid = $user['id'];
|
|
if($upd){
|
|
$ret = $this->app_user_model->update($upd, array('id' => $uid));
|
|
if(!$ret){
|
|
debug_log("[error]# code:{$code}; ".$this->app_user_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
throw new Exception('授权用户信息失败', API_CODE_FAIL);
|
|
}
|
|
}
|
|
} else {
|
|
$add = array(
|
|
'openid' => $session['openid'],
|
|
'unionid' => strval($session['unionid']),
|
|
'c_time' => time(),
|
|
);
|
|
|
|
$uid = $this->app_user_model->add($add);
|
|
if(!$uid){
|
|
debug_log("[error]# code:{$code}; ".$this->app_user_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
throw new Exception('授权用户信息失败', API_CODE_FAIL);
|
|
}
|
|
}
|
|
|
|
$udata = array('uid' => $uid, 'session_key' => $session['session_key']);
|
|
$ukey = $this->refresh_login($udata);
|
|
|
|
return array('ukey' => $ukey);
|
|
}
|
|
|
|
/**
|
|
* 用户信息
|
|
* @return array
|
|
*/
|
|
protected function get(){
|
|
$uid = $this->session['uid'];
|
|
|
|
$user = $this->app_user_model->get(array('id' => $uid));
|
|
$jsondata = json_decode($user['jsondata'],true);
|
|
|
|
$istop = 0;
|
|
if($this->session['dealer'] && $this->session['up_uid']==0){
|
|
$istop = 1;
|
|
}
|
|
$data = array(
|
|
'uid' => $uid,
|
|
'mobile' => $user['mobile'],
|
|
'nickname' => $user['nickname'],
|
|
'headimg' => $user['headimg'],
|
|
'alipay' => [
|
|
'name' => $jsondata['alipay']['name'] ? $jsondata['alipay']['name'] : '',
|
|
'account' => $jsondata['alipay']['account'] ? $jsondata['alipay']['account'] : '',
|
|
],
|
|
'isdealer' => $this->session['dealer'],
|
|
'istop' => $istop,
|
|
'credits' => $user['credits']+$user['freeze_credits'],
|
|
'freeze_credits' => $user['freeze_credits'],
|
|
'expire_time' => $user['expire_time'] ? date('Y-m-d H:i',$user['expire_time']) : ''
|
|
);
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 更新用户信息
|
|
* @return array
|
|
* @throws Exception
|
|
*/
|
|
protected function put(){
|
|
$encrypted = $this->input_param('encryptedData');
|
|
$iv = $this->input_param('iv');
|
|
$intro = $this->input_param('intro');
|
|
|
|
//获取用户信息
|
|
$uid = $this->session['uid'];
|
|
$user = $this->app_user_model->get(array('id' => $uid));
|
|
|
|
$upd = array();
|
|
$mobile = '';
|
|
//授权
|
|
if(!is_null($encrypted)){
|
|
if(!$encrypted || !$iv){
|
|
throw new Exception('授权失败', API_CODE_INVILD_PARAM);
|
|
}
|
|
|
|
$wxdata = $this->wx_data($encrypted, $iv);
|
|
|
|
if(!$wxdata){
|
|
throw new Exception('授权失败', API_CODE_FAIL);
|
|
}
|
|
|
|
$openid = $wxdata['openId'];
|
|
$nickname = $wxdata['nickName'];
|
|
$sex = $wxdata['gender'];
|
|
$headimg = $wxdata['avatarUrl'];
|
|
$unionid = $wxdata['unionId'];
|
|
$mobile = $wxdata['phoneNumber'];
|
|
if(!$mobile && isset($wxdata['phoneNumber'])){
|
|
throw new Exception('微信未绑定手机号', API_CODE_FAIL);
|
|
}
|
|
|
|
$mobile && !$user['mobile'] && $upd['mobile'] = $mobile;
|
|
$nickname && $upd['nickname'] = $nickname;
|
|
$headimg && $upd['headimg'] = $headimg;
|
|
|
|
if($mobile){//判断手机号是否重复
|
|
if(!mobile_valid($mobile)){
|
|
throw new Exception("请输入正确的手机号", API_CODE_FAIL);
|
|
}
|
|
$where = array('mobile' => $mobile, 'id <>' => $uid, "status<>" => -1);
|
|
$count = $this->app_user_model->count($where);
|
|
if($count > 0){
|
|
throw new Exception("{$mobile}已被绑", API_CODE_FAIL);
|
|
}
|
|
//更新购车订单用户id
|
|
$order_rows = $this->orders_model->select(['mobile'=>$mobile],'','','id');
|
|
$order_rows && $order_ids = implode(',',array_column($order_rows,'id'));
|
|
if($order_ids){
|
|
$this->app_liche_orders_model->update(['uid'=>$this->session['uid']],["o_id in ($order_ids)"=>null,'uid'=>0]);
|
|
}
|
|
//更新购车订单委托人用户id
|
|
$en_order_rows = $this->orders_model->select(['ifentrust'=>1,"json_extract(info_json,'$.entrust_mobile')='{$mobile}'"=>null],'','','id');
|
|
$en_order_rows && $en_order_ids = implode(',',array_column($en_order_rows,'id'));
|
|
if($en_order_ids){
|
|
$this->app_liche_orders_model->update(['entrust_uid'=>$this->session['uid']],["o_id in ($en_order_ids)"=>null,'entrust_uid'=>0]);
|
|
}
|
|
//更新新的购车订单
|
|
$new_order_rows = $this->receiver_orders_v2_model->select(['mobile'=>$mobile],'','','id');
|
|
$new_order_rows && $new_order_ids = implode(',',array_column($new_order_rows,'id'));
|
|
if($new_order_ids){
|
|
$this->app_liche_orders_model->update(['uid'=>$this->session['uid']],["o_id in ($new_order_ids)"=>null,'uid'=>0]);
|
|
}
|
|
$new_en_order_rows = $this->receiver_orders_v2_model->select(["owner_mobile"=>$mobile],'','','id');
|
|
$new_en_order_rows && $new_en_order_ids = implode(',',array_column($new_en_order_rows,'id'));
|
|
if($new_en_order_ids){
|
|
$this->app_liche_orders_model->update(['entrust_uid'=>$this->session['uid']],["o_id in ($new_en_order_ids)"=>null,'entrust_uid'=>0]);
|
|
}
|
|
}
|
|
|
|
} else {//编辑其他信息
|
|
$userInfo = $this->input_param('userInfo');
|
|
$userInfo['nickName'] && $upd['nickname'] = $userInfo['nickName'];
|
|
$userInfo['avatarUrl'] && $upd['headimg'] = $userInfo['avatarUrl'];
|
|
|
|
if($intro){
|
|
if(mb_strlen($intro, 'utf8') > 20){
|
|
throw new Exception('介绍自己20个字够啦', API_CODE_FAIL);
|
|
}
|
|
$upd['signature'] = $intro;
|
|
}
|
|
}
|
|
|
|
if($upd){
|
|
$ret = $this->app_user_model->update($upd, array('id' => $uid));
|
|
if(!$ret){
|
|
debug_log("[error]# ".$this->app_user_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
throw new Exception('请求失败', API_CODE_FAIL);
|
|
}
|
|
}
|
|
|
|
$data = array(
|
|
'mobile' => $mobile,
|
|
'nickname' => $upd['nickname'] ? $upd['nickname'] : $user['nickname'],
|
|
'headimg' => $upd['headimg'] ? $upd['headimg'] : $user['headimg'],
|
|
);
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 我的
|
|
* @return array
|
|
*/
|
|
protected function get_my(){
|
|
$this->load->library('liche/progressopt');
|
|
$mobile = $this->session['mobile'];
|
|
$where = [
|
|
|
|
];
|
|
$this->app_liche_orders_model->count($where);
|
|
$where = [
|
|
"(uid = {$this->session['uid']} or entrust_uid={$this->session['uid']})" => null,
|
|
'pid' => 0,
|
|
'status>=' => 0,
|
|
'type <>' => 5
|
|
];
|
|
$un_pay = $this->app_liche_orders_model->count($where);
|
|
$about = [
|
|
[
|
|
'title'=>'购车订单',
|
|
'icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-5.png',
|
|
'url'=>'/pages/mine/carOrder/index',
|
|
'have_new' => $un_pay ? true : false
|
|
],
|
|
['title'=>'我的爱车','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-1.png','url'=>'/pages/mine/myCar/index'],
|
|
['title'=>'我的积分','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-6.png','url'=>'/pages/topicActivity/integral/index'],
|
|
['title'=>'联系小狸','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-3.png'],
|
|
];
|
|
if($this->session['dealer'] || $this->session['manage']){
|
|
$about[] = ['title'=>'推广提现','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-4.png','url'=>'/pages/distribute/index'];
|
|
}
|
|
$progress_list = $this->progressopt->lists($mobile);
|
|
$data = [
|
|
//'progressOpt' => $progressOpt,
|
|
//'progress' => $progress,
|
|
'progress_list' => $progress_list,
|
|
'about' => $about,
|
|
'order' => [
|
|
['title' => '全部订单', 'icon' => 'https://qs.haodian.cn/wechat_app/liche/mine/order-icon-1.png', 'url' => '/pages/order/index?typeId=0'],
|
|
['title' => '待付款', 'icon' => 'https://qs.haodian.cn/wechat_app/liche/mine/order-icon-2.png', 'url' => "/pages/order/index?typeId=1"],
|
|
['title' => '进行中', 'icon' => 'https://qs.haodian.cn/wechat_app/liche/mine/order-icon-3.png', 'url' => "/pages/order/index?typeId=2"],
|
|
['title' => '已完成', 'icon' => 'https://qs.haodian.cn/wechat_app/liche/mine/order-icon-4.png', 'url' => "/pages/order/index?typeId=3"],
|
|
],
|
|
];
|
|
return $data;
|
|
}
|
|
//我的爱车
|
|
protected function get_mycar(){
|
|
$this->load->model('receiver/order/receiver_orders_model','orders_model');
|
|
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
!$page && $page = 1;
|
|
!$size && $size = 10;
|
|
$mobile = $this->session['mobile'];
|
|
|
|
$where = [
|
|
"(mobile={$mobile} or (ifentrust=1 and json_extract(info_json,'$.entrust_mobile')='{$mobile}'))" => null,
|
|
"status" => 6,
|
|
];
|
|
$count = $this->orders_model->count($where);
|
|
$lists = [];
|
|
if($count){
|
|
$this->load->model("items/items_model");
|
|
$this->load->model('receiver/order/receiver_order_agents_model','agents_model');
|
|
$rows = $this->orders_model->select($where,'id desc',$page,$size);
|
|
//品牌车型
|
|
$brand_arr = array_unique(array_column($rows,'brand_id'));
|
|
$brands = $this->auto_brand_model->get_map_by_ids($brand_arr,'id,name');
|
|
//车系车型
|
|
$series_arr = array_unique(array_column($rows,'s_id'));
|
|
$series = $this->auto_series_model->get_map_by_ids($series_arr,'id,name');
|
|
|
|
foreach($rows as $key=>$val){
|
|
$item = $this->items_model->get(['id'=>$val['item_id']],'vin');
|
|
$agent = $this->agents_model->get(['o_id'=>$val['id']]);
|
|
$color = $this->auto_attr_model->get(['id'=>$val['cor_id']],'title,jsondata');
|
|
$color && $color['jsondata'] = json_decode($color['jsondata'],true);
|
|
$agent['ins_time'] = $agent['ins_time'] ? date('Y.m.d',strtotime($agent['ins_time'])):'';
|
|
|
|
$brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : '';
|
|
$serie_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : '';
|
|
|
|
$car_img = [];
|
|
if($agent['car_img']){
|
|
$car_img[] = build_qiniu_image_url($agent['car_img']);
|
|
}
|
|
$ins_img = [];
|
|
if($agent['ins_img']){
|
|
$ins_imgs = json_decode($agent['ins_img']);
|
|
foreach($ins_imgs as $key =>$val){
|
|
$ins_img[] = build_qiniu_image_url($val);
|
|
}
|
|
}
|
|
$other[] = [
|
|
'icon'=>'icon-hangshizheng',
|
|
'title'=>'行驶证',
|
|
'img'=> $car_img
|
|
];
|
|
$other[] = [
|
|
'icon'=>'icon-baodan',
|
|
'title'=>'保单',
|
|
'img'=> $ins_img
|
|
];
|
|
|
|
$lists[] = [
|
|
'title' => "{$brand_name}{$serie_name}",
|
|
'model' => [
|
|
'title' => $color['title'],
|
|
'img' => $color['jsondata']['img']? build_qiniu_image_url($color['jsondata']['img']):'',
|
|
'color' => $color['jsondata']['code']
|
|
],
|
|
'vincode' => "车架号 {$item['vin']}",
|
|
'platenumber' => $agent['car_num'],
|
|
'insure' => "{$agent['ins_time']}到期",
|
|
'other' => $other
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $lists,
|
|
'total' => $count
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
//判断用户报名
|
|
protected function get_ck(){
|
|
$this->load->model('receiver/receiver_clues_model','clues_model');
|
|
$uid = $this->session['uid'];
|
|
$apt_count = $this->clues_model->count(['cf_uid'=>$uid,'cf_id'=>1,'status'=>0]);//预约试驾
|
|
$dg_count = $this->clues_model->count(['cf_uid'=>$uid,'cf_id'=>2,'status'=>0]);//订购
|
|
$data = [
|
|
'apt' => $apt_count ? 1 : 0,
|
|
'dg' => $dg_count ? 1 : 0
|
|
];
|
|
return $data;
|
|
}
|
|
|
|
//修改支付宝信息
|
|
protected function put_alipay(){
|
|
$uid = $this->session['uid'];
|
|
$account = $this->input_param('account');
|
|
$name = $this->input_param('name');
|
|
if(!$account || !$name){
|
|
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
|
|
}
|
|
$user = $this->app_user_model->get(array('id' => $uid));
|
|
$jsondata = json_decode($user['jsondata'],true);
|
|
$jsondata['alipay']['name'] = $name;
|
|
$jsondata['alipay']['account'] = $account;
|
|
$this->app_user_model->update(['jsondata'=>json_encode($jsondata,JSON_UNESCAPED_UNICODE)],['id'=>$uid]);
|
|
throw new Exception('保存成功', API_CODE_SUCCESS);
|
|
}
|
|
|
|
//我的爱车2
|
|
protected function get_mycar__1_1(){
|
|
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
!$page && $page = 1;
|
|
!$size && $size = 10;
|
|
$mobile = $this->session['mobile'];
|
|
|
|
$where = [
|
|
"(mobile={$mobile} or owner_mobile={$mobile})" => null,
|
|
"status" => 1,
|
|
];
|
|
$count = $this->receiver_orders_v2_model->count($where);
|
|
$lists = [];
|
|
if($count){
|
|
$this->load->library('receiver/orders_v2_entity');
|
|
$this->load->model("items/items_model");
|
|
$this->load->model('receiver/order/receiver_order_agents_model','agents_model');
|
|
$this->load->model('receiver/order/receiver_order_datas_model');
|
|
$rows = $this->receiver_orders_v2_model->select($where,'id desc',$page,$size);
|
|
//品牌车型
|
|
$brand_arr = array_unique(array_column($rows,'brand_id'));
|
|
$brands = $this->auto_brand_model->get_map_by_ids($brand_arr,'id,name');
|
|
//车系车型
|
|
$series_arr = array_unique(array_column($rows,'s_id'));
|
|
$series = $this->auto_series_model->get_map_by_ids($series_arr,'id,name');
|
|
foreach($rows as $key=>$val){
|
|
$item = $this->items_model->get(['id'=>$val['item_id']],'vin');
|
|
$color = $this->auto_attr_model->get(['id'=>$val['cor_id']],'title,jsondata');
|
|
$car_img = $ins_img = [];
|
|
$platenumber = $ins_company = $insure = '';
|
|
if($val['id']>=Orders_v2_entity::V2_START_ID){
|
|
$order_data = $this->receiver_order_datas_model->get(['o_id'=>$val['id']]);
|
|
$jsondata = json_decode($order_data['jsondata'],true);
|
|
$jsondata['car_info']['PlateNo'] && $platenumber = $jsondata['car_info']['PlateNo'];
|
|
if($order_data['car_img']){
|
|
$car_img = [
|
|
[
|
|
'text' => '查看行驶证',
|
|
'img' => build_qiniu_image_url($order_data['car_img']),
|
|
]
|
|
];
|
|
}
|
|
if($order_data['insurance_img'] || $order_data['business_img']){
|
|
$insurance_img = json_decode($order_data['insurance_img'],true);
|
|
$business_img = json_decode($order_data['business_img'],true);
|
|
if($insurance_img['img']){
|
|
$ins_img[] = [
|
|
'text' => '查看强制险',
|
|
'img' => build_qiniu_image_url($insurance_img['img']),
|
|
];
|
|
}
|
|
$ins_company = $business_img['product'];
|
|
if($business_img['img']){
|
|
$business_url = build_qiniu_image_url($business_img['img']);
|
|
$ins_img[] = [
|
|
'text' => '查看商业险',
|
|
'img' => $business_url,
|
|
];
|
|
// $business_info = $jsondata['ins_info'][md5($business_url)];
|
|
// $insure = $business_info['data']['投保日期'] ? $business_info['data']['投保日期'] : '';
|
|
}
|
|
}
|
|
}else{
|
|
$agent = $this->agents_model->get(['o_id'=>$val['id']]);
|
|
$agent['car_num'] && $platenumber = $agent['car_num'];
|
|
$insure = $agent['ins_time'] ? date('Y.m.d',strtotime($agent['ins_time'])):'';
|
|
$agent['car_img'] && $car_img[] = build_qiniu_image_url($agent['car_img']);
|
|
if($agent['ins_img']){
|
|
$ins_imgs = json_decode($agent['ins_img']);
|
|
foreach($ins_imgs as $k =>$v){
|
|
$ins_img[] = build_qiniu_image_url($v);
|
|
}
|
|
}
|
|
}
|
|
$other = [];
|
|
$other[] = [
|
|
'icon'=>'icon-hangshizheng',
|
|
'title'=>'行驶证',
|
|
'img'=> $car_img
|
|
];
|
|
$other[] = [
|
|
'icon'=>'icon-baodan',
|
|
'title'=>'保单',
|
|
'img'=> $ins_img
|
|
];
|
|
|
|
$color && $color['jsondata'] = json_decode($color['jsondata'],true);
|
|
|
|
$brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : '';
|
|
$serie_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : '';
|
|
|
|
$show_srv = false;
|
|
if(in_array($val['brand_id'],[1,6])){ //东风启辰和东风EV 显示店铺地址
|
|
$show_srv = true;
|
|
}
|
|
$lists[] = [
|
|
'o_id' => $val['id'],
|
|
'title' => "{$brand_name}{$serie_name}",
|
|
'model' => [
|
|
'title' => $color['title'],
|
|
'img' => $color['jsondata']['img']? build_qiniu_image_url($color['jsondata']['img']):'',
|
|
'color' => $color['jsondata']['code']
|
|
],
|
|
'vincode' => "车架号 {$item['vin']}",
|
|
'platenumber' => $platenumber,
|
|
'ins_company' => $ins_company,
|
|
'insure' => $insure,
|
|
'other' => $other,
|
|
'show_srv' => $show_srv,
|
|
'brand_id' => $val['brand_id'],
|
|
];
|
|
}
|
|
}
|
|
$data = [
|
|
'list' => $lists,
|
|
'total' => $count
|
|
];
|
|
return $data;
|
|
}
|
|
}
|