Auction.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\models\auction;
  3. use app\models\store\StoreProduct;
  4. use app\models\user\User;
  5. use crmeb\services\SystemConfigService;
  6. use think\facade\Db;
  7. use crmeb\traits\ModelTrait;
  8. use crmeb\basic\BaseModel;
  9. /**
  10. * TODO 场馆model
  11. * Class Article
  12. * @package app\models\article
  13. */
  14. class Auction extends BaseModel
  15. {
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'auction';
  26. use ModelTrait;
  27. public function list($data, $uid)
  28. {
  29. $model = self::where([['delete_time', '=', 0], ['status' ,'=', '1'], ['auction_gu_id', '=', $data['auction_gu_id']]]);
  30. $model->page($data['page'], $data['limit']);
  31. $model->order('id DESC, sort DESC');
  32. $id = [];
  33. // if ($data['advance']){
  34. // $model->where('id', 'in', $id);
  35. // }
  36. $list = $model->select();
  37. $list = count($list) ? $list->toArray() : [];
  38. if ($list){
  39. foreach ($list as $k =>$v)
  40. {
  41. $list[$k]['time'] = strtotime($v['end_time']);
  42. $list[$k]['day'] = date('Y-m-d H:i:s', strtotime($v['end_time']));
  43. $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']]])->field('auction_id')->select();
  44. foreach ($booking as $value) {
  45. $id[] = $value['auction_id'];
  46. }
  47. if (in_array($v['id'], $id)){
  48. $list[$k]['sta'] = 2; // 进入
  49. $list[$k]['str'] = '进入';
  50. }else{
  51. $list[$k]['sta'] = 1; // 预约
  52. $list[$k]['str'] = '预约';
  53. }
  54. }
  55. }
  56. return $list;
  57. }
  58. /**
  59. * 更新场次
  60. * @return void
  61. * @throws \think\db\exception\DataNotFoundException
  62. * @throws \think\db\exception\DbException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. */
  65. public static function frequency()
  66. {
  67. $list = self::select();
  68. foreach ($list as $k => $v){
  69. if ($v['day_time'] < time()){
  70. $find = self::find($v['id']);
  71. $find['day_time'] = strtotime(date('Y-m-d 23:59:59'));
  72. $find['frequency'] = $v['frequency'] + 1;
  73. $find->save();
  74. }
  75. }
  76. }
  77. // public static function is_new()
  78. // {
  79. // $user = User::where('is_new', 1)->select();
  80. // if ($user){
  81. // foreach ($user as $k => $v)
  82. // {
  83. // if ($v['add_time']+3600 < time()){
  84. // User::where('uid', $v['uid'])->update(['is_new' => 0]);
  85. // }
  86. //
  87. // }
  88. // }
  89. //
  90. //
  91. // }
  92. }