FormidModel.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Models\Common;
  3. use App\Models\Model;
  4. /**
  5. * App\Models\Common\FormidModel
  6. *
  7. * @property int $id 主键
  8. * @property int $uid 用户id
  9. * @property string|null $openid openid
  10. * @property string $form_id 交互id
  11. * @property \Illuminate\Support\Carbon $created_at 交互时间
  12. * @property \Illuminate\Support\Carbon $updated_at 更新时间
  13. * @property int $state 是否使用过0未使用1使用
  14. * @property string $appid
  15. * @property string $public_id 公众号id
  16. * @property int|null $action_id 动作id
  17. * @property string|null $extra 附加数据
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel newModelQuery()
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel newQuery()
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel query()
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereActionId($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereAppid($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereCreatedAt($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereExtra($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereFormId($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereId($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereOpenid($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel wherePublicId($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereState($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereUid($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Common\FormidModel whereUpdatedAt($value)
  32. * @mixin \Eloquent
  33. */
  34. class FormidModel extends Model
  35. {
  36. protected $table = 'kdgx_charge_fpdx_miniprogram_formid';
  37. protected $fillable = ['uid', 'form_id', 'public_id', 'openid', 'state', 'action_id', 'extra'];
  38. protected $dateFormat = 'U';
  39. /**
  40. * 获取某人可用的formid
  41. * @param int $uid 用户id
  42. * @param string $pubic_id
  43. * @return string|false formid
  44. */
  45. public static function getUseFormid(int $uid, string $pubic_id)
  46. {
  47. $form = self::where(array(
  48. ['uid', $uid],
  49. ['created_at', '>', time() - 80000 * 7],
  50. ['state', 0],
  51. ['public_id', $pubic_id]
  52. ))->orderBy('id', 'asc')->first();
  53. if (!$form) {
  54. return false;
  55. } else {
  56. $form->state = 1;
  57. $form->save();
  58. return $form->form_id;
  59. }
  60. }
  61. }