request->post('user_id'); if (!isset($user_id)) { return $this->result('网络错误', [], 100); } $data = UsersModel::where('user_id', $user_id)->find(); $data['daifahuo'] = 1; $data['daishouhuo'] = 1; if ($data) { return $this->result('', $data, 200); } else { return $this->result('未获取用户信息', [], 100); } } /** * 修改昵称 * @ApiMethod (POST) * @param string $user_id 用户id * @param string $user_nickname 用户昵称 */ public function updNickName() { $params = $this->request->post(); if (!isset($params['user_id']) || !isset($params['user_nickname'])) { return $this->result('网络错误', [], 100); } $data['user_nickname'] = $params['user_nickname']; $data['user_id'] = $params['user_id']; $selNickName = UsersModel::where($data)->find(); if ($selNickName) { return $this->result('请输入新昵称', [], 100); } $userModel = new UsersModel(); $updNickName = $userModel->allowField(true)->save($data, ['user_id' => $params['user_id']]); if ($updNickName) { return $this->result('修改成功', [], 200); } else { return $this->result('修改失败', [], 100); } } /** * 修改密码 * @ApiMethod (POST) * @param string $user_id 用户id * @param string $user_pwd 用户密码 * @param string $user_qrpwd 重复 密码 */ public function updPwd() { $params = $this->request->post(); $rules = [ 'user_id' => 'require|number', 'user_pwd' => 'require|max:18|min:6', 'user_qrpwd' => 'require', ]; $msg = [ 'user_id.require' => '用户id不能为空', 'user_id.number' => '用户i为整形', 'user_pwd.require' => '密码不能为空', 'user_pwd.max' => '密码最大18位', 'user_pwd.min' => '密码最小6位', 'user_qrpwd.require' => '重复密码不能为空', ]; $validata = $this->validate($params, $rules, $msg); if (is_string($validata)) { return $this->result($validata, [], 100); } if ($params['user_pwd'] != $params['user_qrpwd']) { return $this->result('两次密码输入不一致', [], 100); } $data = array( 'user_id' => $params['user_id'], 'user_pwd' => sha1(md5($params['user_pwd'])), ); $model = new UsersModel(); $updPwd = $model->allowField(true)->save($data, ['user_id' => $data['user_id']]); if ($updPwd) { return $this->result('修改成功', [], 200); } else { return $this->result('修改失败', [], 100); } } /** * 修改支付密码 * @ApiMethod (POST) * @param string $user_id 用户id * @param string $user_tel 手机号 * @param string $code 验证码 * @param string $user_paypwd 支付密码 * @param string $user_qrpaypwd 确认支付密码 */ public function updPayPwd() { $params = $this->request->post(); $rules = [ 'user_tel' => "require|number", 'user_id' => "require|number", 'code' => "require", 'user_paypwd' => "require|number", 'user_qrpaypwd' => "require", ]; $msg = [ 'user_tel.require' => '手机号不能为空', 'user_id.require' => '网络错误', 'user_code.require' => '验证码不能为空', 'user_paypwd.require' => '支付密码不能为空', 'user_qrpaypwd.require' => '支付密码不能为空', 'user_paypwd.number' => '支付密码只支持数字', 'user_code.number' => '验证码只支持数字', 'user_id.number' => '网络错误', 'user_tel.number' => '手机号不合法', ]; $validata = $this->validate($params, $rules, $msg); if (is_string($validata)) { return $this->result($validata, [], 100); } if ($params['user_paypwd'] != $params['user_qrpaypwd']) { return $this->result('两次密码输入不一致', [], 100); } $code = Cache::get($params['code']); if (!$code) { return $this->result('验证码错误', [], 100); // 验证验证码 } $data = array( 'user_id' => $params['user_id'], 'user_paypwd' => $params['user_paypwd'], ); $user = new UsersModel(); $validataTel = $user->where('user_id', $data['user_id'])->where('user_tel', $params['user_tel'])->find(); if (!$validataTel) { return $this->result('请使用此账号手机号修改密码', [], 100); } $validataPayPwd = $user->where($data)->find(); if ($validataPayPwd) { return $this->result('请输入新密码', [], 100); } $updPayPwd = $user->allowField(true)->save($data, ['user_id' => $data['user_id']]); if ($updPayPwd) { Cache::rm($params['code']); // 删除缓存验证码 return $this->result('修改成功', [], 200); } else { return $this->result('修改失败', [], 100); } } /** * 实名认证 * * @ApiMethod (POST) * @param string $user_id 用户id * @param string $user_nickname 姓名 * @param string $idcard 身份证号 */ public function realName() { $params = $this->request->post(); $rules = [ 'user_id' => 'require|number', 'user_nickname' => 'require', 'idcard' => 'require' ]; $msg = [ 'user_id.require' => '网络错误', 'user_nickname.require' => '姓名不能为空', 'idcard.require' => '身份证号不能为空', 'user_id.number' => '网络错误', ]; $validata = $this->validate($params, $rules, $msg); if (is_string($validata)) { return $this->result($validata, [], 100); } $is_name = UsersModel::where('user_id', $params['user_id'])->where('is_realname', 1)->find(); if ($is_name) { return $this->result('您已经实名认证过了', [], 100); } $realName = new Realname(); $res = $realName->realName($params); return $res; } /** * 常见问题 * @ApiMethod (POST) */ public function question() { $data = Db::name('question')->find(); if ($data) { return $this->result('', $data, 200); } else { return $this->result('', $data, 100); } } /** * 我的团队 * @ApiMethod (POST) * @param string $user_id 用户id */ public function team() { $user_id = $this->request->post('user_id'); if (!$user_id) { return $this->result('网络错误', [], 100); } $user = UsersModel::where('user_id', $user_id)->find(); if (!$user) { return $this->result('网络错误', [], 100); } $data['syj'] = UsersModel::where('user_tel', $user['user_tjtel'])->find(); if (!$data['syj']) { $data['syj'] = []; } $data['team'] = UsersModel::where('user_tjtel', $user['user_tel'])->select(); if (!$data['team']) { $data['team'] = []; } return $this->result('', $data, 200); } /** * 我的地址 * @ApiMethod (POST) * @param string $user_id 用户id */ public function address() { $user_id = $this->request->post('user_id'); if (!isset($user_id)) { return $this->result('网络错误', [], 100); } $data = Address::where('user_id', $user_id)->select(); if ($data) { return $this->result('', $data, 200); } else { return $this->result('暂无数据', [], 100); } } /** * 地址添加 * @ApiMethod (POST) * @param string $user_id 用户id * @param string $a_name 姓名 * @param string $a_tel 手机号 * @param string $city 城市 * @param string $area 详细地址 * @param string $is_default 1默认0不默认 */ public function addressAdd() { $params = $this->request->post(); $rules = [ 'user_id' => 'require|number', 'a_name' => 'require', 'city' => 'require', 'area' => 'require', 'is_default' => 'require|number|max:1', ]; $msg = [ 'user_id.require' => '网络错误', 'a_name.require' => '姓名不能为空', 'city.require' => '地区不能为空', 'area.require' => '详细地址不能为空', 'is_default.require' => '网络错误', 'is_default.number' => '网络错误', 'is_default.max' => '网络错误', 'user_id.number' => '网络错误', ]; $validata = $this->validate($params, $rules, $msg); if (is_string($validata)) { return $this->result($validata, [], 100); } if (isset($params['a_tel'])) { $check = '/^(1(([35789][0-9])|(47)))\d{8}$/'; if (!preg_match($check, $params['a_tel'])) { return $this->result('手机号不合法', [], 100); } } else { return $this->result('手机号不能为空', [], 100); } $model = new Address(); $addressAdd = $model->allowField(true)->save($params); if ($addressAdd) { return $this->result('添加成功', '', 200); } else { return $this->result('添加失败', '', 100); } } /** * 地址修改 * @ApiMethod (POST) * @param string $a_id 地址id * @param string $a_name 姓名 * @param string $a_tel 手机号 * @param string $city 城市 * @param string $area 详细地址 * @param string $is_default 1默认0不默认 */ public function addressUpd() { $params = $this->request->post(); $count = count($params); if ($count < 2) { return $this->result('请至少修改一项', [], 100); } if (!isset($params['a_id'])) { return $this->result('网络错误', [], 100); } $model = new Address(); $addressUpd = $model->allowField(true)->save($params, ['a_id' => $params['a_id']]); if ($addressUpd) { return $this->result('修改成功', '', 200); } else { return $this->result('修改失败', '', 100); } } /** * 地址删除 * @ApiMethod (POST) * @param string $a_id 地址id */ public function addressDel() { $a_id = $this->request->post('a_id'); if (!isset($a_id)) { return $this->result('网络错误', [], 100); } $model = new Address(); $addressDel = $model->where('a_id', $a_id)->delete(); if ($addressDel) { return $this->result('修改成功', '', 200); } else { return $this->result('修改失败', '', 100); } } /** * 我的客服 * @ApiMethod (POST) */ public function coursetomer() { $data = Db::name('coustomer')->select(); if ($data) { return $this->result('', $data, 200); } else { return $this->result('暂无数据', [], 100); } } /** * 我的红豆 * @ApiMethod (POST) * @param string $user_id 用户id */ public function redbean() { $user_id = $this->request->post('user_id'); if (!isset($user_id)) { return $this->result('网络错误', [], 100); } $redbean = UsersModel::where('user_id', $user_id)->field('user_id, user_redbean')->find(); if ($redbean) { return $this->result('', $redbean, 200); } else { return $this->result('网络错误', [], 100); } } /** * 我的红豆 * @ApiMethod (POST) * @param string $user_id 用户id * @param string $user_redbean 兑换个数 */ public function useRedBean() { $params = $this->request->post(); if (!isset($params['user_id'])) { return $this->result('网络错误', [], 100); } if (!isset($params['user_redbean'])) { return $this->result('网络错误', [], 100); } $redbean = UsersModel::where('user_id', $params['user_id'])->field('user_id, user_redbean')->find(); if ($params['user_redbean'] > $redbean['user_redbean'] || $params['user_redbean'] < 1) { return $this->result('提现个数错误', [], 100); } Db::startTrans(); try { $upd = UsersModel::where('user_id', $params['user_id'])->setDec('user_redbean', $params['user(redbean']); Db::commit(); } catch (\Exception $e) { Db::rollback(); $data = array( 'user_id' => $params['user_id'], 't_type' => 1, 'state' => 2, 'number' => '-' . $params['user_id'], 'create_time' => date("Y-m-d H:i:s", time()), ); $record = new Record(); $recordadd = $record->allowField(true)->save($data); if ($recordadd) { return $this->result('兑换失败', '', 100); } else { return $this->result('网络错误', '', 100); } } if ($upd) { $data = array( 'user_id' => $params['user_id'], 't_type' => 1, 'state' => 1, 'number' => '-' . $params['user_id'], 'create_time' => date("Y-m-d H:i:s", time()), ); $record = new Record(); $recordadd = $record->allowField(true)->save($data); if ($recordadd) { return $this->result('兑换成功', '', 200); } else { return $this->result('网络错误', '', 100); } } else { return $this->result('网络错误', '', 100); } } /** * 我的红豆兑换记录 * @ApiMethod (POST) * @param string $user_id 用户id */ public function redbeanRecord() { $params = $this->request->post(); if (!isset($params['user_id'])) { return $this->result('网络错误', [], 100); } $data = Record::where('user_id', $params['user_id'])->order('r_id desc')->select(); if ($data) { return $this->result('', $data, 200); } else { return $this->result('暂无数据', [], 100); } } /** * 我的足迹显示 * @ApiMethod (POST) * @param string $user_id 用户id */ public function footIndex() { $params = $this->request->post(); if (!isset($params['user_id'])) { return $this->result('网络错误', [], 100); } $data = Foot::with('commodity') ->where('user_id', $params['user_id']) ->select(); if ($data) { return $this->result('', $data, 200); } else { return $this->result('暂无数据', '', 100); } } /** * 我的足迹删除 * @ApiMethod (POST) * @param string $f_id 足迹id */ public function footDel() { $params = $this->request->post(); if (!isset($params['f_id'])) { return $this->result('网络错误', [], 100); } $footDel = Foot::where('f_id', $params['f_id'])->delete(); if ($footDel) { return $this->result('删除成功', [], 200); } else { return $this->result('删除失败', [], 100); } } /** * 会员提现价格显示 * @ApiMethod (POST) */ public function cashMoney() { $data = Db::name('cash_money')->select(); return $this->result('', $data, 200); } /** * 会员提现到第几次 * @ApiMethod (POST) * @param string $user_id 用户id */ public function cashIndex() { $params = $this->request->post(); if (!isset($params['user_id'])) { return $this->result('网络错误', [], 100); } $data = UsersModel::Where('user_id', $params['user_id'])->field('user_id,cash_level')->find(); if ($data) { return $this->result('', $data, 200); } else { return $this->result('网络错误', '', 100); } } /** * 会员提现 * @ApiMethod (POST) * @param string $user_id 用户id * @param string $money 金额 */ public function cash() { $params = $this->request->post(); $rules = [ 'user_id' => 'require|number', 'money' => 'require|number', ]; $msg = [ 'user_id.require' => '网络错误', 'money.require' => '请选择提现金额', 'user_id.number' => '网络错误', 'money.number' => '网络错误', ]; $validata = $this->validate($params,$rules,$msg); if (is_string($validata)) { return $this->result($validata,[],100); } if(!preg_match("/^[1-9][0-9]*$/" ,$params['money'])){ return $this->result('请输入正整数',[],100); } // //检测提现金额表中是否有这个金额 $is_money = Db::name('cash_money')->where('money',$params['money'])->find(); // if (!$is_money) { // return $this->result('该金额暂不支持提现',[],100); // } // //判断是否该提现这个次数了 $user_cash_level = UsersModel::where('user_id',$params['user_id'])->find(); // if ($user_cash_level) { // if ($user_cash_level['cash_level'] + 1 != 9) { //最后一个不算 // if($is_money['c_id'] != $user_cash_level['cash_level'] + 1) { // return $this->result('请按照顺序提现',[],100); // } // } // } if ($user_cash_level['user_money'] < $params['money']) { return $this->result('余额不足',[],100); } if ($user_cash_level['type'] != 1) { return $this->result('请先微信授权在提现',[],100); } Db::startTrans(); try{ $updMoney = UsersModel::where('user_id',$params['user_id'])->setDec('user_money',$params['money']); Db::commit(); } catch (\Exception $e) { Db::rollback(); return $this->result('网络错误,提现失败',[],100); } if ($updMoney) { $number = rand(100,999).time(); $data = [ 'user_id' => $params['user_id'], 'money' => $params['money'], 'state' => 1, 'create_time' => date('Y-m-d H:i:s',time()), 'number' => $number, ]; $add_log = Db::name('cash_log')->insert($data); $cashWeChat = new Cashwechat(); $res = $cashWeChat->sendMoney(1,"oRrdQt-L9A0WfDGT-nwHC24Er0tI",'余额提现',$user_cash_level['user_nickname'],$number); return $res; } } }