123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- namespace app\models\auction;
- use app\admin\model\user\User;
- use app\admin\model\user\UserBill;
- use crmeb\services\product\Product;
- 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')
- ->leftJoin('user u', 'a.collection_id = u.uid')
- ->where('a.order_id', $data['order_id'])->find();
- }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 = AuctionProduct::alias('a')
- ->field('a.*, au.name as au_name')
- ->leftJoin('auction au', 'au.id = a.auction_id')
- ->order('a.id DESC')
- ->where('a.uid', $uid)
- ->where('a.is_show', 0)
- ->select();
- }else{
- $list = self::where([['uid', '=', $uid], ['status', '<', 1]])->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();
- }else{
- if ($data['type'] == 3){
- $list = AuctionProduct::alias('a')
- ->field('a.*, au.name as au_name')
- ->leftJoin('auction au', 'au.id = a.auction_id')
- ->order('a.id DESC')
- ->where('a.uid', $uid)
- ->where('a.is_show', 1)
- ->select();
- }else{
- if ($data['type'] == 1){
- $status = 1;
- }elseif ($data['type'] == 2){
- $status = 2;
- }else{
- $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('a.id DESC')
- ->where([['a.collection_id', '=', $uid], ['a.status', '=', $status]])
- ->page($data['page'], $data['limit'])
- ->select();
- }
- }
- $list = !empty($list)? $list->toArray(): [];
- return $list;
- }
-
- public static function deduction()
- {
- $hour = strtotime(date('Y-m-d H:i:s', strtotime('-30 minute')));
- $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();
- $booking = AuctionBooking::where([['uid', '=', $v['uid']], ['status', '=', 1], ['auction_id', '=', $auction['id']]])->where('status', '=', 1)->find();
- if ($booking){
- AuctionBooking::where('id', $booking['id'])->update(['status' => 2]);
- }
- AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->update(['status' => 0]);
- }
- }
- }
-
- public static function th()
- {
- $auction = Auction::select();
- if ($auction){
- foreach ($auction as $k => $v){
- if (strtotime($v['rend_time'])+1800 < time()){
-
- $booking = AuctionBooking::where([['auction_id', '=', $v['id']], ['status','=' , 1], ['frequency', '=', $v['frequency']]])->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){
- $date = date("Y-m-d");
- $firstday = date('Y-m-01 00:00:00', strtotime($date));
- $lastday = date('Y-m-d 23:59:59', strtotime("$firstday +1 month -1 day"));
- $userBok = AuctionBooking::where('uid', '=',$value['uid'])->where('th', '=', 1)->whereBetweenTime('create_time', $firstday, $lastday)->count();
- if ($userBok >= 3){
- $userBok++;
- if ($userBok == 4) $bf = 0.1;
- if ($userBok == 5) $bf = 0.2;
- if ($userBok >= 6) $bf = 0.5;
- }else{
- $bf = 0;
- }
- $find = AuctionBooking::find($value['id']);
- $find['status'] = 0;
- $find['th'] = 1;
- $find['deduct_advert'] = $value['advert']*$bf;
- $user = User::where('uid', $value['uid'])->find();
- $user['aid_val'] += ($value['advert']-$find['deduct_advert']);
- $user->save();
- $find->save();
- UserBill::income('未购买解冻但扣除'. $find['deduct_advert'].'广告值',$user['uid'], 'aid_val', 'add_aid_val',$value['advert'] - ($value['advert'] * $bf), 0, $user['aid_val'], '未购买解冻但扣除'. $find['deduct_advert'].'广告值');
- }
- }
- }
- }
- }
- }
- }
-
- public static function pay($order, $uid)
- {
- $user = User::where('uid', $uid)->find();
- $user['now_money'] -= $order['actual_price'];
- AuctionProduct::where('id', $order['product_id'])->update(['uid' => $uid, 'is_show' => 0]);
- $user->save();
- if ($order['collection_id'] > 0){
- self::m_user($order['collection_id'], $order['actual_price']);
- }
- AuctionOrder::where('id', $order['id'])->update(['status' => 2]);
- UserBill::expend('购买商品支付', $uid, 'now_money', 'sub_money', $order['actual_price'], $user['spread_uid'], $user['now_money'], '购买商品支付订单');
- }
-
- public static function m_user($uid, $price)
- {
- $user = User::where('uid', $uid)->find();
- $user['now_money'] += $price;
- $user->save();
- UserBill::income('卖出商品', $uid, 'now_money', 'add_money', $price, $user['spread_uid'], $user['now_money'], '商品卖出');
- }
- }
|