diff --git a/api/controllers/Hd.php b/api/controllers/Hd.php index 8b2581b4..220f55fb 100644 --- a/api/controllers/Hd.php +++ b/api/controllers/Hd.php @@ -17,7 +17,6 @@ class Hd extends CI_Controller { private static $apps = array( 'e49d182c6e6dab64' => 'liche', '1c156bb57cd6984a' => 'licheb', - 'fba9a12d2cd8599a' => 'neta', ); /** @@ -34,114 +33,6 @@ class Hd extends CI_Controller { private $inputs; private $log_file = 'hd.log'; - public function wxapp(){ - $callback = $_GET['callback']; - !$callback && $callback = $_POST['callback']; - trim($callback);//去掉首尾空白符 - $callback = $this->match_version($callback); - $callback = explode('.', $callback); - if(count($callback) > 2) { - $method_name = array_pop($callback); - $class_name = ucfirst(array_pop($callback)); - $dir = implode('/', $callback); - } else { - echo 'inval request'; - exit; - } - define('WECHATAPP', 1); - $file_name = APPPATH."controllers/wxapp/{$dir}/{$class_name}.php"; - if(file_exists($file_name)) { - require_once $file_name; - } else { - echo "class {$class_name} not exist";exit; - } - if($class_name == 'Welcome') { - $class = $this; - } else { - $class = new $class_name(); - }; - if(!$method_name || !method_exists($class, $method_name)) { - echo "method {$method_name} not exist"; - exit; - }; - - try{ - if(method_exists($class, 'check_login')){//校验登录 - $class->check_login($method_name); - } - $result = $class->$method_name(); - if(!$result) { - throw new Exception('', ERR_SYS_FAIL); - } - $this->print_return($result); - } catch (Exception $e) { - $this->print_return($this->return_error($e->getCode(), $e->getMessage())); - } - } - - /** - * 内容入口 - */ - function content(){ - define('WXAPP_CONTENT', 1); - - //加载输入参数 - $this->input_param(); - $version = $this->input_param('version'); - $sversion = $this->input_param('sversion'); - - $app_id = $this->input_param('app_id'); - - $this->log_file = get_class($this) . "_{$app_id}.log"; - - //卡ID为空 - $app = self::$apps[$app_id]; - if(!$app_id){ - debug_log("[fail]". __FUNCTION__ . ":app_id is null; uri_string:" . $this->uri->uri_string(), $this->log_file); - return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '应用不存在')); - } - //签名不正确 - if(!$this->vaild_sign()){ - debug_log("[fail]". __FUNCTION__ . ":sign check fail; uri_string:" . $this->uri->uri_string() . "; param:".json_encode($this->inputs), $this->log_file); - return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '验签失败')); - } - - $app = self::$apps[$app_id]; - $class_name = ucfirst($this->uri->segment(3));//:hd/content/subject/tag - if($this->uri->segment(4)){ - $method = $this->request . "_" . $this->uri->segment(4); - } else { - $method = $this->request; - } - - //app定制ct - $file_name = APPPATH."controllers/wxapp/content/{$app}/{$class_name}.php"; - //ct不存在 - if(file_exists($file_name)) { - require_once $file_name; - } else { - //app定制ct不存在,使用公共ct - $file_name = APPPATH."controllers/wxapp/content/{$class_name}.php"; - if(file_exists($file_name)) { - require_once $file_name; - } else{ - debug_log("[fail]". __FUNCTION__ . ": file '{$file_name}' not exist; method:{$method}, app_id:".$app_id, $this->log_file); - return $this->print_return($this->return_error(API_CODE_NONE, '内部错误')); - } - } - - try{ - $class = new $class_name($this->inputs, $app); - - $result = $class->$method($version, $sversion); - if(!$result) { - throw new Exception('', ERR_SYS_FAIL); - } - return $this->print_return($result); - } catch (Exception $e){ - return $this->print_return($this->return_error($e->getCode(), $e->getMessage())); - } - } /** * app其他入口 @@ -211,63 +102,6 @@ class Hd extends CI_Controller { return $this->print_return($this->return_error($e->getCode(), $e->getMessage())); } } - /** - * 分销入口 - */ - public function distribution(){ - define('WXAPP_ITEMS', 1); - //加载输入参数 - $this->input_param(); - $app_id = $this->input_param('app_id'); - !$app_id && $app_id = $this->input_param('vipcard_id'); - $version = $this->input_param('version'); - $sversion = $this->input_param('sversion'); - - $this->log_file = get_class($this) . "_{$app_id}.log"; - - //应用ID为空 - if(!$app_id){ - debug_log("[fail]". __FUNCTION__ . ":app_id is null; uri_string:" . $this->uri->uri_string(), $this->log_file); - return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '请求丢失')); - } - //签名不正确 - if(!$this->vaild_sign()){ - debug_log("[fail]". __FUNCTION__ . ":sign check fail; uri_string:" . $this->uri->uri_string() . "; param:".json_encode($this->inputs), $this->log_file); - return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '非法请求')); - } - $app = self::$apps[$app_id]; - $class_name = ucfirst($this->uri->segment(3)); - if($this->uri->segment(4)){ - $method = $this->request . "_" . $this->uri->segment(4); - } else { - $method = $this->request; - } - //app定制ct - $file_name = APPPATH."controllers/wxapp/distribution/{$app}/{$class_name}.php"; - //ct不存在 - if(file_exists($file_name)) { - require_once $file_name; - } else { - //app定制ct不存在,使用公共ct - $file_name = APPPATH."controllers/wxapp/distribution/{$class_name}.php"; - if(file_exists($file_name)) { - require_once $file_name; - } else{ - debug_log("[fail]". __FUNCTION__ . ": file '{$file_name}' not exist; method:{$method}, app_id:".$app_id, $this->log_file); - return $this->print_return($this->return_error(API_CODE_NONE, '非法请求')); - } - } - try{ - $class = new $class_name($this->inputs, $app); - $result = $class->$method($version, $sversion); - if(!$result) { - throw new Exception('', ERR_SYS_FAIL); - } - return $this->print_return($result); - } catch (Exception $e){ - return $this->print_return($this->return_error($e->getCode(), $e->getMessage())); - } - } /** * 可能要被废弃 diff --git a/api/controllers/Weixin.php b/api/controllers/Weixin.php new file mode 100644 index 00000000..d9891f47 --- /dev/null +++ b/api/controllers/Weixin.php @@ -0,0 +1,70 @@ +app_id = $this->input->get('app_id'); + $this->reset = $this->input->get('reset'); + $this->appid = $this->input->get('appid'); + $this->secret = $this->input->get('secret'); + $this->corpid = $this->input->get('corpid'); + $this->corpsecret = $this->input->get('corpsecret'); + + $wx_configs = array( + + ); + + $wx_config = $wx_configs[$this->app_id]; + if ($wx_config) { + !$this->appid && $this->appid = $wx_config['appid']; + !$this->secret && $this->secret = $wx_config['secret']; + } + + $param = array('appid' => $this->appid, "secret" => $this->secret); + $this->load->library("hd_wechat", $param); + } + + /** + * 获取access_token + */ + function access_token() + { + $access_token = $this->hd_wechat->access_token($this->reset); + + $data = array("access_token" => $access_token); + + echo json_encode($data, JSON_UNESCAPED_UNICODE); + + return; + } + + /** + * 获取分享凭证 + */ + function api_ticket() + { + $api_ticket = $this->hd_wechat->api_ticket($this->reset); + + $data = array("api_ticket" => $api_ticket); + + echo json_encode($data, JSON_UNESCAPED_UNICODE); + + return; + } +} \ No newline at end of file diff --git a/api/controllers/Welcome.php b/api/controllers/Welcome.php index b80b45fe..0da8c233 100644 --- a/api/controllers/Welcome.php +++ b/api/controllers/Welcome.php @@ -11,5 +11,6 @@ class Welcome extends CI_Controller { } public function test(){ + } } diff --git a/api/controllers/wxapp/Wxapp.php b/api/controllers/wxapp/Wxapp.php index 519feffb..89330c69 100644 --- a/api/controllers/wxapp/Wxapp.php +++ b/api/controllers/wxapp/Wxapp.php @@ -480,7 +480,7 @@ abstract class Wxapp extends HD_Controller{ * @return array|mixed|string */ protected function wx_data($encrypted, $iv){ - require_once APPPATH."third_party/WeChat/wxBizDataCrypt.php"; + require_once COMMPATH."third_party/WeChat/wxBizDataCrypt.php"; $pc = new WXBizDataCrypt($this->wx_config['appid'], $this->session['session_key']); $wx_data = ''; $errCode = $pc->decryptData($encrypted, $iv, $wx_data); diff --git a/api/controllers/wxapp/app/Series.php b/api/controllers/wxapp/app/Series.php new file mode 100644 index 00000000..71ed5f91 --- /dev/null +++ b/api/controllers/wxapp/app/Series.php @@ -0,0 +1,255 @@ +login_white = array();//登录白名单 + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg =array();//授权微信信息 + $this->load->model('auto/auto_brand_model'); + $this->load->model('auto/auto_series_model'); + $this->load->model('auto/auto_cars_model'); + $this->load->model("biz/biz_model"); + } + //获取车系 + protected function get(){ + $page = $this->input_param('page'); + $size = $this->input_param('size'); + $brand_id = $this->input_param('brand_id'); + !$page && $page = 1; + !$size && $size = 20; + + $where = [ + 'status' => 1 + ]; + $brand_id && $where['brand_id']=$brand_id; + $count = $this->auto_series_model->count($where); + $list = $this->auto_series_model->select($where,'id desc',$page,$size,'id,name'); + $data = [ + 'list' => $list, + 'total' => $count + ]; + return $data; + } + + //获取品牌 + protected function get_brands(){ + $page = $this->input_param('page'); + $size = $this->input_param('size'); + !$page && $page = 1; + !$size && $size = 20; + + $where = [ + 'status' => 1 + ]; + $count = $this->auto_brand_model->count($where); + $list = $this->auto_brand_model->select($where,'id desc',$page,$size,'id,name'); + $data = [ + 'list' => $list, + 'total' => $count + ]; + return $data; + } + + //获取车型列表 + protected function get_cars(){ + if ($this->app_id == 1){ + return $this->get_cars_by_brand_id(); // liche根据brand_id取数据 + } + + $uid = $this->session['uid']; + $id = $this->input_param('id'); //车系id + + $where = [ + 'status' => 1 + ]; + $user = $this->app_user_model->get(array('id' => $uid)); + if(isset($user['biz_id'])){ + $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $b_biz_rows = $this->auto_brand_biz_model->select(['biz_id'=>$biz_id],'','','','brand_id'); + + $str_brands = implode(',',array_column($b_biz_rows,'brand_id')); + !$str_brands && $str_brands = 0; + + $where["brand_id in ($str_brands)"] = null; + } + if($id){ //只显示相同品牌 + $series = $this->auto_series_model->get(['id'=>$id],'brand_id'); + $series['brand_id'] && $where['brand_id'] = $series['brand_id']; + } + $rows = $this->auto_series_model-> select($where,'',1,20,'id,brand_id,name'); + $list = []; + if($rows){ + $first = []; + $brand_arr = array_unique(array_column($rows,'brand_id')); + $brand_ids = implode(',',$brand_arr); + if($brand_ids){ + $where = [ + "id in ({$brand_ids})" => null, + ]; + $brand_rows = $this->auto_brand_model->map('id','',$where,'','','','id,name'); + } + foreach($rows as $key=>$val){ + $brand_name = isset($brand_rows[$val['brand_id']]) ? $brand_rows[$val['brand_id']][0]['name'] : ''; + $temp = [ + 'id' => $val['id'], + 'title' => $brand_name.$val['name'], + ]; + if($val['id']==$id){ + $first[] = $temp; + }else{ + $list[] = $temp; + } + } + $list = array_merge($first,$list); + } + return $list; + } + protected function get_cars_by_brand_id(){ + $id = $this->input_param('id'); + $id = $id ? $id : 0; + $where = [ + 'status' => 1, + 'brand_id' => $id + ]; + $rows = $this->auto_series_model->select($where,'',1,20,'id,brand_id,name'); + $list = []; + if($rows){ + $first = []; + $brand_arr = array_unique(array_column($rows,'brand_id')); + $brand_ids = implode(',',$brand_arr); + if($brand_ids){ + $where = [ + "id in ({$brand_ids})" => null, + ]; + $brand_rows = $this->auto_brand_model->map('id','',$where,'','','','id,name'); + } + foreach($rows as $key=>$val){ + $brand_name = isset($brand_rows[$val['brand_id']]) ? $brand_rows[$val['brand_id']][0]['name'] : ''; + $temp = [ + 'id' => $val['id'], + 'title' => $brand_name.$val['name'], + ]; + if($val['id']==$id){ + $first[] = $temp; + }else{ + $list[] = $temp; + } + } + $list = array_merge($first,$list); + } + return $list; + } + + //获取车系属性 + protected function get_attrs(){ + $s_id = $this->input_param('id'); + $type = $this->input_param('type'); + $page = $this->input_param('page'); + $size = $this->input_param('size'); + + !$page && $page = 0; + !$size && $size = 0; + + $lists = []; + if($type==2 || $type==1){ //1颜色 2内饰颜色 + $type = $type==1 ? 0 : $type; + $where = [ + 's_id' => $s_id, + 'type' => $type, + 'status' => 1 + ]; + $count = $this->auto_attr_model->count($where); + $lists = $this->auto_attr_model->select($where,'',$page,$size,'id,title'); + }else{ //车辆级别 + $city_id = ''; + $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + if($biz_id){ + $biz = $this->biz_model->get(['id'=>$biz_id],'city_id'); + $city_id = $biz['city_id']; + } + $where = [ + 's_id' => $s_id, + ]; + if($city_id=='350900'){ //宁德市特殊判断 + $where['(status=1 or id=30)'] = null; + }else{ + $where['status'] = 1; + } + $rows = $this->auto_cars_model->select($where,'id desc',$page,$size,'id,s_id,v_id'); + if($rows){ + $target_arr = array_unique(array_column($rows,'v_id')); + $attrs = $this->auto_attr_model->get_map_by_ids($target_arr,'id,title',1); + foreach($attrs as $key => $val){ + $lists[] = [ + 'id' => $key, + 'title' => $val[0]['title'] + ]; + } + } + $count = count($lists); + } + $data = [ + 'list' => $lists, + 'total' => $count + ]; + return $data; + } + + //获取车型信息信息 + protected function get_info(){ + $biz_id = $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + $s_id = $this->input_param('car_id'); + $v_id = $this->input_param('v_id'); + + if(!$s_id || !$v_id){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + $city_id = ''; + if($biz_id){ + $biz = $this->biz_model->get(['id'=>$biz_id],'city_id'); + $city_id = $biz['city_id']; + } + + $where_car = array( + 's_id'=>$s_id, + 'v_id' => $v_id, + ); + if($v_id!=113) { //哪吒 U 2021款Pro400巡航版 不判断状态 + $where_car['status'] = 1; + } + $car = $this->auto_cars_model->get($where_car,'',$city_id); + $biz_id == 70 && $car['price_book'] = 2000; //蕉城辉科写死定金 + if(!$car){ + throw new Exception('当前车型暂无库存', ERR_PARAMS_ERROR); + } + $dis_fine_money = $car['price_fine_floor']>0 && $car['price_fine']-$car['price_fine_floor']>0 ? $car['price_fine']-$car['price_fine_floor'] : 0; + $dis_fine_money_list = [500,1000,1500]; + $dis_money = $car['price_car'] - $car['price_floor']; + $dis_money_list = [500,1000,2000]; + $data = [ + 'price' => $car['price_car'] ? floatval($car['price_car']) : 0, + 'deposit' => $car['price_book'] ? floatval($car['price_book']) : 0, + 'dis_money' => $dis_money, + 'dis_money_list' => $dis_money_list, + 'fine_money' => floatval($car['price_fine']), + 'dis_fine_money' => $dis_fine_money, + 'dis_fine_money_list' => $dis_fine_money_list, + 'deposit_list' => [2000,3000,5000], + ]; + return $data; + } + +} diff --git a/api/controllers/wxapp/licheb/Clues.php b/api/controllers/wxapp/licheb/Clues.php new file mode 100644 index 00000000..8cb60ac9 --- /dev/null +++ b/api/controllers/wxapp/licheb/Clues.php @@ -0,0 +1,69 @@ +login_white = array();//登录白名单 + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + $this->load->model('receiver/receiver_clues_model', 'clues_model'); + $this->load->model('receiver/receiver_clue_oplogs_model', 'clue_oplogs_model'); + $this->load->model('area_model', 'mdArea'); + } + + public function get() + { + + $id = $this->input_param('id'); + if ($id) { + $where = [ + 'id' => $id, + ]; + $row = $this->clues_model->get($where); + if (!$row) { + throw new Exception('数据不存在', ERR_PARAMS_ERROR); + } + $other_data = []; + if ($row['county_id']) { + $re_area = $this->mdArea->get(['county_id' => $row['county_id']], 'province_name,city_name,county_name'); + $re_area && $other_data['所在地区'] = "{$re_area['province_name']}-{$re_area['city_name']}-{$re_area['county_name']}"; + } + $other_data['创建时间'] = date('Y-m-d', $row['c_time']); + $logs = $this->clue_oplogs_model->select(['clue_id' => $id], 'id desc', 1, 1); + if ($logs) { + $other_data['最近联系时间'] = date('Y-m-d', $logs[0]['c_time']); + } + $data = [ + 'id' => $row['id'], + 'name' => $row['name'], + 'mobile' => mobile_asterisk($row['mobile']), + 'other_data' => $other_data, + ]; + return $data; + } else { + $page = $this->input_param('page'); + $size = $this->input_param('size'); + !$page && $page = 1; + !$size && $size = 10; + $where = ['biz_id' => $this->get_biz_id(), 'status' => 0]; + $total = $this->clues_model->count($where); + $lists = []; + if ($total > 0) { + $rows = $this->clues_model->select($where, 'id desc', $page, $size, 'id,mobile,name'); + foreach ($rows as $item) { + $item['mobile'] = mobile_asterisk($item['mobile']); + $lists[] = $item; + } + } + return ['list' => $lists, 'total' => $total]; + } + + } +} \ No newline at end of file diff --git a/api/controllers/wxapp/licheb/Clueslogs.php b/api/controllers/wxapp/licheb/Clueslogs.php new file mode 100644 index 00000000..4f943bf5 --- /dev/null +++ b/api/controllers/wxapp/licheb/Clueslogs.php @@ -0,0 +1,93 @@ +login_white = array();//登录白名单 + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg = array();//授权微信信息 + + $this->load->model('receiver/receiver_clues_model', 'clues_model'); + $this->load->model('receiver/receiver_clue_oplogs_model', 'clue_oplogs_model'); + $this->load->model('receiver/receiver_comments_model', 'mdComments'); +// $this->load->model('receiver/receiver_xz_model'); + } + + protected function get() + { + $id = $this->input_param('id'); + $page = $this->input_param('page'); + $size = $this->input_param('size'); + !$page && $page = 1; + !$size && $size = 20; + $where = ['clue_id' => $id]; + $count = $this->clue_oplogs_model->count($where); + $lists = []; + if ($count) { + $rows = $this->clue_oplogs_model->select($where, 'id desc', $page, $size, 'id,log,uname,type,c_time'); + foreach ($rows as $key => $val) { + $record = ''; + $second = 0; + $content = $val['log']; + $img_json = json_decode($val['imgs'], true); + $imgs = []; + if ($img_json) { + foreach ($img_json as $val2) { + $imgs[] = build_qiniu_image_url($val2); + } + } + if ($val['type'] == 2) { + $rec_row = $this->receiver_xz_model->get(['id' => $val['log']], 'rec_url,duration'); + $content = '拨打电话'; + !$rec_row['duration'] && $content .= '(未接通)'; + $rec_row['rec_url'] && $record = $rec_row['rec_url']; + $rec_row['duration'] && $second = intval($rec_row['duration'] / 1000); + } + $lists[] = [ + 'id' => $val['id'], + 'content' => "【{$val['uname']}】" . $content, + 'record_url' => $record, + 'second' => $second, + 'type_name' => $this->clue_oplogs_model->typeAry($val['type']), + 'c_time' => date('Y.m.d H:i', $val['c_time']) + ]; + } + } + $data = [ + 'list' => $lists, + 'total' => $count + ]; + return $data; + } + + protected function post() + { + $id = $this->input_param('cus_id'); + $log = trim($this->input_param('content')); + $img_arr = $this->input_param('imgs'); + if (!$log && !$img_arr) { + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + $this->load->library('receiver/customers_entity'); + $result = $this->customers_entity->add_log_visit($id, $this->session['uid'], $this->session['uname'], $log, 0, 1, $img_arr); + if ($result) { + throw new Exception('修改成功', API_CODE_SUCCESS); + } else { + throw new Exception('修改失败', ERR_PARAMS_ERROR); + } + } +} diff --git a/api/controllers/wxapp/licheb/Customers.php b/api/controllers/wxapp/licheb/Customers.php index 42986b16..89a20453 100644 --- a/api/controllers/wxapp/licheb/Customers.php +++ b/api/controllers/wxapp/licheb/Customers.php @@ -52,7 +52,7 @@ class Customers extends Wxapp $other_data = ['客户等级' => $row['level']]; if ($row['county_id']) { $re_area = $this->mdArea->get(['county_id' => $row['county_id']], 'city_name,county_name'); - $re_area && $other_data['所在地区'] = "{$re_area['city_name']}-{$re_area['county_name']}"; + $re_area && $other_data['所在地区'] = "{$re_area['province_name']}-{$re_area['city_name']}-{$re_area['county_name']}"; } if ($this->get_biz('type') != 5) { $other_data['客户来源'] = $this->get_cfTitle($row); @@ -360,7 +360,6 @@ class Customers extends Wxapp } $uid = $this->session['uid']; $uname = $this->session['uname']; - $this->load->library('receiver/customers_entity'); $this->customers_entity->add_log($id, $uid, $uname, "创建客户档案", 3); if ($wxgr) { $imgs = []; @@ -1126,27 +1125,6 @@ class Customers extends Wxapp , 'c_time<=' => strtotime($e_c_time)]; // $group_id == 1 && $where['admin_id'] = $this->myuid; $count = $this->customers_model->count($where); - } else if ($visit == 4) {//今日/本月企v - $where = ['change_type' => 'add_external_contact', 'c_time>=' => strtotime($s_c_time), 'c_time<=' => strtotime($e_c_time)]; - if ($biz_type == 5) {//异业店 - $this->load->model('app/app_different_qy_log_model', 'mdWechatLog'); - $this->load->model('app/app_different_qy_model', 'mdWechat'); - } else { - $this->load->model('app/app_lichene_qy_log_model', 'mdWechatLog'); - $this->load->model('app/app_lichene_qy_model', 'mdWechat'); - } - if ($group_id == 1) { - $where['userid'] = $this->session['userid'] ? $this->session['userid'] : '-1'; - } else { - $res_user = $this->app_user_model->select(['biz_id' => $this->biz_id, 'group_id <' => 4, 'status >=' => 0, 'userid<>' => ''], 'id asc', 0, 0, 'userid'); - if ($res_user) { - $str_userids = implode("','", array_column($res_user, 'userid')); - $where["userid in('{$str_userids}')"] = null; - } else { - $where["userid"] = '-1'; - } - } - $count = $this->mdWechatLog->count($where, 'distinct(external_userid)'); } else if ($visit == 5 || $visit == 7) {//今日/本月到店/战败 $oplogs_type = $visit == 7 ? 7 : 4;//4到店7战败 $s_c_time = strtotime($s_c_time); diff --git a/api/controllers/wxapp/licheb/Sign.php b/api/controllers/wxapp/licheb/Sign.php new file mode 100644 index 00000000..c98cecbb --- /dev/null +++ b/api/controllers/wxapp/licheb/Sign.php @@ -0,0 +1,192 @@ +login_white = array('get_userConf');//登录白名单 + $this->load->model('receiver/receiver_clues_model', 'clues_model'); + $this->load->model('receiver/receiver_clue_oplogs_model', 'clue_oplogs_model'); + $this->load->model('receiver/receiver_customers_model', 'customers_model'); + $this->load->model('receiver/receiver_customer_sign_model', 'sign_model'); + $this->load->model('area_model'); + $this->load->model("biz/biz_model"); + $this->load->model("item/item_model"); + $this->load->model('app/app_model'); + $this->load->library('receiver/customers_entity'); + } + + //商家签到页配置信息 + protected function get_conf() + { + $biz = $this->biz_model->get(['id' => $this->get_biz_id()]); + $area = $this->area_model->get(['city_id' => $biz['city_id']]); + $where = [ + 'status' => 1, + 's_time>=' => time(), + 'e_time<=' => time(), + "province_id={$area['province_id']} or province_id=0" => null + ]; + $item_row = $this->item_model->get($where); + $time_out = 600000; + $item = []; + if ($item_row) { + $item['title'] = $item_row['title']; + $item['img'] = $item_row['img'] ? build_qiniu_image_url($item_row['img']) : ''; + } + $this->load->helper('string'); + $key = $this->session['uid'] . random_string('alnum', 20); + $biz_info = [ + 'biz_uid' => $this->session['uid'], + 'biz_id' => $this->get_biz_id(), + ]; + $this->app_redis->save($key, $biz_info, $time_out); + echo $key; + exit; + //获取小程序二维码 + $wxconfig = $this->app_model->appConfig()[2]['wx']; + $this->load->library("hd_wechat", $wxconfig); + $width = '430px'; + $scene = "key=$key"; + $result = $this->hd_wechat->qrcode('', $scene, '', $width); + if (!$result['code']) { + throw new Exception($result['msg'], ERR_PARAMS_ERROR); + } + $data = [ + 'time' => date('Y-m-d H:i:s'), + 'uname' => "车管家 {$this->session['uname']}", + 'shop' => "{$area['city_name']}-{$biz['biz_name']}", + 'qcode' => base64_encode($result['file']), + 'qrcode_count_time' => $time_out, + 'item' => $item + ]; + return $data; + } + + //用户签到页面配置 + protected function get_userConf() + { + $cache_key = $this->input_param('key'); + $biz_info = $this->app_redis->get($cache_key); + if (!$biz_info || !$biz_info['biz_uid'] || !$biz_info['biz_id']) { + throw new Exception('二维码过期,请重新扫码签到', ERR_PARAMS_ERROR); + } + $biz_uid = $biz_info['biz_uid']; + $biz_id = $biz_info['biz_id']; + $biz = $this->biz_model->get(['id' => $biz_id]); + $user = $this->app_user_model->get(['id' => $biz_uid]); + $lists = [ + [ + 'icon' => 'iconfont icon-yonghu', + 'title' => '用户全程0负担', + 'content' => '无需额外付费,即可享受报价权益' + ], + [ + 'icon' => 'iconfont icon-yonghu', + 'title' => '1次覆盖全范围', + 'content' => '权益覆盖空间站所有合作品牌' + ], + [ + 'icon' => 'iconfont icon-yonghu', + 'title' => '赔付至高2万元', + 'content' => '根据所购车型官方指导价划分,赔付差价' + ], [ + 'icon' => 'iconfont icon-yonghu', + 'title' => '保价长达3个月', + 'content' => '自购车之日起(含购车当日)90天', + ] + ]; + $data = [ + 'biz_uname' => $user['uname'], + 'biz_name' => $biz['biz_name'], + 'lists' => $lists, + ]; + return $data; + } + + //用户签到 + protected function post() + { + $cache_key = $this->input_param('key'); + $lat = $this->input_param('lat'); + $lng = $this->input_param('lng'); + + if (!$cache_key || !$lat || !$lng) throw new Exception('参数错误', ERR_PARAMS_ERROR); + if (!isValidLatLng($lat, $lng)) throw new Exception('未获取到定位', ERR_PARAMS_ERROR); + $sign_data = [ + 'status' => 0, + 'uid' => $this->session['id'], + 'lat' => $lat, + 'lng' => $lng, + 'c_time' => time() + ]; + $biz_info = $this->app_redis->get($cache_key); + if (!$biz_info || !$biz_info['biz_uid'] || !$biz_info['biz_id']) { + $sign_data['descrip'] = '二维码过期'; + $this->sign_model->add($sign_data); + throw new Exception('二维码过期,请重新扫码签到', ERR_PARAMS_ERROR); + } + $biz_uid = $biz_info['biz_uid']; + $biz_id = $biz_info['biz_id']; + $biz = $this->biz_model->get(['id' => $biz_id]); + $biz_user = $this->app_user_model->get(['id' => $biz_uid]); + //计算距离 + $this->load->helper('search'); + $distance = get_distance($lat, $lng, $biz['lat'], $biz['lng']); + $sign_data['distance'] = $distance; + if ($distance > 500) { + $sign_data['descrip'] = '不在打卡范围'; + $this->sign_model->add($sign_data); + return ['type' => 'fail', 'msg' => '您未在门店的有效范围之内']; + } + $mobile = $this->session['mobile']; + $where = ['mobile' => $mobile, 'biz_id' => $biz_id]; + $rows = $this->customers_model->select($where, 'id desc', 1, 1); + if (!$rows[0]) { + $sign_data['descrip'] = '用户不存在'; + $this->sign_model->add($sign_data); + throw new Exception('用户不存在', ERR_SYS_FAIL); + } + $customers_row = $rows[0]; + if ($customers_row['status']) { + $sign_data['descrip'] = '当前状态无需签到,状态值' . $customers_row['status']; + $this->sign_model->add($sign_data); + return ['type' => 'fail', 'msg' => '您已打卡']; + } + $update = [ + 'a_num' => $customers_row['a_num'] + 1, + 'status' => 1, + 'dt_time' => date('Y-m-d H:i:s'), + ]; + $res = $this->customers_model->update($update, ['id' => $customers_row['id']]); + if (!$res) { + throw new Exception('签到失败', ERR_PARAMS_ERROR); + } + $this->customers_entity->add_log($customers_row['id'], $biz_uid, $biz_user['uname'], "用户签到", 4); + //添加签到日志 + $where = [ + 'status' => 1, + 's_time>=' => time(), + 'e_time<=' => time(), + "province_id={$biz['province_id']} or province_id=0" => null + ]; + $item_row = $this->item_model->get($where); + $sign_data['status'] = 1; + + $sign_data['distance'] = $distance; + $sign_data['customer_id'] = $customers_row['id']; + $item_row && $sign_data['item_id'] = $item_row['id']; + $this->sign_model->add($sign_data); + $data = [ + 'type' => 'success', + 'item_title' => $item_row ? $item_row['title'] : '', + 'item_img' => $item_row['img'] ? build_qiniu_image_url($item_row['img']) : '', + ]; + return $data; + } +} \ No newline at end of file diff --git a/api/controllers/wxapp/licheb/Sms.php b/api/controllers/wxapp/licheb/Sms.php index 95144598..c4f17f33 100644 --- a/api/controllers/wxapp/licheb/Sms.php +++ b/api/controllers/wxapp/licheb/Sms.php @@ -32,7 +32,7 @@ class Sms extends Wxapp if (!mobile_valid($mobile)) { throw new Exception('请输入正确的手机号码', ERR_PARAMS_ERROR); } - $user = $this->app_user_model->get(['mobile' => $mobile, 'status>' => -1]); + $user = $this->app_user_model->get(['mobile' => $mobile, 'status>' => -1, 'group_id > ' => 0]); if (!$user) { throw new Exception('用户不存在', API_CODE_FAIL); } diff --git a/api/controllers/wxapp/licheb/User.php b/api/controllers/wxapp/licheb/User.php index 025fd542..6721b39b 100644 --- a/api/controllers/wxapp/licheb/User.php +++ b/api/controllers/wxapp/licheb/User.php @@ -29,6 +29,7 @@ class User extends Wxapp // $this->load->model('items/items_oplogs_model', 'mdItemsOplogs'); $this->load->model('sys/sys_city_model'); // $this->load->library('receiver/orders_v2_entity'); + $this->load->model('receiver/receiver_clues_model', 'clues_model'); } /** @@ -38,11 +39,14 @@ class User extends Wxapp */ protected function get_ukey() { - $mobile_white = ['18350451617','13850003412']; + $mobile_white = ['18350451617', '13850003412']; $code = $this->input_param('code'); $mobile = $this->input_param('mobile'); $sms_code = $this->input_param('sms_code'); - + $by_code = $this->input_param('by_code'); + if ($by_code) { //普通用户code登录 + return $this->get_cUkey(); + } if (!$code || !$mobile || !$sms_code) { throw new Exception('参数错误', API_CODE_INVILD_PARAM); } @@ -54,7 +58,7 @@ class User extends Wxapp throw new Exception('验证码错误', API_CODE_FAIL); } } - $user = $this->app_user_model->get(['mobile' => $mobile, 'status>' => -1]); + $user = $this->app_user_model->get(['mobile' => $mobile, 'status>' => -1, 'group_id>' => 0]); if (!$user) { throw new Exception('用户不存在', API_CODE_FAIL); } @@ -93,6 +97,35 @@ class User extends Wxapp return array('ukey' => $ukey); } + protected function get_cUkey() + { + $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); + } + $open_id = $session['openid']; + $user = $this->app_user_model->get(['openid' => $open_id]); + if (!$user) { + $userData = [ + 'openid' => $open_id, + 'group_id' => 0, + 'group_id1' => 0, + 'c_time' => time(), + ]; + $session['unionid'] && $userData['unionid'] = $session['unionid']; + $uid = $this->app_user_model->add($userData); + } else { + $uid = $user['id']; + } + $udata = array('uid' => $uid, 'session_key' => $session['session_key']); + + $ukey = $this->refresh_login($udata); + + return array('ukey' => $ukey); + } + /** * Notes:用户信息 * Created on: 2022/10/12 14:09 @@ -199,7 +232,6 @@ class User extends Wxapp //获取用户信息 $uid = $this->session['uid']; $user = $this->app_user_model->get(array('id' => $uid)); - $upd = array(); $mobile = ''; //授权 @@ -208,7 +240,6 @@ class User extends Wxapp throw new Exception('授权失败', API_CODE_INVILD_PARAM); } $wxdata = $this->wx_data($encrypted, $iv); - if (!$wxdata) { throw new Exception('授权失败', API_CODE_FAIL); } @@ -221,17 +252,19 @@ class User extends Wxapp if (!$mobile && isset($wxdata['phoneNumber'])) { throw new Exception('微信未绑定手机号', API_CODE_FAIL); } - $mobile && !$user['mobile'] && $upd['mobile'] = $mobile; + $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); + if ($user['group_id'] > 0) { //普通用户不判断手机号是否被绑定 + $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); + } } } } else {//编辑其他信息 @@ -285,22 +318,17 @@ class User extends Wxapp $group_id == 1 && $where['admin_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $loan_count = 0; - //客户代办事项 - if ($group_id == 1) { - $customer_op_list = []; - } else { - //未派单客户 - $where = ['admin_id' => 0, 'biz_id' => $biz_id, 'cs_biz_id<>' => -1, 'status>=' => 0]; - if ($group_id == 4 && $biz_id != 1) { - $where['brand_id!='] = 3; //渠道经理过滤 - } - $unuse_count = $this->customers_model->count($where); - $defeat_count = $this->customers_model->count(['biz_id' => $biz_id, 'cs_biz_id<>' => -1, 'if_defeat' => 1, 'status>' => -1]); - $customer_op_list = [ - ['title' => '待分配客户(人)', 'icon' => 'icon-daifenpei', 'total' => $unuse_count, 'page' => '/pages/customer/allot/index'], - ['title' => '战败申请(人)', 'icon' => 'icon-statistics-custom-5', 'total' => $defeat_count, 'page' => '/pages/customer/optDefeat/index'], - ]; - } + //客户代办事项--未派单客户 + $where = ['admin_id' => 0, 'biz_id' => $biz_id, 'cs_biz_id<>' => -1, 'status>=' => 0]; + $unuse_count = $this->customers_model->count($where); + $defeat_count = $this->customers_model->count(['biz_id' => $biz_id, 'cs_biz_id<>' => -1, 'if_defeat' => 1, 'status>' => -1]); + $clues_count = $this->clues_model->count(['biz_id' => $biz_id, 'status' => 0]); + $customer_op_list = [ + ['title' => '待分配客户(人)', 'icon' => 'icon-daifenpei', 'total' => $unuse_count, 'page' => '/pages/customer/allot/index'], + ['title' => '线索池(人)', 'icon' => 'icon-daifenpei', 'total' => $clues_count, 'page' => '/pages/clues/index'], + ['title' => '战败申请(人)', 'icon' => 'icon-statistics-custom-5', 'total' => $defeat_count, 'page' => '/pages/customer/optDefeat/index'], + ]; + $where = ['status>=' => 0, 'payway' => 0, 'brand_id>' => 0, 'biz_id' => $biz_id, 'status!=' => 2,]; $group_id == 1 && $where['sale_id'] = $uid; $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 @@ -329,8 +357,7 @@ class User extends Wxapp $group_id == 4 && $where['brand_id!='] = 3; //渠道经理过滤 $ck_total = 0; $deallist = [ - ['title' => '分期办理 ', 'icon' => 'icon-banfenqi', 'total' => $fq_total, 'page' => '/pages/order/filterList/index2?type=fq&title=分期办理'], - ['title' => '车辆匹配', 'icon' => 'icon-cheliangfenpei', 'total' => $pc_total, 'page' => '/pages/order/filterList/index2?type=pc&title=车辆分配'], + ['title' => '签约下定 ', 'icon' => 'icon-banfenqi', 'total' => $fq_total, 'page' => '/pages/order/filterList/index2?type=fq&title=分期办理'], ['title' => '发票开具', 'icon' => 'icon-kaipiao1', 'total' => $kp_total, 'page' => '/pages/order/filterList/index2?type=kp&title=发票开具'], ['title' => '交付确认', 'icon' => 'icon-jiaofu', 'total' => $ck_total, 'page' => '/pages/order/filterList/index2?type=jf&title=交付确认'], ]; @@ -398,68 +425,20 @@ class User extends Wxapp "id in(select customer_id from lc_receiver_customer_oplogs where type=4 and uid in({$str_uids}) and c_time>=" . strtotime($s_today) . " and c_time<=" . strtotime($e_today) . ")" => null]; $where_month_dd = ['biz_id' => $biz_id, 'status>=' => 0, 'cs_biz_id<>' => -1, "id in(select customer_id from lc_receiver_customer_oplogs where type=4 and uid in({$str_uids}) and c_time>=" . strtotime($s_month) . " and c_time<=" . strtotime($e_month) . ")" => null]; - //订单 - $where_today_order = ['status>=' => 0, 'order_time>=' => $s_today, 'order_time<=' => $e_today]; - $where_month_order = ['status>=' => 0, 'order_time>=' => $s_month, 'order_time<=' => $e_month]; //战败 $where_today_defeat = ['biz_id' => $biz_id, 'status>=' => 0, 'cs_biz_id<>' => -1, "id in(select customer_id from lc_receiver_customer_oplogs where type=7 and uid in({$str_uids}) and c_time>=" . strtotime($s_today) . " and c_time<=" . strtotime($e_today) . ")" => null]; $where_month_defeat = ['biz_id' => $biz_id, 'status>=' => 0, 'cs_biz_id<>' => -1, "id in(select customer_id from lc_receiver_customer_oplogs where type=7 and uid in({$str_uids}) and c_time>=" . strtotime($s_month) . " and c_time<=" . strtotime($e_month) . ")" => null]; - //退订 - $where_today_refund = ['status' => 2, 'refund_time>=' => $s_today, 'refund_time<=' => $e_today]; - $where_month_refund = ['status' => 2, 'refund_time>=' => $s_month, 'refund_time<=' => $e_month]; - if ($group_id == 1) { - $where_today_xs['admin_id'] = $uid; - $where_month_xs['admin_id'] = $uid; - $where_today_order['admin_id'] = $uid; - $where_month_order['admin_id'] = $uid; - $where_today_refund['admin_id'] = $uid; - $where_month_refund['admin_id'] = $uid; - } else if ($group_id == 2 || $group_id == 3) {//店长/老板 - $where_today_order["(biz_id = {$biz_id} OR admin_id = {$uid})"] = null; - $where_month_order["(biz_id = {$biz_id} OR admin_id = {$uid})"] = null; - $where_today_refund["(biz_id = {$biz_id} OR admin_id = {$uid})"] = null; - $where_month_refund["(biz_id = {$biz_id} OR admin_id = {$uid})"] = null; - } else if ($group_id == 4) { - $where_today_order['biz_id'] = $biz_id; - $where_month_order['biz_id'] = $biz_id; - $where_today_refund['biz_id'] = $biz_id; - $where_month_refund['biz_id'] = $biz_id; - if ($biz_id != 1) {//渠道经理过滤 - $where_today_order['brand_id<>'] = 3; - $where_month_order['brand_id<>'] = 3; - $where_today_refund['brand_id<>'] = 3; - $where_month_refund['brand_id<>'] = 3; - } - } - $today_qy = $month_qy = 0; - if ($str_userids) { - $where_today_qy["userid in('{$str_userids}')"] = null; - $where_month_qy["userid in('{$str_userids}')"] = null; - $re_biz = $this->biz_model->get(['id' => $biz_id]); - if ($re_biz['type'] == 5) {//异业店 - $this->load->model('app/app_different_qy_log_model', 'mdDifferentQyLog'); - $today_qy = $this->mdDifferentQyLog->count($where_today_qy, 'distinct(external_userid)'); - $month_qy = $this->mdDifferentQyLog->count($where_month_qy, 'distinct(external_userid)'); - } else { - $today_qy = 0; - $month_qy = 0; - } - } $statistics = [ ['today' => ['title' => '今日', 'value' => $this->customers_model->count($where_today_xs), 'url' => '/pages/customer/filterList/index?status=3&visit=3&title=线索'] , 'month' => ['title' => '本月线索', 'value' => $this->customers_model->count($where_month_xs)]], - ['today' => ['title' => '今日', 'value' => $today_qy, 'url' => '/pages/customer/filterList/index?status=4&visit=4&title=企v'] - , 'month' => ['title' => '本月企v', 'value' => $month_qy]], ['today' => ['title' => '今日', 'value' => $this->customers_model->count($where_today_dd), 'url' => '/pages/customer/filterList/index?status=5&visit=5&title=到店'] , 'month' => ['title' => '本月到店', 'value' => $this->customers_model->count($where_month_dd)]], ['today' => ['title' => '今日', 'value' => 0, 'url' => '/pages/order/filterList/index2?status=6&visit=6&title=订单'] , 'month' => ['title' => '本月订单', 'value' => 0]], ['today' => ['title' => '今日', 'value' => $this->customers_model->count($where_today_defeat), 'url' => '/pages/customer/filterList/index?status=7&visit=7&title=战败'] - , 'month' => ['title' => '本月战败', 'value' => $this->customers_model->count($where_month_defeat)]], - ['today' => ['title' => '今日', 'value' => 0, 'url' => '/pages/order/filterList/index2?status=8&visit=8&title=退订'] - , 'month' => ['title' => '本月退订', 'value' => 0]] + , 'month' => ['title' => '本月战败', 'value' => $this->customers_model->count($where_month_defeat)]] ]; $data = [ 'wl_count' => ['title' => '待跟进客户(人)', 'num' => $wl_num, 'url' => '/pages/customer/filterList/index?status=1&visit=1&title=待跟进客户'], @@ -625,4 +604,16 @@ class User extends Wxapp $this->app_redis->save($this->redis_login . $ukey, json_encode($this->session, JSON_UNESCAPED_UNICODE), 30 * 24 * 3600); throw new Exception('保存成功', API_CODE_SUCCESS); } + + //获取用户手机号 + protected function get_tel() + { + $uid = $this->session['uid']; + + $user = $this->app_user_model->get(array('id' => $uid)); + $data = [ + 'mobile' => $user['mobile'], + ]; + return $data; + } } diff --git a/common/helpers/comm_helper.php b/common/helpers/comm_helper.php index 47c56e10..6b53c276 100644 --- a/common/helpers/comm_helper.php +++ b/common/helpers/comm_helper.php @@ -1,5 +1,5 @@ sendSms($mobile, array('code' => $code), $template, $sign); - var_dump($req);exit; + var_dump($req); + exit; return true; } } @@ -739,7 +740,7 @@ if (!function_exists('num_to_rmb')) { * @return string */ if (!function_exists('friendly_date')) { - function friendly_date($sTime, $type = 'normal',$d_type = '') + function friendly_date($sTime, $type = 'normal', $d_type = '') { if (!$sTime) return ''; //sTime=源时间,cTime=当前时间,dTime=时间差 @@ -763,9 +764,9 @@ if (!function_exists('friendly_date')) { //return intval($dTime/3600)."小时前"; return '今天' . date('H:i', $sTime); } elseif ($dYear == 0) { - return $d_type ? date("m.d H:i", $sTime) : date("m月d日 H:i", $sTime) ; + return $d_type ? date("m.d H:i", $sTime) : date("m月d日 H:i", $sTime); } else { - return $d_type ? date("Y.m.d H:i", $sTime) : date("Y-m-d H:i", $sTime) ; + return $d_type ? date("Y.m.d H:i", $sTime) : date("Y-m-d H:i", $sTime); } } elseif ($type == 'mohu') { if ($dTime < 60) { @@ -945,27 +946,27 @@ if (!function_exists('http_host_com')) { $url = ''; if (false !== strpos($_SERVER['HTTP_HOST'], 'dev')) { //dev 测试 if ($type == 'api') { - $url = 'https://liche-api-dev.xiaoyu.com'; + $url = ''; } else if ($type == 'home') { - $url = "https://liche-dev.xiaoyu.com"; + $url = ""; } else if ($type == 'admin') { - $url = "http://liche-admin.dev.xiaoyu.com"; + $url = ""; } - } elseif (false !== strpos($_SERVER['HTTP_HOST'], 'test')) {//test 测试 + } elseif (false !== strpos($_SERVER['HTTP_HOST'], 'ss')) {//test 测试 if ($type == 'api') { - $url = 'api.lc.haodian.cn'; + $url = 'https://api.ss.haodian.cn/'; } else if ($type == 'home') { - $url = "https://www-test.liche.cn"; + $url = ""; } else if ($type == 'admin') { - $url = "https://admin.test.liche.cn"; + $url = "http://admin.ss.haodian.cn/"; } } else { // 正式 if ($type == 'api') { - $url = 'https://api.liche.cn'; + $url = ""; } else if ($type == 'home') { - $url = "https://www.liche.cn"; + $url = ""; } else if ($type == 'admin') { - $url = "https://admin.liche.cn"; + $url = ""; } } return $url; @@ -1185,3 +1186,15 @@ if (!function_exists('is_img')) { } } } + +if (!function_exists('isValidLatLng')) { + function isValidLatLng($lat, $lng) + { + // 经度正则表达式 + $longitudePattern = '/^-?((1?[0-7]?[0-9]|[1-9]?[0-9]|1[0-4]?[0-9]{2}|15[0-9]{2}|1[0-1]?[0-9]{3}|12[0-3]?[0-9]{2}|124[0-8]?[0-9]|1249(?![\d:]+))\.[\d:]+)$/'; + // 纬度正则表达式 + $latitudePattern = '/^-?(([0-8]?[0-9]|9?[0-4]?[0-9]{2}|1[0-3]?[0-9]{3}|14[0-8]?[0-9]{2}|149(?![\d:]+))\.[\d:]+)$/'; + + return preg_match($longitudePattern, $lng) && preg_match($latitudePattern, $lat); + } +} diff --git a/common/helpers/order_helper.php b/common/helpers/order_helper.php index 2048083a..abcf95d5 100644 --- a/common/helpers/order_helper.php +++ b/common/helpers/order_helper.php @@ -28,9 +28,6 @@ if ( ! function_exists('create_order_no')) case 'licheb': $source_id = sprintf("%02d", 2); break; - case 'market': - $source_id = sprintf("%02d", 51); - break; default: $source_id = sprintf("%02d", 0); } diff --git a/common/libraries/Hd_wechat.php b/common/libraries/Hd_wechat.php new file mode 100644 index 00000000..749362c7 --- /dev/null +++ b/common/libraries/Hd_wechat.php @@ -0,0 +1,290 @@ +env = 'd'; + } elseif (false !== strpos($_SERVER['HTTP_HOST'], 'api.ss.haodian.cn')) {//test 测试 + $this->env = 'p'; + } else { // 正式 + $this->env = 'p'; + } + + if ('p' != $this->env) { + $this->url_wechat = http_host_com('api') . 'weixin'; + } + $this->redis = &load_cache('redis'); + + $param && $this->init($param); + } + + /** + * 初始化 + * @param $param + */ + function init($param) + { + $this->appid = $param['appid']; + $this->secret = $param['secret']; + $this->log_dir = "libraries_wechat_{$this->appid}"; + } + + /** + * 获取或者重置access_token + * @param $reset (是否重置) + * @return mixed + */ + function access_token($reset = false) + { + $redis = $this->redis; + $key = "wechat_access_token_{$this->appid}"; + + debug_log("[info]: appid={$this->appid}", __FUNCTION__, $this->log_dir); + + $func = __FUNCTION__; + + if (!$reset) {//不重置 + if ($this->access_token) { + $access_token = $this->access_token; + } elseif ($this->url_wechat) {//从线上获取access_token + $url = $this->url_wechat . "/{$func}?appid={$this->appid}&secret={$this->secret}"; + $res = $this->http_get($url); + $ret = json_decode($res, true); + $access_token = $ret['access_token']; + if (!$access_token) { + debug_log("[warning]# res={$res}; url={$url}", __FUNCTION__, $this->log_dir); + } + } else {//缓存中获取 + $access_token = $redis->get($key); + } + + if ($access_token) { + return $access_token; + } + } + + //重置access_token,第三方的不处理 + if ($this->url_wechat) { + $url = $this->url_wechat . "/{$func}?appid={$this->appid}&secret={$this->secret}&reset=1"; + } else { + $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appid}&secret={$this->secret}"; + } + $res = $this->http_get($url); + $ret = json_decode($res, true); + $access_token = $ret['access_token']; + if ($access_token) { + //线上环境才缓存 + 'p' == $this->env && $redis->save($key, $access_token, 7000); + } else { + debug_log("[warning]# res={$res}; url={$url}", __FUNCTION__, $this->log_dir); + } + + $this->access_token = $access_token; + + return $access_token; + } + + /** + * 分享票据 + * @param bool $reset "是否重置" + * @return mixed + */ + function api_ticket($reset = false) + { + $redis = $this->redis; + $key = 'wechat_jsApiTicket_' . $this->appid; + + $func = __FUNCTION__; + + if (!$reset) {//不重置 + if ($this->api_ticket) { + $api_ticket = $this->api_ticket; + } elseif ($this->url_wechat) {//从线上获取ticket + $url = $this->url_wechat . "/{$func}?appid={$this->appid}&secret={$this->secret}"; + $res = $this->http_get($url); + $ret = json_decode($res, true); + $api_ticket = $ret['api_ticket']; + if (!$api_ticket) { + debug_log("[warning]# res={$res}; url={$url}", __FUNCTION__, $this->log_dir); + } + } else {//缓存中获取 + $api_ticket = $redis->get($key); + } + + if ($api_ticket) { + return $api_ticket; + } + } + + //重置 + if ($this->url_wechat) {//从线上重置获取ticket + $url = $this->url_wechat . "/{$func}?appid={$this->appid}&secret={$this->secret}&reset=1"; + $res = $this->http_get($url); + $ret = json_decode($res, true); + } else { + $access_token = $this->access_token(); + $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={$access_token}"; + $res = $this->http_get($url); + $ret = json_decode($res, true); + if (!$ret['ticket']) { + debug_log("[warning]# res={$res}; url={$url}", __FUNCTION__, $this->log_dir); + //可能是access_token过期,重置获取一下 + $access_token = $this->access_token(true); + $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={$access_token}"; + $res = $this->http_get($url); + $ret = json_decode($res, true); + } + } + $api_ticket = $ret['ticket']; + if ($api_ticket) { + //线上环境才缓存 + 'p' == $this->env && $redis->save($key, $api_ticket, 7000); + } else { + debug_log("[warning]# res={$res}; url={$url}", __FUNCTION__, $this->log_dir); + } + + $this->api_ticket = $api_ticket; + + return $api_ticket; + } + + /** + * 生成二维码 + * @param $filename (文件名称) + * @param $scene (最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式) + * @param $page (必须是已经发布的小程序存在的页面(否则报错),例如 pages/index/index, 根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面) + * @param $width (二维码的宽度,单位 px,最小 280px,最大 1280px,默认430px) + * @return array {'file':'文件路径', 'url':'访问相对路径'} + */ + function qrcode($filename, $scene, $page, $width) + { + $access_token = $this->access_token(); + if (!$access_token) { + debug_log("[error] " . __FUNCTION__ . ": not access_token", $this->log_dir); + return ['code' => 0, 'msg' => '获取微信token失败']; + } + + $pre_url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='; + $url = $pre_url . $access_token; + $data = array( + 'scene' => $scene, + 'page' => $page, + 'width' => $width ? $width : 430, + ); + + list($code, $res) = $this->http_post($url, $data); + $ret = json_decode($res, true); + if (isset($ret['errcode']) && 40001 == $ret['errcode']) {//token过期,重置后请求 + $url = $pre_url . $this->access_token(true); + list($code, $res) = $this->http_post($url, $data); + $ret = json_decode($res, true); + } + if (isset($ret['errcode'])) { + debug_log("[error] " . __FUNCTION__ . ": httpcode:{$code}, response:{$res}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_dir); + return ['code' => 0, 'msg' => $res['errcode']]; + } + + if ($filename) { //保存图片 + $file = APPPATH . '../www/api/wx/' . $filename . '.png'; + $dir = substr($file, 0, strrpos($file, '/')); + if (!is_dir($dir)) { + $ret = mkdir($dir, 0777, true);// 如果文件夹不存在,将以递归方式创建该文件夹 + if (!$ret) { + debug_log("[error] " . __FUNCTION__ . ": mkdir {$ret}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_dir); + return ['code' => 0, 'msg' => '创建文件夹失败']; + } + } + + if (file_exists($file)) { + return array('code' => 1, 'file' => $file, 'url' => 'wx/' . $filename . '.png'); + } + $ret = file_put_contents($file, $res); + if (false === $ret) { + debug_log("[error] " . __FUNCTION__ . ": file_put_contents {$ret}, filename:{$filename}, scene:{$scene}, page:{$page}, width:{$width}", $this->log_dir); + return ['code' => 0, 'msg' => '保存图片失败']; + } + return ['code' => 1, 'file' => $file, 'url' => 'wx/' . $filename . '.png']; + } else { //不保存图片 + return ['code' => 1, 'file' => $res]; + } + } + + /** + * @param $url + * @return mixed + */ + private function http_get($url) + { + $curl = curl_init(); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 500); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true); + curl_setopt($curl, CURLOPT_URL, $url); + + $res = curl_exec($curl); + $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + curl_close($curl); + if (200 != $code) { + $size = strlen($res); + if ($size > 5000) { + debug_log("[info]# httpcode={$code}, response is big only show size={$size}", __FUNCTION__, $this->log_dir); + } else { + debug_log("[info]# httpcode={$code}, response={$res}", __FUNCTION__, $this->log_dir); + } + return ""; + } + + return $res; + } + + /** + * @param $url + * @param $data + * @return array + */ + private function http_post($url, $data) + { + debug_log("[info] " . __FUNCTION__ . ":url={$url}, data=" . json_encode($data), $this->log_dir); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); + $res = curl_exec($ch); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + + $size = strlen($res); + if ($size > 5000) { + debug_log("[info] " . __FUNCTION__ . ":httpcode={$code}, response is big only show size={$size}", $this->log_dir); + } else { + debug_log("[info] " . __FUNCTION__ . ":httpcode={$code}, response={$res}", $this->log_dir); + } + + return array($code, $res); + } +} diff --git a/common/models/app/App_model.php b/common/models/app/App_model.php index 57185afd..52eee889 100644 --- a/common/models/app/App_model.php +++ b/common/models/app/App_model.php @@ -26,26 +26,13 @@ class App_model extends HD_Model public function appConfig($app_id = null) { $map_config = array( - 1 => array( - 'app_key' => 'liche', - 'table' => 'hd_app_liche_users', - 'model' => 'app/liche/app_liche_users_model', - 'wx' => array( - 'appid' => 'wx98e64c11aac45966', - 'secret' => 'f8eec7be1c87a1c8e40213e144821ec3', - 'pages_groupcode_detail' => 'pages/groupCode/index', - 'pages_special2' => 'pages/special2/index', - 'pages_storeInfo' => array('id' => 'biz_id', 'pages' => 'pages/storeInfo/index'), - 'pages_lantushijia' => 'pages/topicActivity/lantushijia/index', - ), - ), 2 => array( 'app_key' => 'licheb', 'table' => 'hd_app_licheb_users', 'model' => 'app/licheb/app_licheb_users_model', 'wx' => array( - 'appid' => 'wx71095d4049de3ed1', - 'secret' => 'a80eb6ed68d7bae2d804fe507a4522f7', + 'appid' => 'wx4733380c110313ec', + 'secret' => 'cfa1bb15b671f919e959100c0b4070a2', ), ), ); diff --git a/common/models/item/Item_model.php b/common/models/item/Item_model.php new file mode 100644 index 00000000..2d1afb2b --- /dev/null +++ b/common/models/item/Item_model.php @@ -0,0 +1,12 @@ +table_name, 'default'); + } +} diff --git a/common/models/receiver/Receiver_customer_sign_model.php b/common/models/receiver/Receiver_customer_sign_model.php new file mode 100644 index 00000000..01d9095c --- /dev/null +++ b/common/models/receiver/Receiver_customer_sign_model.php @@ -0,0 +1,14 @@ +table_name, 'default'); + } + +} \ No newline at end of file