Auction.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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('sort DESC,id DESC');
  32. $id = [];
  33. // if ($data['advance']){
  34. // $model->where('id', 'in', $id);
  35. // }
  36. $slider_image = AuctionGu::where('id', $data['auction_gu_id'])->find();
  37. $list['data'] = $model->select();
  38. $list['data'] = count($list['data']) ? $list['data']->toArray() : [];
  39. if ($list){
  40. foreach ($list['data'] as $k =>$v)
  41. {
  42. $list['data'][$k]['time'] = strtotime($v['end_time']);
  43. $list['data'][$k]['start_time'] = strtotime($v['radd_time']);
  44. $list['data'][$k]['top_time'] = strtotime($v['rend_time']);
  45. $list['data'][$k]['day'] = date('Y-m-d H:i:s', strtotime($v['end_time']));
  46. $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']]])->field('auction_id')->select();
  47. foreach ($booking as $value) {
  48. $id[] = $value['auction_id'];
  49. }
  50. if (in_array($v['id'], $id)){
  51. $list['data'][$k]['sta'] = 2; // 进入
  52. $list['data'][$k]['str'] = '进入';
  53. }else{
  54. $list['data'][$k]['sta'] = 1; // 预约
  55. $list['data'][$k]['str'] = '预约';
  56. }
  57. }
  58. $list['slider_image'] = json_decode($slider_image['slider_image']);
  59. }
  60. return $list;
  61. }
  62. /**
  63. * 更新场次
  64. * @return void
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\DbException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. */
  69. public static function frequency()
  70. {
  71. $list = self::select();
  72. foreach ($list as $k => $v){
  73. if ($v['day_time'] < time()){
  74. $find = self::find($v['id']);
  75. $find['day_time'] = strtotime(date('Y-m-d 23:59:59'));
  76. $find['frequency'] = $v['frequency'] + 1;
  77. $find->save();
  78. }
  79. }
  80. }
  81. // public static function is_new()
  82. // {
  83. // $user = User::where('is_new', 1)->select();
  84. // if ($user){
  85. // foreach ($user as $k => $v)
  86. // {
  87. // if ($v['add_time']+3600 < time()){
  88. // User::where('uid', $v['uid'])->update(['is_new' => 0]);
  89. // }
  90. //
  91. // }
  92. // }
  93. //
  94. //
  95. // }
  96. }