| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- <?php
- namespace app\controller;
- use app\business\LoginBusiness;
- use app\business\SmsBusiness;
- use app\business\StreamBusiness;
- use Illuminate\Support\Arr;
- use Respect\Validation\Validator;
- use support\Db;
- use support\Redis;
- use support\Request;
- use hg\apidoc\annotation as Apidoc;
- use Webman\Captcha\CaptchaBuilder;
- use Webman\Captcha\PhraseBuilder;
- #[Apidoc\Title("登陆注册")]
- #[Apidoc\Group("Login")]
- #[Apidoc\Sort(1)]
- class LoginController
- {
- #[Apidoc\Title("登录")]
- #[Apidoc\Url("api/login/login.html")]
- #[Apidoc\Method("POST")]
- #[Apidoc\Param("mobile", type: "int", require: true, desc: "账号/手机号", mock: 16500000000)]
- #[Apidoc\Param("app", type: "int", require: true, desc: "是否为APP", mock: '')]
- #[Apidoc\Param("password", type: "string", require: true, desc: "密码(6-16字母加数字)位密码", mock: 123456)]
- #[Apidoc\Param("code", type: "int", require: true, desc: "验证码")]
- #[Apidoc\Param("key", type: "string", require: true, desc: "验证码的key")]
- public function login(Request $request)
- {
- $param = $request->param_data;
- Db::beginTransaction();
- try {
- $param = Arr::only($param, ['mobile', 'password', 'app', 'code', 'key']);
- Validator::input($param, [
- 'mobile' => Validator::notEmpty()->intType()->setName('手机号'),
- 'password' => Validator::notEmpty()->stringType()->Length(6, 15)->alnum()->setName('密码'),
- 'code' => Validator::notEmpty()->intType()->setName('验证码'),
- 'key' => Validator::notEmpty()->stringType()->setName('验证码标识'),
- ]);
- /* if(empty(preg_match('/^1[3-9]\d{9}$/', $param['mobile']))){
- throw new \Exception('请输入正确的手机号');
- }*/
- if (strtolower($param['code']) != Redis::get($param['key'])) {
- throw new \Exception('验证码错误!');
- }
- $param['last_ip'] = $request->getRealIp($safe_mode = true);
- $token = LoginBusiness::login($param);
- Redis::del($param['key']);
- } catch (\Throwable $exception) {
- Db::rollBack();
- return error($exception->getMessage());
- }
- Db::commit();
- return success([
- 'token' => $token
- ]);
- }
- #[Apidoc\Title("注册")]
- #[Apidoc\Url("api/login/register.html")]
- #[Apidoc\Method("POST")]
- // #[Apidoc\Header("token",type: "string",require: true,desc: "身份令牌Token",mock: "@token")]
- #[Apidoc\Param("mobile", type: "int", require: true, desc: "账号/手机号", mock: 15800000000)]
- #[Apidoc\Param("password", type: "string", require: true, desc: "密码(6-16字母加数字)位密码", mock: 123456)]
- #[Apidoc\Param("confirm_password", type: "string", require: true, desc: "确认密码(6-16字母加数字)位密码", mock: 123456)]
- #[Apidoc\Param("invitation_code", type: "int", require: true, desc: "邀请码", mock: 100001)]
- #[Apidoc\Param("code", type: "int", require: true, desc: "验证码")]
- #[Apidoc\Param("key", type: "string", require: true, desc: "验证码的key")]
- public function register(Request $request)
- {
- $param = $request->param_data;
- Db::beginTransaction();
- try {
- $param = Arr::only($param, ['mobile', 'password', 'confirm_password', 'invitation_code', 'code', 'key']);
- Validator::input($param, [
- 'mobile' => Validator::notEmpty()->intType()->setName('手机号'),
- 'password' => Validator::notEmpty()->stringType()->Length(6, 15)->alnum()->setName('密码'),
- 'confirm_password' => Validator::notEmpty()->stringType()->Length(6, 15)->alnum()->setName('确认密码'),
- 'invitation_code' => Validator::notEmpty()->intType()->setName('邀请码'),
- 'code' => Validator::notEmpty()->intType()->setName('验证码'),
- 'key' => Validator::notEmpty()->stringType()->setName('验证码标识'),
- ]);
- /* if(empty(preg_match('/^1[3-9]\d{9}$/', $param['mobile']))){
- throw new \Exception('请输入正确的手机号');
- }
- */
- if (strtolower($param['code']) != Redis::get($param['key'])) {
- throw new \Exception('验证码错误!');
- }
- Redis::del($param['key']);
- if ($param['password'] != $param['confirm_password']) {
- throw new \Exception('两次密码不一致!');
- }
- $param['last_ip'] = $request->getRealIp($safe_mode = true);
- $param['join_ip'] = $param['last_ip'];
- $token = LoginBusiness::register($param);
- } catch (\Throwable $exception) {
- Db::rollBack();
- return error($exception->getMessage());
- }
- Db::commit();
- return success([
- 'token' => $token
- ]);
- }
- // #[Apidoc\Title("注册领取")]
- // #[Apidoc\Url("api/login/register_receive.html")]
- // #[Apidoc\Method("POST")]
- // #[Apidoc\Header("token", type: "string", require: true, desc: "身份令牌Token", mock: "@token")]
- // public function register_receive(Request $request)
- // {
- // $param = $request->all();
- // Db::beginTransaction();
- // try {
- // $user = Db::table('wa_users')->where('id', $request->user_data['id'])->first();
- // $system = Db::table('wa_system')->first();
- // /** @var $has 查是否已经领取 */
- // $has = Db::table('wa_stream')
- // ->where('user_id', $request->user_data['id'])
- // ->where('type', streamType1)
- // ->where('mold', moldType5)
- // ->exists();
- // if (!empty($has)) {
- // throw new \Exception('已经领取该奖励了,不能重复领取!');
- // }
- //
- // /** 注册赠送 */
- // if (!empty($system) && !empty($user) && !empty($system->register_award)) {//注册赠送
- // StreamBusiness::addStream($request->user_data['id'], $system->register_award, streamType1, moldType5, moldTypefild5);
- // }
- // } catch (\Throwable $exception) {
- // Db::rollBack();
- // return error($exception->getMessage());
- // }
- // Db::commit();
- // return success([], '领取成功');
- // }
- #[Apidoc\Title("验证码")]
- #[Apidoc\Url("api/login/authccode.html")]
- #[Apidoc\Method("POST")]
- // #[Apidoc\Header("token",type: "string",require: true,desc: "身份令牌Token",mock: "@token")]
- #[Apidoc\Returned(name: "img", type: "blob", require: true, desc: '图形验证码', default: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD//gA7')]
- #[Apidoc\Returned(name: "key", type: "string", require: true, desc: '验证码KEY', default: 'authccode172036979253337')]
- public function authccode()
- {
- $phraseBuilder = new PhraseBuilder(4, '123456789');
- $builder = new CaptchaBuilder(null, $phraseBuilder);
- // 生成验证码
- $builder->build(100, 29);
- $key = 'authccode' . time() . mt_rand(10000, 99999);
- Redis::setEx($key, 600, strtolower($builder->getPhrase()));
- $img_content = $builder->inline();
- return success(['img' => $img_content, 'key' => $key]);
- }
- #[Apidoc\Title("邀请规则")]
- #[Apidoc\Url("api/login/invite.html")]
- #[Apidoc\Method("POST")]
- #[Apidoc\Header("token", type: "string", require: true, desc: "身份令牌Token", mock: "@token")]
- #[Apidoc\Returned(name: "invite", type: "array", desc: '活动规则', default: '', children: [
- ['name' => "id", 'type' => 'int', 'require' => true, 'default' => 1, 'desc' => '规则ID'],
- ['name' => "num", 'type' => 'int', 'require' => true, 'default' => 1, 'desc' => '邀请人'],
- ['name' => "money", 'type' => 'int', 'require' => true, 'default' => 38, 'desc' => 'USD '],
- ['name' => "complete", 'type' => 'int', 'require' => true, 'default' => 0, 'desc' => '完成人数'],
- ['name' => "has", 'type' => 'int', 'require' => true, 'default' => false, 'desc' => '是否领奖 true 已领奖 false 未领奖'],
- ])]
- #[Apidoc\Returned(name: "uuid", type: "string", require: true, desc: '邀请码', default: '10001')]
- #[Apidoc\Returned(name: "is_num", type: "string", require: true, desc: '累计邀请人数', default: '10001')]
- #[Apidoc\Returned(name: "gift_gold", type: "int", require: true, desc: '已助力脱贫次数', default: '1')]
- #[Apidoc\Returned(name: "raffle_num", type: "int", require: true, desc: '可助力**次', default: '1')]
- #[Apidoc\Returned(name: "invitation_award", type: "int", require: true, desc: '每助力脱贫一次获得', default: '1')]
- public function invite(Request $request)
- {
- $invite = Db::table('wa_invite')->where('status', 1)
- ->orderBy('sort')->get()->toArray();
- foreach ($invite as $k => $v) {
- $invite[$k]->complete = $request->user_data['is_num'];
- $invite[$k]->has = Db::table('wa_stream')
- ->where('user_id', $request->user_data['id'])
- ->where('type', streamType3)
- ->where('source_id', $v->id)->exists();
- }
- $system = Db::table('wa_system')->first();
- return success([
- 'invite' => $invite,
- 'uuid' => $request->user_data['uuid'],
- 'is_num' => $request->user_data['is_num'],
- 'raffle_num' => $request->user_data['raffle_num'],
- 'gift_gold' => $system->gift_gold,
- 'boost_gift' => $system->boost_gift,
- 'original_boost_gift' => $system->original_boost_gift,
- ]);
- }
- #[Apidoc\Title("邀请领奖")]
- #[Apidoc\Url("api/login/invite_receive.html")]
- #[Apidoc\Method("POST")]
- #[Apidoc\Header("token", type: "string", require: true, desc: "身份令牌Token", mock: "@token")]
- #[Apidoc\Param("id", type: "int", require: true, desc: '邀请规则ID', mock: 1)]
- public function invite_receive(Request $request)
- {
- $param = $request->param_data;
- Db::beginTransaction();
- try {
- $param = Arr::only($param, ['id']);
- Validator::input($param, [
- 'id' => Validator::notEmpty()->intType()->setName('标识'),
- ]);
- if (!empty(Redis::get($param['id'] . $request->user_data['id']))) {
- throw new \Exception('请不要连续操作');
- }
- Redis::setEx($param['id'] . $request->user_data['id'], 5, $request->user_data['id']);
- $inviteData = Db::table('wa_invite')->where('id', $param['id'])->first();
- if (empty($inviteData)) {
- throw new \Exception('非法操作');
- }
- if ($request->user_data['is_num'] < $inviteData->num) {
- throw new \Exception('未达到,邀请规则!');
- }
- $has = Db::table('wa_stream')
- ->where('user_id', $request->user_data['id'])
- ->where('type', streamType3)
- ->where('source_id', $param['id'])
- ->exists();
- if (!empty($has)) {
- throw new \Exception('已领取过奖励!');
- }
- if (!empty($inviteData->money)) {
- StreamBusiness::addStream($request->user_data['id'], $inviteData->money, streamType3, moldType1, moldTypefild1, $inviteData->id);
- }
- if (!empty($inviteData->money_one)) {
- for ($i = 1; $i <= $inviteData->money_one; $i++) {
- $goodsdata = Db::table('wa_sign_goods')->where('id',23)->first();
- $signId = Db::table('wa_sign_record')->insertGetId([
- 'uid' => $request->user_data['id'],
- 'goods_id' => $goodsdata->id,
- 'num' => 1,
- 'money' => 0,
- 'type' => $goodsdata->type,
- 'status' => 1,
- 'order_no' => date('YmdHis') . mt_rand(1000, 9999),
- 'created_at' => date('Y-m-d H:i:s'),
- 'updated_at' => date('Y-m-d H:i:s'),
- ]);
- $thisDay = date('Y-m-d H:i:s');
- /** @var $futureDay 未来时间 */
- $futureDay = futureDay(999);
- if (!empty($goodsdata->highest_pay_price)) {
- Db::table('wa_cron_task_sign_two')->insert([
- 'user_id' => $request->user_data['id'],
- 'goods_id' => $goodsdata->id,
- 'order_id' => $signId,
- 'money' => 0,
- 'bonus' => 0,
- 'goods_type' => $goodsdata->type,
- 'day_dividend_time' => strtotime(date('Y-m-d', strtotime('+1 days')) . ' 01:00:00'),
- 'dividend_time' => strtotime($futureDay),
- 'created_at' => $thisDay,
- 'updated_at' => $thisDay,
- 'my_good_id' => $signId,
- 'highest_pay_price' => $goodsdata->highest_pay_price,
- 'day' => $goodsdata->day,
- 'bl' => $goodsdata->bl,
- 'progress' => $goodsdata->progress,
- ]);
- }
- }
- }
- if (!empty($inviteData->money_two)) {
- StreamBusiness::addStream($request->user_data['id'], $inviteData->money_two, streamType3, moldType5, moldTypefild5, $inviteData->id);
- }
- } catch (\Throwable $exception) {
- Db::rollBack();
- return error($exception->getMessage());
- }
- Db::commit();
- return success([], '领取成功');
- }
- #[Apidoc\Title("判断当前用户是否存在是否实名")]
- #[Apidoc\Url("api/login/sign_in.html")]
- #[Apidoc\Method("POST")]
- #[Apidoc\Param("mobile", type: "int", require: true, desc: "账号/手机号", mock: 15800000000)]
- #[Apidoc\Returned(name: "is_sign_in", type: "int", require: true, desc: '是否实名 1=未实名,2=实名', default: '1')]
- public function signIn(Request $request)
- {
- $param = $request->param_data;
- Db::beginTransaction();
- try {
- $param = Arr::only($param, ['mobile']);
- Validator::input($param, [
- 'mobile' => Validator::notEmpty()->intType()->setName('手机号'),
- ]);
- $userlist = Db::table('wa_users')->where('mobile', $param['mobile'])->first();
- if (!$userlist) {
- throw new \Exception('请输入正确手机号!');
- }
- $is_sign_in = 1;
- if ($userlist->is_autonym == 1) {
- $is_sign_in = 2;
- }
- $data = ['is_sign_in' => $is_sign_in];
- } catch (\Throwable $exception) {
- Db::rollBack();
- return error($exception->getMessage());
- }
- Db::commit();
- return success($data, '请求成功');
- }
- #[Apidoc\Title("未登陆修改密码")]
- #[Apidoc\Url("api/login/passsave.html")]
- #[Apidoc\Method("POST")]
- #[Apidoc\Param("mobile", type: "int", require: true, desc: "手机号", mock: 15800000000)]
- #[Apidoc\Param("number", type: "string", require: true, desc: "身份证", mock: 1123)]
- #[Apidoc\Param("password", type: "int", require: true, desc: "密码", mock: 123456)]
- public function passsave(Request $request)
- {
- $param = $request->param_data;
- Db::beginTransaction();
- try {
- Validator::input($param, [
- 'mobile' => Validator::notEmpty()->intType()->setName('手机号'),
- 'password' => Validator::notEmpty()->setName('密码'),
- ]);
- $userlist = Db::table('wa_users')->where('mobile', $param['mobile'])->first();
- if (!$userlist) {
- throw new \Exception('请输入正确手机号!');
- }
- if ($userlist->is_autonym == 1) {
- if (empty($param['number'])) {
- throw new \Exception('请输入身份证号码!');
- }
- $identity = Db::table('wa_user_identity')->where('uid', $userlist->id)->where('number', $param['number'])->first();
- if (!$identity) {
- throw new \Exception('输入的身份证号码和实名信息不一致!');
- }
- }
- Db::table('wa_users')->where('id', $userlist->id)->update(['password' => md5($param['password'])]);
- } catch (\Throwable $exception) {
- Db::rollBack();
- return error($exception->getMessage());
- }
- Db::commit();
- return success([], '修改成功');
- }
- #[Apidoc\Title("参与助力")]
- #[Apidoc\Url("api/login/boost.html")]
- #[Apidoc\Method("POST")]
- #[Apidoc\Header("token", type: "string", require: true, desc: "身份令牌Token", mock: "@token")]
- public function boost(Request $request)
- {
- $param = $request->param_data;
- Db::beginTransaction();
- try {
- $userdata = Db::table('wa_users')->where('id', $request->user_data['id'])->first();
- if ($userdata->raffle_num <= 0) {
- throw new \Exception('助力次数不足!');
- }
- if (!empty(Redis::get('111' . $request->user_data['id']))) {
- throw new \Exception('慢点操作!');
- }
- Redis::setEx('111' . $request->user_data['id'], 5, $request->user_data['id']);
- $system = Db::table('wa_system')->first();
- if (!empty($system->boost_gift)) {
- StreamBusiness::addStream($request->user_data['id'], $system->boost_gift, streamType11, moldType1, moldTypefild1);
- }
- Db::table('wa_users')->where('id', $request->user_data['id'])->decrement('raffle_num', 1);
- Db::table('wa_system')->where('id', 1)->increment('gift_gold', 3);
- } catch (\Throwable $exception) {
- Db::rollBack();
- return error($exception->getMessage());
- }
- Db::commit();
- return success([], '领取成功');
- }
- }
|