123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-09-12
- * Time: 9:33
- */
-
- namespace api\js\controller;
-
-
- use api\js\model\JsModel;
- use cmf\controller\RestBaseController;
- use think\Db;
- use think\Log;
- class IndexController extends RestBaseController
- {
- public function index()
- {
- $navList = Db::name('index_nav')->where('pos',1)->order('list_order','asc')->select()->each(function ($navList){
- $navList['icon'] = cmf_get_image_preview_url($navList['icon']);
- return $navList;
- });
- $banner = Db::name('slide_item')->where('slide_id',1)->where('status',1)->order('list_order','asc')->select()->each(function ($banner){
- $banner['image'] = cmf_get_image_preview_url($banner['image']);
- return $banner;
- });
-
- $lat = $this->request->param('lat',1);//维度
- $lng = $this->request->param('lng',1);//经度
- $lat = $lat > 1 ? $lat :37.475375;
- $lng = $lng> 1 ? $lng :121.373573;
-
- $JsModel = new JsModel();
- $jsList = $JsModel->getLits([],$lat,$lng);
- $this->success('ok',['nav'=>$navList,'banner'=>$banner,'js'=>$jsList]);
- }
-
-
-
- public function getRegion()
- {
- $parentId = $this->request->param('parentId');
- $pdepth = $this->request->param('depth',1);
- if($parentId){
- $where['parentId'] = $parentId;
- }
-
- $where['depth'] = $pdepth;
- $list = Db::name('region')->where($where)->field('id,cityName')->select();
- $this->success('ok',$list);
- }
-
- public function getOut()
- {
- $list = Db::name('project_out')->select();
- $this->success('ok',$list);
- }
-
- public function getWXLog()
- {
- $this->success('ok',1);
- }
-
- public function getdow()
- {
- $info = cmf_get_option('dow');
- $this->success('ok',$info);
- }
-
- public function getKefu()
- {
- $info = Db::name('portal_post')->where('id',6)->find();
-
- $this->success('ok',$info['phone']);
- }
- public function bindWechat(){
- $validate = new \think\Validate([
- 'mobile' => 'require',
- 'code' => 'require',
- 'openid' => 'require',
- ]);
- $validate->message([
- 'mobile.require' => '请输入您的手机号',
- 'code.require' => '验证码不能为空!',
- 'openid' => '微信授权失败!'
- ]);
-
-
- $data = $this->request->param();
-
- if (!$validate->check($data)) {
- $this->error($validate->getError());
- }
- $type = $data['type'];
-
- unset($data['type']);
- $findUserWhere = [];
- if (cmf_check_mobile($data['mobile'])) {
- $findUserWhere['mobile'] = $data['mobile'];
- } else {
- $this->error('手机号格式错误');
- }
- if ($type == 1) {
- $findUserWhere['user_type'] = 2;
- }
- if ($type == 2) {
- $findUserWhere['user_type'] = 3;
- }
-
- $isExist = UserModel::name("user")->where('user_type', $findUserWhere['user_type'])
- ->where('openid', $data['openid'])->count();
-
- if (!$isExist) {
- $findUser = UserModel::name("user")->where($findUserWhere)->find();
- if (empty($findUser)) {
- // 用户不存在
- } else {
- if ($findUser->openid) {
- $this->error("账号已绑定其他微信!");
- }
- Db::name('user')->where('id', $findUser['id'])->update(['openid' => $data['openid']]);
- }
-
-
- if (empty($this->deviceType) && (empty($data['device_type']) || !in_array($data['device_type'], $this->allowedDeviceTypes))) {
- $this->error("请求错误,未知设备!");
- } else if (!empty($data['device_type'])) {
- $this->deviceType = $data['device_type'];
- }
-
- $findUserToken = Db::name("user_token")
- ->where('user_id', $findUser['id'])
- ->where('device_type', $this->deviceType)
- ->find();
- $currentTime = time();
- $expireTime = $currentTime + 24 * 3600 * 180;
- $token = md5(uniqid()) . md5(uniqid());
- if (empty($findUserToken)) {
- $result = Db::name("user_token")->insert([
- 'token' => $token,
- 'user_id' => $findUser['id'],
- 'expire_time' => $expireTime,
- 'create_time' => $currentTime,
- 'device_type' => $this->deviceType
- ]);
- } else {
- $result = Db::name("user_token")
- ->where('user_id', $findUser['id'])
- ->where('device_type', $this->deviceType)
- ->update([
- 'token' => $token,
- 'expire_time' => $expireTime,
- 'create_time' => $currentTime
- ]);
- }
-
- if (empty($result)) {
- $this->error("登录失败!");
- }
-
- Db::name('user')->where('id', $findUser['id'])->update(['last_login_ip' => get_client_ip(), 'last_login_time' => time()]);
- $this->success("登录成功!", ['token' => $token, 'id' => $findUser['id']]);
- } else {
- $this->error("微信已绑定其他账号!");
- }
- }
- }
|