RoutineFormId.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\models\routine;
  3. use crmeb\basic\BaseModel;
  4. use crmeb\traits\ModelTrait;
  5. /**
  6. * TODO 表单ID表
  7. * Class RoutineFormId
  8. * @package app\models\routine
  9. */
  10. class RoutineFormId extends BaseModel
  11. {
  12. /**
  13. * 数据表主键
  14. * @var string
  15. */
  16. protected $pk = 'id';
  17. /**
  18. * 模型名称
  19. * @var string
  20. */
  21. protected $name = 'routine_form_id';
  22. use ModelTrait;
  23. /**
  24. * TODO 删除已失效的formID
  25. * @return bool
  26. * @throws \Exception
  27. */
  28. public static function delStatusInvalid()
  29. {
  30. return self::where('status', 2)->where('stop_time', '<', time())->delete();
  31. }
  32. /**
  33. * TODO
  34. * @param int $uid
  35. * @param bool $isArray
  36. * @return array|bool|mixed|null|\think\Model
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. * @throws \think\exception\DbException
  40. */
  41. public static function getFormIdOne($uid = 0, $isArray = false)
  42. {
  43. $formId = self::where('status', 1)->where('stop_time', '>', time())->where('uid', $uid)->order('id asc')->find();
  44. if ($isArray) return $formId;
  45. if ($formId) return $formId['form_id'];
  46. else return false;
  47. }
  48. /**
  49. * 修改一个FormID为已使用
  50. * @param string $formId
  51. * @return $this|bool
  52. */
  53. public static function delFormIdOne($formId = '')
  54. {
  55. if ($formId == '') return true;
  56. return self::where('form_id', $formId)->update(['status' => 2]);
  57. }
  58. /**
  59. * TODO 创建formid
  60. * @param $formId
  61. * @param $uid
  62. * @return RoutineFormId|bool|\think\Model
  63. */
  64. public static function SetFormId($formId, $uid)
  65. {
  66. if (!strlen(trim($formId)) || $formId == 'the formId is a mock one') return false;
  67. $data['form_id'] = $formId;
  68. $data['uid'] = $uid;
  69. $data['status'] = 1;
  70. $data['stop_time'] = bcadd(time(), bcmul(6, 86400, 0), 0);
  71. return self::create($data);
  72. }
  73. }