RoutineFormId.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. return self::where('status',2)->where('stop_time','<',time())->delete();
  30. }
  31. /**
  32. * TODO
  33. * @param int $uid
  34. * @param bool $isArray
  35. * @return array|bool|mixed|null|\think\Model
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. */
  40. public static function getFormIdOne($uid = 0, $isArray = false){
  41. $formId = self::where('status',1)->where('stop_time','>',time())->where('uid',$uid)->order('id asc')->find();
  42. if($isArray) return $formId;
  43. if($formId) return $formId['form_id'];
  44. else return false;
  45. }
  46. /**
  47. * 修改一个FormID为已使用
  48. * @param string $formId
  49. * @return $this|bool
  50. */
  51. public static function delFormIdOne($formId = ''){
  52. if($formId == '') return true;
  53. return self::where('form_id',$formId)->update(['status'=>2]);
  54. }
  55. /**
  56. * TODO 创建formid
  57. * @param $formId
  58. * @param $uid
  59. * @return RoutineFormId|bool|\think\Model
  60. */
  61. public static function SetFormId($formId, $uid)
  62. {
  63. if(!strlen(trim($formId)) || $formId == 'the formId is a mock one') return false;
  64. $data['form_id'] = $formId;
  65. $data['uid'] = $uid;
  66. $data['status'] = 1;
  67. $data['stop_time'] = bcadd(time(),bcmul(6,86400,0),0);
  68. return self::create($data);
  69. }
  70. }