| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\api\service;
- use think\Cache;
- use think\Exception;
- use app\api\model\User as UserModel;
- class User
- {
- /**
- * 记忆上门自提联系人
- * @param $userId
- * @param $linkman
- * @param $phone
- * @return bool
- */
- public static function setLastExtract($userId, $linkman, $phone)
- {
- // 缓存时间30天
- $expire = 86400 * 30;
- return Cache::set("{$userId}_LastExtract", compact('linkman', 'phone'), $expire);
- }
- /**
- * 记忆上门自提联系人
- * @param $userId
- * @return mixed
- */
- public static function getLastExtract($userId)
- {
- if ($lastExtract = Cache::get("{$userId}_LastExtract")) {
- return $lastExtract;
- }
- return ['linkman' => '', 'phone' => ''];
- }
- /**
- * 设置支付密码
- * @param $userId
- * @param $password
- * @return UserModel
- * @throws Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function setPayPassword($userId, $password)
- {
- if(empty($password)){
- throw new Exception('请输入6位数字密码');
- }
- if(!preg_match("/^[0-9]\d{5}$/", $password)){
- throw new Exception('密码格式不正确,请输入6位数字密码');
- }
- $payPassword = makePassword($password);
- return UserModel::where('user_id', $userId)->update(['pay_password'=>$payPassword,'update_time'=>time()]);
- }
- }
|