123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace app\models\auction;
- use app\models\store\StoreProduct;
- use crmeb\services\SystemConfigService;
- use Monolog\Handler\IFTTTHandler;
- use think\facade\Db;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- /**
- * TODO 场馆model
- * Class Article
- * @package app\models\article
- */
- class Auction extends BaseModel
- {
- /**
- * 数据表主键
- * @var string
- */
- protected $pk = 'id';
- /**
- * 模型名称
- * @var string
- */
- protected $name = 'auction';
- use ModelTrait;
- public function list($data, $uid)
- {
- $model = self::where([['delete_time', '=', 0], ['status' ,'=', '1']]);
- $model->page($data['page'], $data['limit']);
- $model->order('id DESC, sort DESC');
- $id = [];
- if ($data['advance']){
- $model->where('id', 'in', $id);
- }
- $list = $model->select();
- $list = count($list) ? $list->toArray() : [];
- if ($list){
- foreach ($list as $k =>$v)
- {
- $list[$k]['time'] = strtotime($v['radd_time']) - 1800;
- $list[$k]['e_time'] = strtotime($v['rend_time']);
- $list[$k]['day'] = date('Y-m-d H:i:s', strtotime($v['radd_time']) - 1800);
- if (strtotime($v['rend_time']) < time()){
- $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']+1], ['auction_id', '=', $v['id']]])->field('auction_id')->find();
- if ($booking){
- $list[$k]['sta'] = 2; // 进入
- $list[$k]['str'] = '进入';
- }else{
- $list[$k]['sta'] = 1; // 预约
- $list[$k]['str'] = '预约';
- }
- }else{
- $booking = AuctionBooking::where([['uid', '=', $uid], ['frequency', '=', $v['frequency']], ['auction_id', '=', $v['id']]])->field('auction_id')->find();
- if ($booking){
- $list[$k]['sta'] = 2; // 进入
- $list[$k]['str'] = '进入';
- }else{
- $list[$k]['sta'] = 1; // 预约
- $list[$k]['str'] = '预约';
- }
- }
- }
- }
- return $list;
- }
- /**
- * 每日修改场次
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function frequency()
- {
- $list = self::select();
- foreach ($list as $k => $v){
- if ($v['day_time'] < time()){
- $find = self::find($v['id']);
- $find['day_time'] = strtotime(date('Y-m-d 23:59:59'));
- $find['frequency'] = $v['frequency'] + 1;
- $find->save();
- }
- }
- }
- public static function recovery()
- {
- $auction = Auction::select();
- $recovery = (int)SystemConfigService::get('recovery');
- if ($auction){
- foreach ($auction as $k => $v) {
- if (strtotime($v['rend_time'])-300 < time()){
- //关闭场次五分钟前
- $orderCount = AuctionOrder::where('auction_id', '=', $v['id'])->where('status', '>',0)->where('price', '<', $recovery)->count();// 当前订单数量
- $bok = AuctionBooking::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']]])->count();
- $count = ceil($bok * ($v['dispatch']/100));
- $orderId = AuctionOrder::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']], ['status', '>', 0]])->column('product_id');
- if ($orderCount < $count){
- // 如果购买人数没有到放单人数
- for ($x=1 ; $x <= $count; $x++){
- $orderId = AuctionOrder::where([['auction_id', '=', $v['id']], ['frequency', '=', $v['frequency']], ['status', '>', 0]])->column('product_id');
- $product = AuctionProduct::where([['auction_id', '=', $v['id']],
- ['is_show', '=', 1],
- ['id', 'notIn', $orderId],
- ['uid', '<>', 1],
- ['hanging_price', '<', $recovery]]
- )->orderRaw('rand()')
- ->limit(1)
- ->find(); // 随机出来一个商品
- $orderData = [
- 'uid' => 1,
- 'collection_id' => $product['uid'],
- 'order_id' => getNewOrderId(),
- 'auction_id' => $v['id'],
- 'product_id' => $product['id'],
- 'name' => $product['name'],
- 'image' => $product['image'],
- 'price' => $product['hanging_price'],
- 'actual_price' => $product['hanging_price'] - $product['price'],
- 'create_time' => time(),
- 'frequency' => $v['frequency']
- ];
- AuctionOrder::create($orderData);
- unset($orderData);// 清空数组
- }
- }
- $auctionProduct = AuctionProduct::where([['auction_id', '=', $v['id']], ['is_show', '=', 1],['id', 'notIn', $orderId],['hanging_price', '>', $recovery]])->select();// 如果又商品成功回收价格
- if ($auctionProduct){
- // 商品价格超出规定值进行回收
- foreach ($auctionProduct as $key => $value){
- $orderData = [
- 'uid' => 1,
- 'collection_id' => $value['uid'],
- 'order_id' => getNewOrderId(),
- 'auction_id' => $v['id'],
- 'product_id' => $value['id'],
- 'name' => $value['name'],
- 'image' => $value['image'],
- 'price' => $value['hanging_price'],
- 'actual_price' => $value['hanging_price'] - $value['price'],
- 'create_time' => time(),
- 'frequency' => $v['frequency']
- ];
- AuctionOrder::insert($orderData);
- unset($orderData); // 清空数组
- }
- }
- }
- }
- }
- }
- }
|