Auction.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. namespace app\models\auction;
  3. use app\models\store\StoreProduct;
  4. use crmeb\services\SystemConfigService;
  5. use Monolog\Handler\IFTTTHandler;
  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']]);
  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['radd_time']) - 600;
  42. $list[$k]['e_time'] = strtotime($v['rend_time']);
  43. $list[$k]['day'] = date('Y-m-d H:i:s', strtotime($v['radd_time']) - 600);
  44. if (strtotime($v['rend_time']) < time()){
  45. $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']+1], ['auction_id', '=', $v['id']]])->field('auction_id')->find();
  46. if ($booking){
  47. $list[$k]['sta'] = 2; // 进入
  48. $list[$k]['str'] = '进入';
  49. }else{
  50. $list[$k]['sta'] = 1; // 预约
  51. $list[$k]['str'] = '预约';
  52. }
  53. }else{
  54. $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']], ['auction_id', '=', $v['id']]])->field('auction_id')->find();
  55. if ($booking){
  56. $list[$k]['sta'] = 2; // 进入
  57. $list[$k]['str'] = '进入';
  58. }else{
  59. $list[$k]['sta'] = 1; // 预约
  60. $list[$k]['str'] = '预约';
  61. }
  62. }
  63. }
  64. }
  65. return $list;
  66. }
  67. /**
  68. * 每日修改场次
  69. * @return void
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\DbException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. */
  74. public static function frequency()
  75. {
  76. $list = self::select();
  77. foreach ($list as $k => $v){
  78. if ($v['day_time'] < time()){
  79. $find = self::find($v['id']);
  80. $find['day_time'] = strtotime(date('Y-m-d 23:59:59'));
  81. $find['frequency'] = $v['frequency'] + 1;
  82. $find->save();
  83. }
  84. }
  85. }
  86. public static function recovery()
  87. {
  88. $auction = Auction::select();
  89. $recovery = (int)SystemConfigService::get('recovery');
  90. if ($auction){
  91. foreach ($auction as $k => $v) {
  92. if (strtotime($v['rend_time'])-600 < time()){
  93. //关闭场次五分钟前
  94. $orderCount = AuctionOrder::where('auction_id', '=', $v['id'])->where('frequency', '=', $v['frequency'])->where('status', '>',0)->where('price', '<', $recovery)->count();// 当前订单数量
  95. $bok = AuctionBooking::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']]])->count();
  96. $count = ceil($bok * ($v['dispatch']/100));
  97. $orderId = AuctionOrder::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']], ['status', '>', 0]])->column('product_id');
  98. if ($orderCount < $count){;
  99. // 如果购买人数没有到放单人数
  100. $dayo = AuctionOrder::where('auction_id', '=', $v['id'])->where('frequency', '=', $v['frequency'])->where('status', '>',0)->where('price', '<', $recovery)->column('product_id');// 当前出售商品
  101. $product = AuctionProduct::where([['id', 'notIn', $dayo], ['uid', '>', 1], ['price', '<', $recovery], ['auction_id', '=', $v['id']]])->select();
  102. if ($product){
  103. foreach ($product as &$item){
  104. $orderData = [
  105. 'uid' => 1,
  106. 'collection_id' => $item['uid']? $item['uid']: 0,
  107. 'order_id' => getNewOrderId(),
  108. 'auction_id' => $v['id'],
  109. 'product_id' => $item['id'],
  110. 'name' => $item['name'],
  111. 'image' => $item['image'],
  112. 'price' => $item['hanging_price'],
  113. 'actual_price' => $item['hanging_price'] - $item['price'],
  114. 'create_time' => time(),
  115. 'frequency' => $v['frequency']
  116. ];
  117. AuctionOrder::create($orderData);
  118. unset($orderData);// 清空数组
  119. }
  120. }
  121. }
  122. $auctionProduct = AuctionProduct::where([['auction_id', '=', $v['id']], ['is_show', '=', 1],['id', 'notIn', $orderId],['hanging_price', '>', $recovery]])->select();// 如果又商品成功回收价格
  123. if ($auctionProduct){
  124. // 商品价格超出规定值进行回收
  125. foreach ($auctionProduct as $key => $value){
  126. $orderData = [
  127. 'uid' => 1,
  128. 'collection_id' => $value['uid'],
  129. 'order_id' => getNewOrderId(),
  130. 'auction_id' => $v['id'],
  131. 'product_id' => $value['id'],
  132. 'name' => $value['name'],
  133. 'image' => $value['image'],
  134. 'price' => $value['hanging_price'],
  135. 'actual_price' => $value['hanging_price'] - $value['price'],
  136. 'create_time' => time(),
  137. 'frequency' => $v['frequency']
  138. ];
  139. AuctionOrder::insert($orderData);
  140. unset($orderData); // 清空数组
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }