AuctionProduct.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/02
  6. */
  7. namespace app\models\auction;
  8. use crmeb\traits\ModelTrait;
  9. use crmeb\basic\BaseModel;
  10. /**
  11. * 竞拍上坪 Model
  12. * Class WechatNews
  13. * @package app\admin\model\wechat
  14. */
  15. class AuctionProduct extends BaseModel
  16. {
  17. use ModelTrait;
  18. protected $pk = 'id';
  19. protected $name = 'auction_product';
  20. protected $autoWriteTimestamp = true;
  21. /**
  22. * 竞拍商品列表
  23. * @param $data
  24. * @param $uid
  25. * @return array
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public static function list($data, $uid){
  31. $model = self::where('auction_id', $data['id'])->order('succeed_time ASC,is_show DESC,id DESC');
  32. $model = $model->page($data['page'], $data['limit']);
  33. if ($data['name']) $model->where('name', 'like', '%'.$data['name'].'%');
  34. $list = $model->select();
  35. $list = empty($list)? [] : $list->toArray();
  36. foreach ($list as &$item){
  37. $item['status'] = 1;
  38. if ($item['succeed_time'] == strtotime('today') || $item['is_show'] == 0) $item['status'] = 2;
  39. }
  40. return $list;
  41. }
  42. /**
  43. * 用户商品
  44. * @param $data
  45. * @param $uid
  46. * @return array
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public static function user_product($data, $uid){
  52. $model = self::alias('a')
  53. ->field('a.*,b.nickname')
  54. ->leftJoin('auction b', 'a.auction_id = b.id')
  55. ->where('a.uid', $uid)->order('a.id DESC');
  56. $model->page($data['page'], $data['limit']);
  57. $list = $model->select();
  58. $list = empty($list)? [] : $list->toArray();
  59. return $list;
  60. }
  61. /**
  62. * 场次时间到期用户未出售商品下架
  63. * @return void
  64. */
  65. public static function off_the_shelf(){
  66. $auction = Auction::where('rend_time', '<', date('H:i:s'))->select();
  67. if ($auction){
  68. foreach ($auction as $k => $v) {
  69. $productId = AuctionTime::where('auction_id', '=', $v['id'])->where('add_time', '=', strtotime(date('Y-m-d', time())))->column('product_id');
  70. if ($productId){
  71. $orderId = AuctionOrder::where('product_id', 'in', $productId)->where('frequency', '=', $v['frequency'])->where('status','>', 0)->column('product_id');
  72. if ($orderId){
  73. foreach ($orderId as $value){
  74. if (in_array($value, $productId))unset($productId[$value]);
  75. }
  76. }
  77. if ($productId){
  78. foreach ($productId as $item){
  79. $product = AuctionProduct::where([['id', '=', $item], ['is_admin', '=', 2]])->find();// 查找今天场次没买出去的商品下架
  80. if ($product){
  81. $product['is_show'] = 0;
  82. $product['hanging_price'] = $product['price'];
  83. $product->save();
  84. }
  85. }
  86. }
  87. $order = AuctionProduct::where([['id', 'in', $productId], ['auction_id', '=', $v['id']], ['is_admin', '=', 2]])->column('order');// 查找今天场次没买出去的商品订单
  88. AuctionOrder::where('order_id', 'in', $order)->save(['is_gs' => 0]);//订单为未挂售状态
  89. AuctionTime::where('auction_id', '=', $v['id'])->where('add_time', '<=', strtotime(date('Y-m-d', time())))->delete(); // 清除今天挂售时间
  90. }
  91. }
  92. }
  93. }
  94. public static function bs($id)
  95. {
  96. $product = AuctionProduct::where('id',$id)->find();
  97. $auction = Auction::where('id', $product['auction_id'])->find();
  98. if (!$product) return app('json')->fail('商品不存在');
  99. $time = explode(',', $auction['site']);
  100. $date = date('w', time()); // 今天星期几
  101. if ($date == 0) $date = 7;//星期天
  102. $count = count($time);
  103. $week = [
  104. 1 => 'Monday', // 星期一
  105. 2 => 'Tuesday', // 星期二
  106. 3 => 'Wednesday', // 星期三
  107. 4 => 'Thursday', // 星期四
  108. 5 => 'Friday', // 星期五
  109. 6 => 'Saturday', // 星期六
  110. 7 => 'Sunday', //星期天
  111. ];
  112. $data['gs_time'] = '';
  113. $bs = 0;
  114. if ($count <= 1){
  115. $toweek = $week[$time[0]];
  116. $bs = (strtotime("next ".$toweek) - strtotime('today'))/86400;
  117. $data['gs_time'] = date('Y-m-d H:i:s', strtotime("next ".$toweek));
  118. }else{
  119. $node = 0;
  120. foreach ($time as $item)
  121. {
  122. $node ++;
  123. if ($node < $count){
  124. if ($date >= $item and $date < $time[$node]){
  125. $bs = $time[$node] - $date;
  126. $data['gs_time'] = date('Y-m-d H:i:s', strtotime($week[$time[$node]]));
  127. }
  128. }else{
  129. if ($date >= $item){
  130. $toweek = $week[$time[0]];
  131. $bs = (strtotime("next ".$toweek) - strtotime('today'))/86400;
  132. $data['gs_time'] = date('Y-m-d H:i:s', strtotime("next ".$toweek));
  133. }
  134. }
  135. }
  136. }
  137. $hanging_price = round($product['hanging_price'] * $product['rise']/100, 2); // 溢价
  138. $anticipate = round($product['hanging_price'] * $product['deduct']/100, 2); // 扣除
  139. $give = $product['hanging_price'] * $product['give']/100;// 赠送趣豆
  140. $data['price'] = $product['hanging_price'];
  141. $data['hanging_price'] = ($product['hanging_price'] + ($hanging_price * $bs));
  142. if($data['hanging_price'] < $product['hanging_price']) return false;
  143. $data['anticipate'] = round($anticipate*$bs,2);
  144. $data['give'] = round($give*$bs,2);
  145. return $data;
  146. }
  147. }