User.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\api\service;
  3. use think\Cache;
  4. use think\Exception;
  5. use app\api\model\User as UserModel;
  6. class User
  7. {
  8. /**
  9. * 记忆上门自提联系人
  10. * @param $userId
  11. * @param $linkman
  12. * @param $phone
  13. * @return bool
  14. */
  15. public static function setLastExtract($userId, $linkman, $phone)
  16. {
  17. // 缓存时间30天
  18. $expire = 86400 * 30;
  19. return Cache::set("{$userId}_LastExtract", compact('linkman', 'phone'), $expire);
  20. }
  21. /**
  22. * 记忆上门自提联系人
  23. * @param $userId
  24. * @return mixed
  25. */
  26. public static function getLastExtract($userId)
  27. {
  28. if ($lastExtract = Cache::get("{$userId}_LastExtract")) {
  29. return $lastExtract;
  30. }
  31. return ['linkman' => '', 'phone' => ''];
  32. }
  33. /**
  34. * 设置支付密码
  35. * @param $userId
  36. * @param $password
  37. * @return UserModel
  38. * @throws Exception
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. * @throws \think\exception\DbException
  42. */
  43. public static function setPayPassword($userId, $password)
  44. {
  45. if(empty($password)){
  46. throw new Exception('请输入6位数字密码');
  47. }
  48. if(!preg_match("/^[0-9]\d{5}$/", $password)){
  49. throw new Exception('密码格式不正确,请输入6位数字密码');
  50. }
  51. $payPassword = makePassword($password);
  52. return UserModel::where('user_id', $userId)->update(['pay_password'=>$payPassword,'update_time'=>time()]);
  53. }
  54. }