123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- <?php
- namespace app\models\auction;
- use app\admin\model\user\User;
- use app\admin\model\user\UserBill;
- use crmeb\services\product\Product;
- use crmeb\services\SystemConfigService;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- class AuctionOrder extends BaseModel
- {
- use ModelTrait;
- protected $pk = 'id';
- protected $name = 'auction_order';
- protected $autoWriteTimestamp = true;
-
- public static function userOrder($data, $uid)
- {
- if ($data['order_id']) {
- $list = self::alias('a')
- ->field('a.*,u.nickname,u.avatar,u.uid as user_id,c.nickname as c_nickname,pay.phone')
- ->leftJoin('user u', 'a.uid = u.uid')
- ->leftJoin('user c', 'a.collection_id = c.uid')
- ->leftJoin('auction_pay pay', 'a.collection_id = pay.uid')
- ->where('a.order_id', $data['order_id'])->find();
- $product = AuctionProduct::where('id', $list['product_id'])->find();
- $list['actual_price'] = round($list['price'] - $product['fictitious_price'], 2);
- $pay = AuctionPay::where('uid', $list['collection_id'])->select();
- $list['wx'] = [];
- $list['zfb'] = [];
- $list['bank'] = [];
- $list['time'] = strtotime($list['create_time']);
- if ($pay) {
- foreach ($pay as $k => $v) {
- if ($v['type'] == 1) {
- $list['wx'] = $v;
- } elseif ($v['type'] == 2) {
- $list['zfb'] = $v;
- } elseif ($v['type'] == 3) {
- $list['bank'] = $v;
- }
- }
- }
- } else {
- if ($data['type'] == 1) {
- $list = self::where([['uid', '=', $uid], ['status', '=', 1]])->order('id DESC')->page($data['page'], $data['limit'])->select();
- } else if ($data['type'] == 2) {
- $list = self::where([['uid', '=', $uid], ['status', '=', 2]])->order('id DESC')->page($data['page'], $data['limit'])->select();
- } else if ($data['type'] == 3) {
- $list = self::where([['uid', '=', $uid], ['status', '=', 3], ['is_gs', '=', 1]])->order('id DESC')->page($data['page'], $data['limit'])->select();
- } else if ($data['type'] == 4) {
- $list = AuctionProduct::where([['uid', '=', $uid], ['is_show', '=', 0]])
- ->page($data['page'], $data['limit'])
- ->select();
- if ($list) {
- foreach ($list as $k => $v) {
- $list[$k]['product_id'] = $v['id'];
- $list[$k]['is_gs'] = 0;
- $list[$k]['order_id'] = $list[$k]['order'];
- $list[$k]['price'] = $v['hanging_price'];
- }
- }
- } else {
- $list = self::where([['uid', '=', $uid]])->order('id DESC')->page($data['page'], $data['limit'])->select();
- }
- }
- $list = !empty($list) ? $list->toArray() : [];
- return $list;
- }
-
- public static function seller_list($data, $uid)
- {
- if ($data['order_id']) {
- $list = self::alias('a')
- ->field('a.*,u.nickname,u.avatar,u.uid as user_id')
- ->leftJoin('user u', 'a.uid = u.uid')
- ->where('a.order_id', $data['order_id'])->find();
- $product = AuctionProduct::where('id', $list['product_id'])->find();
- $list['actual_price'] = $list['price'] - $product['fictitious_price'];
- $list = empty($list) ? [] : $list->toArray();
- return $list;
- } else {
- if ($data['type'] == 1) {
- $status = 1;
- } else if ($data['type'] == 2) {
- $status = 2;
- } else if ($data['type'] == 3) {
- $status = 3;
- } else {
- $status = 0;
- }
- if ($data['type'] == 4) {
- $product = AuctionTime::alias('a')
- ->field('FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as gs_time,au.nickname,b.*')
- ->order('a.id DESC')
- ->where([['a.uid', '=', $uid]])
- ->where('b.is_admin', 2)
- ->page($data['page'], $data['limit'])
- ->leftJoin('auction_product b', 'a.product_id = b.id')
- ->leftJoin('auction au', 'au.id = a.auction_id')
- ->select();
- } else {
- if ($status == 0) {
- $list = self::alias('a')
- ->field('a.*,u.nickname,u.avatar,u.uid as user_id')
- ->leftJoin('user u', 'a.uid = u.uid')
- ->order('id DESC')
- ->where([['a.collection_id', '=', $uid]])
- ->page($data['page'], $data['limit'])
- ->select();
- } else {
- $list = self::alias('a')
- ->field('a.*,u.nickname,u.avatar,u.uid as user_id')
- ->leftJoin('user u', 'a.uid = u.uid')
- ->order('id DESC')
- ->where([['a.collection_id', '=', $uid], ['a.status', '=', $status]])
- ->page($data['page'], $data['limit'])
- ->select();
- }
- }
- }
- if ($data['type'] != 4) {
- $list = !empty($list) ? $list->toArray() : [];
- foreach ($list as $k => $v) {
- $pay = AuctionPay::where('uid', $v['uid'])->find();
- $list[$k]['phone'] = $pay['phone'];
- }
- return $list;
- } else {
- $product = empty($product) ? [] : $product->toArray();
- return $product;
- }
- }
-
- public static function earn($id, $price, $product)
- {
- $userModel = new \app\models\user\User();
- $productModel = new AuctionProduct();
- $user = $userModel->find($id);
- AuctionTime::where([['product_id', '=', $product['id']]])->delete();
- $productModel->where('id', $product['id'])->save(['is_show' => 0]);
- }
-
- public static function return($id)
- {
- $data = self::find($id);
- $userModel = new User();
- $productModel = new AuctionProduct();
- $auctionModel = new Auction();
- $bookingModel = new AuctionBooking();
- $frozenModel = new AuctionFrozen();
- $user = $userModel->find($data['uid']);
-
-
-
-
-
-
-
-
-
-
-
-
-
- $product = $productModel->where('id', $data['product_id'])->find();
- $auction = $auctionModel->where('id', $product['auction_id'])->find();
- $booking = $bookingModel->where('auction_id', $auction['id'])->where('uid', $user['uid'])->where('frequency', $data['frequency'])->find();
- $fz = $frozenModel->where('order_id', $data['order_id'])->where('status', 1)->where('uid', $user['uid'])->find();
- if ($fz){
- $fz['status'] = 0;
- $anticipate = $fz['anticipate'] - $fz['deduction'];
- $user['anticipate'] = $user['anticipate'] + $anticipate;
- $user->save();
- $fz->save();
- UserBill::income('易趣卷退还',$user['uid'], 'anticipate', 'th_anticipate', $anticipate, $user['spread_uid'], $user['anticipate'], '退还订单'.$data['order_id'].'易趣卷,扣除' . $fz['deduction']);
- }else{
- if ($booking['status'] > 0) {
- $booking['status'] = 0;
- $anticipate = $booking['anticipate'] - $booking['deduction'];
- $user['anticipate'] = $user['anticipate'] + $anticipate;
- $user->save();
- $booking->save();
- UserBill::income('易趣卷退还',$user['uid'], 'anticipate', 'th_anticipate', $anticipate, $user['spread_uid'], $user['anticipate'], '退还预约易趣卷扣除' . $booking['deduction']);
- }
- }
- }
-
- public static function deduction()
- {
- $one = (int)SystemConfigService::get('one_time');
- $tow = (int)SystemConfigService::get('tow_time');
- $hour = time() - ($one * 60);
- $time = time() - ($tow * 60);
- $order = AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->select();
- if ($order) {
- foreach ($order as $K => $v) {
- $product = AuctionProduct::where('id', $v['product_id'])->find();
- $auction = Auction::where('id', $product['auction_id'])->find();
- $kc_time = strtotime($auction['radd_time']);
- if ($kc_time < time()){
- if (strtotime($v['create_time']) < $kc_time) $v['create_time'] = date('Y-m-d H:i:s', $kc_time);
- $booking = AuctionBooking::where([['uid', '=', $v['uid']], ['status', '=', 1], ['auction_id', '=', $auction['id']], ['frequency', '=', $auction['frequency']]])->find();
- $fz = AuctionFrozen::where('order_id', $v['order_id'])->where('status', 1)->find();
- $userl = \app\models\user\User::where('uid', $v['uid'])->find();
- if ($fz) {
- if (strtotime($v['create_time']) <= $hour and strtotime($v['create_time']) > $time) {
-
- if ($fz['deduction'] == 0) {
- $user = \app\models\user\User::where('uid', $v['collection_id'])->find();
- $user['anticipate'] = $user['anticipate'] + $fz['anticipate'] / 2;
- $fz['deduction'] = $fz['anticipate'] / 2;
- UserBill::income('超时增加', $v['collection_id'], 'anticipate', 'ad_anticipate', $fz['anticipate'] / 2, $v['uid'], $user['anticipate'], '(' . $userl['nickname'] . '-' . $userl['uid'] . ')超时付款,增加易趣卷');
- UserBill::expend('超时扣除', $v['uid'], 'anticipate', 'dec_anticipate', $fz['anticipate'] / 2, $v['uid'], $fz['anticipate'] / 2, '超时付款,扣除订单'.$v['order_id'].'冻结'. ($fz['anticipate'] / 2) . '易趣卷');
- $fz->save();
- $user->save();
- }
- } elseif (strtotime($v['create_time']) <= $time) {
- $user = \app\models\user\User::where('uid', $v['collection_id'])->find();
- $dedu = $fz['anticipate'] - $fz['deduction'];
- $user['anticipate'] += $dedu;
- $fz['deduction'] = $fz['anticipate'];
- $fz['status'] = 2;
- $product['succeed_time'] = 0;
- $product->save();
- $user->save();
- \app\models\user\User::where('uid', $v['uid'])->update(['status' => 0, 'freeze_time' => strtotime('+1 day')]);
- UserBill::income('超时增加', $v['collection_id'], 'anticipate', 'ad_anticipate', $dedu, $v['uid'], $user['anticipate'], '(' . $userl['nickname'] . '-' . $userl['uid'] . ')超时付款,增加易趣卷');
- UserBill::expend('超时扣除', $v['uid'], 'anticipate', 'dec_anticipate', $dedu, $v['uid'], 0, '超时付款,扣除订单'.$v['order_id'].'冻结' . $dedu . '易趣卷');
- $fz->save();
- AuctionOrder::where('id', $v['id'])->where('status', '=', 1)->update(['status' => 0]);
- }
- } else {
- if (strtotime($v['create_time']) <= $hour and strtotime($v['create_time']) > $time) {
-
- if ($booking) {
- if ($booking['deduction'] == 0) {
- $user = \app\models\user\User::where('uid', $v['collection_id'])->find();
- $user['anticipate'] = $user['anticipate'] + $booking['anticipate'] / 2;
- $booking['deduction'] = $booking['anticipate'] / 2;
- UserBill::income('超时增加', $v['collection_id'], 'anticipate', 'ad_anticipate', $booking['anticipate'] / 2, $v['uid'], $user['anticipate'], '(' . $userl['nickname'] . '-' . $userl['uid'] . ')超时付款,增加易趣卷');
- UserBill::expend('超时扣除', $v['uid'], 'anticipate', 'dec_anticipate', $booking['anticipate'] / 2, $v['uid'], $booking['anticipate'] / 2, '超时付款,扣除预约冻结' . ($booking['anticipate'] / 2) . '易趣卷');
- $booking->save();
- $user->save();
- }
- }
- } elseif (strtotime($v['create_time']) <= $time) {
- if ($booking) {
- $user = \app\models\user\User::where('uid', $v['collection_id'])->find();
- $dedu = $booking['anticipate'] - $booking['deduction'];
- $user['anticipate'] += $dedu;
- $booking['deduction'] = $booking['anticipate'];
- $booking['status'] = 2;
- $product['succeed_time'] = 0;
- $product->save();
- $user->save();
- \app\models\user\User::where('uid', $v['uid'])->update(['status' => 0, 'freeze_time' => strtotime('+1 day')]);
- UserBill::income('超时增加', $v['collection_id'], 'anticipate', 'ad_anticipate', $dedu, $v['uid'], $user['anticipate'], '(' . $userl['nickname'] . '-' . $userl['uid'] . ')超时付款,增加易趣卷');
- UserBill::expend('超时扣除', $v['uid'], 'anticipate', 'dec_anticipate', $dedu, $v['uid'], 0, '超时付款,扣除预约冻结' . $dedu . '易趣卷');
- $booking->save();
- AuctionOrder::where('id', $v['id'])->where('status', '=', 1)->update(['status' => 0]);
- }
- }
- }
- }
- }
- }
- }
-
- public static function th()
- {
- $auction = Auction::where('rend_time', '<', date('H:i:s', time()))->select();
- if ($auction) {
- foreach ($auction as $k => $v) {
- $booking = AuctionBooking::where([['auction_id', '=', $v['id']], ['status', '=', 1]])->select();
- if ($booking) {
- foreach ($booking as $key => $value) {
- $product = AuctionProduct::where('auction_id', $value['auction_id'])->column('id');
- $order = AuctionOrder::where([['product_id', 'in', $product], ['frequency', '=', $value['frequency']], ['uid', '=', $value['uid']]])->find();
- if (!$order) {
- $find = AuctionBooking::find($value['id']);
- $find['status'] = 0;
- $user = User::where('uid', $value['uid'])->find();
- $user['anticipate'] = $user['anticipate'] + $value['anticipate'];
- $user->save();
- $find->save();
- UserBill::income('退回易趣卷', $user['uid'], 'anticipate', 'add_anticipate', $value['anticipate'], 0, $user['anticipate'], '易趣卷' . $value['anticipate'] . '退回');
- }
- }
- }
- }
- }
- }
- public static function goods()
- {
- $order = AuctionOrder::where('status', 2)->select();
- if ($order) {
- foreach ($order as &$item) {
- $auction = Auction::where('id', $item['auction_id'])->value('goods_time');
- $time = $item['voucher_time'] + ($auction * 60);
- if (time() > $time) {
-
- $product = AuctionProduct::where('id', $item['product_id'])->find();
- if ($product['uid'] == $item['uid']) {
- self::where('id', $item['id'])->update(['status' => 3]);
- }else{
- $product['uid'] = $item['uid'];
- $product['add_time'] = 111111;
- $product['order'] = $item['order_id'];
- self::where('id', $item['id'])->update(['status' => 3]);
- self::earn($item['uid'], $item['price'], $product);
- self::return($item['id']);
- $product->save();
- }
- }
- }
- }
- }
- public static function auction_time()
- {
- $auction = Auction::where('status', 1)->select();
- if ($auction){
- foreach ($auction as $item){
- $addtime = strtotime($item['radd_time']);
- $rendtime = strtotime($item['rend_time']);
- if (($addtime-360) < time() and $addtime > time()){
- $model = AuctionProduct::where('is_show', 1)->where('auction_id', $item['id'])->order('id DESC');
- $list = $model->select();
- $list = empty($list)? [] : $list->toArray();
- $lists = [];
- if ($list){
- foreach ($list as $k => $v) {
- $order = AuctionOrder::where('product_id', $v['id'])->where('status', '>', 0)->where('auction_id', $item['id'])->where('frequency', $item['frequency'])->find();
- if ($order){
- $list[$k]['status'] = 2;
- $list[$k]['str'] = '已卖完';
- }else{
- $list[$k]['status'] = 1;
- $list[$k]['str'] = '购买';
- }
- if ($v['is_admin'] == 2){
- $time = AuctionTime::where([['product_id', '=', $v['id']], ['add_time', '<=', strtotime(date('Y-m-d', time()))]])->find();
- if (!$time){
- unset($list[$k]);
- } else{
- $lists[] = $list[$k];
- }
- }else{
- $lists[] = $list[$k];
- }
- }
- }
- $redis = new \Redis();
- $redis->connect('127.0.0.1','6379', 3600);
- foreach ($lists as $k => $v) {
- if ($v['status'] == 1) {
- if (!$redis->llen($v['id']) > 0) {
- $redis->lPush($v['id'], json_encode($v));
- }
- }
- }
- }
- }
- }
- }
- }
|