login_white = array('get_userConf');//登录白名单 $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_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'); $this->load->helper('search'); $this->load->helper("order"); } //商家签到页配置信息 protected function get_conf() { $lat = $this->input_param('lat'); $lng = $this->input_param('lng'); $biz = $this->biz_model->get(['id' => $this->get_biz_id()]); $distance = get_distance($lat, $lng, $biz['lat'], $biz['lng']); if ($distance > 500) { return ['msg' => '您未在门店有效范围', 'type' => 'fail', 'fail_img' => 'https://img.liche.cn/spacestation/failed.png?t=20240607']; // throw new Exception('您未在门店的有效范围之内', ERR_PARAMS_ERROR); } $area = $this->area_model->get(['city_id' => $biz['city_id']]); $where = [ 'status' => 1, 's_time<=' => date('Y-m-d'), 'e_time>=' => date('Y-m-d'), "(province_id={$area['province_id']} or province_id=0)" => null ]; $item_row = $this->item_model->get($where); $time_out = 1800; $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); //获取小程序二维码 $wxconfig = $this->app_model->appConfig()[2]['wx']; $this->load->library("hd_wechat", $wxconfig); $width = '430px'; $result = $this->hd_wechat->qrcode('', $key, 'pages/signup/index', $width); if (!$result['code']) { throw new Exception($result['msg'], ERR_PARAMS_ERROR); } $data = [ 'uname' => "车管家 {$this->session['uname']}", 'shop' => "{$area['city_name']}-{$biz['biz_name']}", 'qcode' => base64_encode($result['file']), 'qrcode_count_time' => $time_out, 'item' => $item, // 'key' => $key ]; 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']) { return ['type' => 'fail', 'msg' => '二维码过期,请重新扫码签到']; } $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-hetong', 'title' => '用户全程0负担', 'content' => '无需额外付费,即可享受报价权益' ], [ 'icon' => 'iconfont icon-hetong', 'title' => '1次覆盖全范围', 'content' => '权益覆盖空间站所有合作品牌' ], [ 'icon' => 'iconfont icon-hetong', 'title' => '赔付至高2万元', 'content' => '根据所购车型官方指导价划分,赔付差价' ], [ 'icon' => 'iconfont icon-hetong', '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 = [ 'sid' => create_customer_no(), '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]); $sign_data['sid'] = create_customer_no($biz['city_id']); //计算距离 $distance = get_distance($lat, $lng, $biz['lat'], $biz['lng']); $biz['lat'] && $sign_data['biz_lat'] = $biz['lat']; $biz['lng'] && $sign_data['biz_lng'] = $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); //到店+1 $this->customers_model->update(array('a_num = a_num+1' => null), ['id' => $customers_row['id']]); $this->customers_entity->add_log($customers_row['id'], $biz_uid, $biz_user['uname'], "客户再次到店", 4); 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<=' => date('Y-m-d'), 'e_time>=' => date('Y-m-d'), "(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; } }