diff --git a/app/api/controller/order/OrderController.php b/app/api/controller/order/OrderController.php index 27553902d..7c6866763 100644 --- a/app/api/controller/order/OrderController.php +++ b/app/api/controller/order/OrderController.php @@ -181,6 +181,17 @@ class OrderController extends BaseApiController } $user=User::where('id',$this->userId)->find(); + if($pay_type == PayEnum::PURCHASE_FUNDS || $pay_type == PayEnum::BALANCE_PAY ){ + if(!$params['password']){ + return $this->fail('缺失参数'); + } + if(empty($user['pay_password'])){ + return $this->fail('请设置密码'); + } + if (payPassword($params['password']) != $user['pay_password']){ + return $this->fail('密码错误'); + } + } $order = OrderLogic::createOrder($cartId, $addressId, $user, $params); diff --git a/app/api/controller/user/UserController.php b/app/api/controller/user/UserController.php index 2f2e921e9..72f06cf85 100644 --- a/app/api/controller/user/UserController.php +++ b/app/api/controller/user/UserController.php @@ -7,6 +7,8 @@ use app\api\logic\user\UserLogic; use app\api\validate\UserValidate; use app\common\enum\PayEnum; use app\common\logic\PaymentLogic; +use support\Cache; +use think\Exception; /** @@ -133,4 +135,55 @@ class UserController extends BaseApiController return $this->success('ok',$res); } + public function send_sms() + { + $res = (new UserLogic())->dealSendSms($this->userId); + if ($res){ + return $this->success('发送成功'); + } + return $this->fail('发送失败'); + } + + + + public function set_payPassword() + { + $params = (new UserValidate())->post()->goCheck('setPayPassword'); + $remark = $this->userId.'_payPassword'; + $code = Cache::get($remark); + if ($code && isset($params['code']) && $code !== $params['code']) { + throw new Exception('验证码错误'); + } + if ($params['rePassword'] !== $params['password']) + return $this->fail('两次密码不一致'); + $result = UserLogic::dealPayPassword($params,$this->userId); + if (!$result) { + return $this->fail('设置失败'); + } + return $this->success('设置成功'); + } + + + + //修改 +// public function withdrawalPassword() +// { +// $data = $this->request->params(['repassword', 'password', 'sms_code']); +// $sms_code = app()->make(SmsService::class)->checkSmsCode($this->user->phone, $data['sms_code'], 'change_pwd'); +// if (!$data['sms_code'] || !$sms_code) { +// return app('json')->fail('验证码不正确'); +// } +// if (!$this->user->phone) +// return app('json')->fail('请先绑定手机号'); +// if (empty($data['repassword']) || empty($data['password'])) +// return app('json')->fail('请输入提现密码'); +// if ($data['repassword'] !== $data['password']) +// return app('json')->fail('两次密码不一致'); +// $password = $this->repository->encodePassword($data['password']); +// $this->repository->update($this->request->uid(), ['withdrawal_pwd' => $password]); +// return app('json')->success('绑定成功'); +// +// } + + } diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php index e6b493914..277da81b9 100644 --- a/app/api/logic/user/UserLogic.php +++ b/app/api/logic/user/UserLogic.php @@ -14,7 +14,9 @@ use app\common\{logic\BaseLogic, model\user\User, model\user\UserRecharge, model\user\UserShip, + service\SmsService, service\wechat\WeChatMnpService}; +use support\Cache; use think\facade\Db; @@ -164,5 +166,36 @@ class UserLogic extends BaseLogic ->select()->toArray(); } + public function dealSendSms($uid) + { + $code = generateRandomCode(); + $phone = User::where('id',$uid)->value('mobile'); + if(empty($phone)){ + throw new \Exception('用户未设置手机号'); + } + $template = getenv('SMS_TEMPLATE'); + $check =(new SmsService())->client($phone,$template,$code); + if($check){ + $remark = $uid.'_payPassword'; + Cache::set($remark,$code,5*60); + return true; + }else{ + return false; + } + + } + + + + + + public static function dealPayPassword($params,$uid) + { + $password = payPassword($params['password']); + return User::where('id',$uid) + ->update(['pay_password'=>$password]); + + } + } \ No newline at end of file diff --git a/app/api/validate/UserValidate.php b/app/api/validate/UserValidate.php index d670e7327..ba6a46b39 100644 --- a/app/api/validate/UserValidate.php +++ b/app/api/validate/UserValidate.php @@ -18,14 +18,26 @@ class UserValidate extends BaseValidate 'code' => 'require', 'store_id' => 'require', 'mobile' => 'require', + 'phone' => 'require|number', + 'password' => 'require', + 'rePassword' => 'require', + ]; protected $message = [ 'code.require' => '参数缺失', 'store_id.require' => '门店id', 'mobile.require' => '手机', + 'phone.require' => '手机', + 'password.require' => '密码', + 'rePassword.require' => '确认密码', ]; + //设置/更新密码 + public function sceneSetPayPassword() + { + return $this->only(['code','password','rePassword']); + } /** * @notes 获取小程序手机号场景 diff --git a/app/functions.php b/app/functions.php index 2eb20b6ed..c4edbadea 100644 --- a/app/functions.php +++ b/app/functions.php @@ -476,3 +476,14 @@ if (!function_exists('countRate')) { return bcmul(bcdiv((bcsub($nowValue, $lastValue, 2)), $lastValue, 4), 100, 2); } } + + +if (!function_exists('payPassword')) { + //支付密码 + function payPassword($password){ + return password_hash($password,PASSWORD_BCRYPT); + } +} + + + diff --git a/app/store/controller/store_order/StoreOrderController.php b/app/store/controller/store_order/StoreOrderController.php index e69c4f048..486fab101 100644 --- a/app/store/controller/store_order/StoreOrderController.php +++ b/app/store/controller/store_order/StoreOrderController.php @@ -23,7 +23,9 @@ use app\common\model\system_store\SystemStore; use app\common\model\system_store\SystemStoreStaff; use app\common\model\user_recharge\UserRecharge; use app\store\validate\store_order\StoreOrderValidate; +use support\Cache; use support\Log; +use think\Exception; use Webman\RedisQueue\Redis; /** @@ -136,6 +138,13 @@ class StoreOrderController extends BaseAdminController if (count($cartId) > 100) { return $this->fail('购物车商品不能超过100个'); } + if($pay_type == PayEnum::PURCHASE_FUNDS){ + $remark = $uid.'_smsPay'; + $code = Cache::get($remark); + if ($code && isset($params['code']) && $code !== $params['code']) { + throw new Exception('验证码错误'); + } + } $user = null; if ($uid) { $user = User::where('id', $uid)->find();