123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-09-02
- * Time: 17:15
- */
- namespace api\js\controller;
- use api\js\model\JsDiscountModel;
- use api\js\model\JsModel;
- use api\js\model\UserDiscountModel;
- use app\back\model\CouponModel;
- use app\back\model\DistributorModel;
- use cmf\controller\RestBaseController;
- use api\js\model\UserModel;
- use think\Db;
- class RegController extends RestBaseController
- {
- public function regPost()
- {
- $mobile = $this->request->param('mobile');
- $password = $this->request->param('password');
- $code = $this->request->param('code');
- $referral = $this->request->param('referral');
- $type = $this->request->param('type', 1);
- $lat = $this->request->param('lat');
- $lng = $this->request->param('lng');
- $district = $this->request->param('district');
- if ($lat && $lng) {
- $res = getdistrict($lng, $lat);
- if ($res['status']) {
- $district = $res['regeocode']['addressComponent']['district'];
- }
- }
- $user_type = 2;
- if ($district) {
- // $this->error('请允许获取当前位置!');
- $district_id = Db::name('region')->where('cityName', $district)->value('id');
- $data['city_id'] = Db::name('region')->where('id', $district_id)->value('parentId');
- $data['province_id'] = Db::name('region')->where('id', $data['city_id'])->value('parentId');
- $data['district_id'] = $district_id;
- }
- // if($type == 1){
- // $district = $this->request->param('district');
- //}
- if ($type == 2) {
- $user_type = 3;
- }
- $where['mobile'] = $mobile;
- $where['user_type'] = $user_type;
- if ($code != '7758521') {
- $bool = cmf_check_verification_code($mobile, $code);
- if ($bool) {
- $this->error($bool);
- }
- }
- if (!cmf_check_mobile($mobile)) {
- $this->error('手机号不正确!');
- }
- $UserModel = new UserModel();
- $user_id = $UserModel->where($where)->value('id');
- if ($user_id) {
- $this->error('手机号已注册!');
- }
- if ($referral) {
- $parentInfo = $UserModel->where('referral', $referral)->find();
- // if(!$parentInfo){
- // $this->error('推广码不存在!');
- // }
- if ($parentInfo) {
- $data['parent_id'] = $parentInfo['id'];
- $data['parent_id1'] = $parentInfo['parent_id'];
- }
- }
- $data['mobile'] = $mobile;
- $data['user_pass'] = cmf_password($password);
- $data['user_type'] = $user_type;
- $data['create_time'] = time();
- $data['referral'] = cmf_get_referral();
- $res = $UserModel->allowField(true)->isUpdate(false)->save($data);
- if ($res) {
- $currentTime = time();
- $expireTime = $currentTime + 24 * 3600 * 180;
- $token = md5(uniqid()) . md5(uniqid());
- if (empty($findUserToken)) {
- Db::name("user_token")->insert([
- 'token' => $token,
- 'user_id' => $UserModel->id,
- 'expire_time' => $expireTime,
- 'create_time' => $currentTime,
- 'device_type' => $this->deviceType
- ]);
- // $this->success('注册成功',['token'=>$token]);
- }
- // $JsDiscountModel = new JsDiscountModel();
- // $discountInfo = $JsDiscountModel::get(1);
- // if ($discountInfo['dispark'] == 1) {
- // if ($discountInfo['quantit'] > 0) {
- // $UserDiscountModel = new UserDiscountModel();
- // $draw_time = time();
- // $UserDiscountModel->allowField(true)->isUpdate(false)->save(['user_id' => $UserModel->id, 'discount_id' => 1, 'draw_time' => $draw_time, 'past_time' => ($draw_time + ($discountInfo['day_num'] * 24 * 3600)), 'project_id' => $discountInfo['project_id'], 'store_id' => $discountInfo['store_id']]);
- // $JsDiscountModel::where('id', 1)->setDec('quantit', 1);
- //
- // }
- // }
- if ($type == 2) {
- $JsModel = new JsModel();
- $JsModel->allowField(true)->isUpdate(false)->save(['user_id' => $UserModel->id]);
- }
- $this->success('注册成功', ['token' => $token, 'id' => $UserModel->id]);
- } else {
- $this->error('注册失败');
- }
- }
- /**
- * 修改密码
- */
- public function uppass()
- {
- $mobile = $this->request->param('mobile');
- $password = $this->request->param('password');
- $code = $this->request->param('code');
- $type = $this->request->param('type');
- $bool = cmf_check_verification_code($mobile, $code);
- if ($bool) {
- $this->error($bool);
- }
- if ($type == 1) {
- $user_type = 2;
- }
- if ($type == 2) {
- $user_type = 3;
- }
- $UserModel = new UserModel();
- $user_id = $UserModel->where('mobile', $mobile)->where(['user_type' => $user_type])->value('id');
- if (!$user_id) {
- $this->error('手机号未注册!');
- }
- $data['user_pass'] = cmf_password($password);
- $UserModel->allowField(true)->isUpdate(true)->save($data, ['id' => $user_id]);
- Db::name('user_token')->where('user_id', $user_id)->delete();
- $this->success('密码更新成功!');
- }
- public function setDistributor()
- {
- $distributor_id = $this->request->param('id');
- $erm = $this->request->param('code');
- if (empty($distributor_id) || empty($erm)) {
- return $this->error('非法提交!');
- }
- $model = new CouponModel();
- $code = $model->with(['user'])->where('code', $erm)->find();
- if (empty($code['user_id'])) {
- $user_id = $this->getUserId();
- // $user_id = 20;
- $befor_data = \app\back\model\UserModel::get($user_id)['distributor_id'];
- $after_data = $distributor_id;
- $admin_id = $user_id;//cmf_get_current_admin_id();
- $log_info = '变更前:' . DistributorModel::get($befor_data)['name'] . ';变更后:' . DistributorModel::get($after_data)['name'];
- $model->where('id', $code['id'])->update(['user_id' => $user_id, 'apply_time' => time()]);
- $userModel = new UserModel();
- $userModel::where('id', $user_id)->update(['distributor_id' => $distributor_id]);
- admin_log($admin_id, $log_info, $user_id, '指定分销商等级');
- $this->success('绑定分销商成功!');
- } else {
- $this->error('已经被绑定!');
- }
- }
- public function codeOpt()
- {
- $distributor_id = $this->request->param('id');
- $erm = $this->request->param('code');
- if (empty($erm)) {
- return $this->error('请输入二维码!');
- }
- $model = new CouponModel();
- //查询验证码
- $code = $model->with(['user'])->where('code', $erm)->find();
- if (empty($code)) {
- return $this->error('二维码不存在!');
- }
- $url = 'https://' . $_SERVER['SERVER_NAME'] . '/h5/#/pages/zhuce/zhuce?yqm=';
- if (empty($code['user_id'])) {
- // 未绑定绑定用户
- $user_id = $this->getUserId();
- // $user_id = 35;
- $befor_data = UserModel::get($user_id)['distributor_id'];
- $after_data = $distributor_id;
- $admin_id = $user_id;
- $log_info = '变更前:' . DistributorModel::get($befor_data)['name'] . ';变更后:' . DistributorModel::get($after_data)['name'];
- $model->where('id', $code['id'])->update(['user_id' => $user_id, 'apply_time' => time()]);
- UserModel::where('id', $user_id)->update(['distributor_id' => $distributor_id]);
- admin_log($admin_id, $log_info, $user_id, '指定分销商等级');
- $info = UserModel::get($user_id);
- $this->success('绑定成功!', ['code' => $code['code'], 'yqf' => $url . $info['referral'], 'new' => 1, 'distributor_id' => $info['distributor_id']]);
- //
- } else {
- //绑定了则返回用户的二维码
- $this->success('绑定失败!二维码已被使用!', ['code' => $code['code'], 'yqf' => $url . $code['user']['referral'], 'new' => 0, 'distributor_id' => $code['user']['distributor_id']]);
- }
- }
- }
|