hrjy 2 years ago
parent
commit
8b2f33d0bf

+ 34 - 19
app/admin/controller/auction/AuctionProduct.php

@@ -3,6 +3,8 @@ namespace app\admin\controller\auction;
 
 
 use app\admin\controller\AuthController;
 use app\admin\controller\AuthController;
 use app\admin\controller\Union;
 use app\admin\controller\Union;
+use app\models\user\User;
+use app\models\user\UserBill;
 use crmeb\services\{ExpressService,
 use crmeb\services\{ExpressService,
     JsonService,
     JsonService,
     MiniProgramService,
     MiniProgramService,
@@ -199,25 +201,38 @@ class AuctionProduct extends AuthController
 
 
     }
     }
 
 
+    /**
+     * 回收
+     * @param $id
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function hs($id)
+    {
+        $userModel = new User();
+        $productModel = new \app\admin\model\auction\AuctionProduct();
+        $product = $productModel->find($id);
+        if ($product['is_show'] < 1) return Json::fail('当前状态不能回收');
+        if ($product['uid'] > 0){
+            $user = $userModel->where('uid', $product['uid'])->find();
+            if (!$product) return Json::fail('数据不存在');
+            $product['is_show'] = 0;
+            $product['uid'] = 0;
+
+            $money = $product['hanging_price'] - $product['price'];
+            $user['now_money'] += $money;
+            UserBill::income('商品回收', $user['uid'], 'now_money', 'system_add', $money, $user['spread_uid'], $user['now_money'], '商品回收');
+
+            $res = $user->save();
+            $product->save();
+            if ($res)  return Json::success('成功!');
+            return Json::fail('失败!');
+        }
+        return Json::fail('商品没有用户不能回收');
+    }
+
 
 
-//    public function edit($id)
-//    {
-//        if (!$id) Json::fail('数据不存在');
-//
-//
-//        $list = \app\admin\model\auction\Auction::get($id);
-//        if (!$list) Json::fail('数据不存在');
-//
-//        $f = array();
-//        $f[] = Form::input('id', 'ID', $list->getData('id'))->disabled(1);
-//        $f[] = Form::input('nickname', '名称', $list->getData('nickname'));
-//        $f[] = Form::uploadImageOne('image', '图片','/index.php/admin/widget.images/upload',$list->getData('image'));
-//        $f[] = Form::radio('is_promoter', '推广员',$list->getData('status'))->options([['value' => 1, 'label' => '启用'], ['value' => 0, 'label' => '禁用']]);
-//        $f[] = Form::dateTime('time', '推广员',$list->getData('add_time'));
-//
-//        $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('update', array('uid' => $id)), 5);
-//        $this->assign(compact('form'));
-//        return $this->fetch('public/form-builder');
-//    }
 
 
 }
 }

+ 7 - 13
app/admin/view/auction/auction_order/index.php

@@ -118,15 +118,11 @@
                         </button>
                         </button>
                         {{#  } else if(d.status == 1) { }}
                         {{#  } else if(d.status == 1) { }}
                         <button type="button" name="status" class="layui-btn-xs layui-btn-disabled" id="">
                         <button type="button" name="status" class="layui-btn-xs layui-btn-disabled" id="">
-                            待上传
+                            待支付
                         </button>
                         </button>
                         {{#  } else if(d.status == 2) { }}
                         {{#  } else if(d.status == 2) { }}
                         <button type="button" name="status" class="layui-btn layui-btn-xs layui-btn-danger" id="">
                         <button type="button" name="status" class="layui-btn layui-btn-xs layui-btn-danger" id="">
-                            待审核
-                        </button>
-                        {{#  } else if(d.status == 3) { }}
-                        <button type="button" name="status" class="layui-btn layui-btn-xs layui-btn-danger" id="">
-                            完成
+                            成功
                         </button>
                         </button>
                         {{#  } }}
                         {{#  } }}
                     </script>
                     </script>
@@ -140,9 +136,9 @@
                         {{#  } }}
                         {{#  } }}
                     </script>
                     </script>
                     <script type="text/html" id="act">
                     <script type="text/html" id="act">
-                        <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event='qd' id="">
-                            通过
-                        </button>
+<!--                        <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event='qd' id="">-->
+<!--                            通过-->
+<!--                        </button>-->
                         <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event='delete' id="">
                         <button type="button" class="layui-btn layui-btn-xs layui-btn-danger" lay-event='delete' id="">
                             删除
                             删除
                         </button>
                         </button>
@@ -165,7 +161,6 @@
             {type: 'checkbox'},
             {type: 'checkbox'},
             {field: 'id', title: 'ID', sort: true, event: 'id', width: '5%', templet: '#id'},
             {field: 'id', title: 'ID', sort: true, event: 'id', width: '5%', templet: '#id'},
             {field: 'image', title: '图片', templet: '#image',  align: 'center', width: '5%'},
             {field: 'image', title: '图片', templet: '#image',  align: 'center', width: '5%'},
-            {field: 'upload_image', title: '打款凭证', templet: '#upload_image',  align: 'center',width: '5%'},
             {field: 'order_id', title: '订单号', templet: '#order_id',  align: 'center'},
             {field: 'order_id', title: '订单号', templet: '#order_id',  align: 'center'},
             {field: 'account', title: '购买用户账号', templet: '#account',  align: 'center'},
             {field: 'account', title: '购买用户账号', templet: '#account',  align: 'center'},
             {field: 'nickname', title: '购买用户呢称', templet: '#nickname',  align: 'center'},
             {field: 'nickname', title: '购买用户呢称', templet: '#nickname',  align: 'center'},
@@ -259,9 +254,8 @@
                 statusList:[
                 statusList:[
                     {name: '全部', value: ''},
                     {name: '全部', value: ''},
                     {name: '过期', value: '0'},
                     {name: '过期', value: '0'},
-                    {name: '待上传', value: '1'},
-                    {name: '待审核', value: '2'},
-                    {name: '完成', value: '3'}
+                    {name: '待支付', value: '1'},
+                    {name: '完成', value: '2'}
                 ],
                 ],
                 where: {
                 where: {
                     data: '',
                     data: '',

+ 19 - 0
app/admin/view/auction/auction_product/index.php

@@ -78,6 +78,9 @@
                         <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='上架|下架'  {{ d.is_show  == 1 ? 'checked' : '' }}>
                         <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='上架|下架'  {{ d.is_show  == 1 ? 'checked' : '' }}>
                     </script>
                     </script>
                     <script type="text/html" id="act">
                     <script type="text/html" id="act">
+                        <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='hs'>
+                            回收
+                        </button>
                         <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='edit'>
                         <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" lay-event='edit'>
                             编辑
                             编辑
                         </button>
                         </button>
@@ -133,6 +136,22 @@
                     });
                     });
                 },code)
                 },code)
                 break;
                 break;
+            case 'hs':
+                var url=layList.U({c:'auction.auction_product',a:'hs',q:{id:data.id}});
+                var code = {title:"操作提示",text:"确定回收?",type:'info',confirm:'是的,回收'};
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            obj.del();
+                            location.reload();
+                        }else
+                            return Promise.reject(res.data.msg || '回收失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                },code)
+                break;
             case 'open_image':
             case 'open_image':
                 $eb.openImage(data.image);
                 $eb.openImage(data.image);
                 break;
                 break;

+ 95 - 0
app/api/controller/auction/AuctionController.php

@@ -0,0 +1,95 @@
+<?php
+
+namespace app\api\controller\auction;
+
+
+use app\models\auction\Auction;
+use app\models\auction\AuctionBooking;
+use app\models\auction\AuctionOrder;
+use app\models\auction\AuctionPay;
+use app\models\user\User;
+use app\models\user\UserBill;
+use app\Request;
+use Monolog\Handler\Curl\Util;
+use think\facade\Cache;
+use crmeb\services\{
+    CacheService,
+    ExpressService,
+    SystemConfigService
+};
+use crmeb\services\UtilService;
+use crmeb\repositories\OrderRepository;
+use think\facade\Db;
+use think\facade\Validate;
+
+
+class AuctionController
+{
+    /**
+     * 场馆列表
+     * @param Request $request
+     * @return mixed
+     */
+    public function list(Request $request)
+    {
+        $data = UtilService::getMore([
+            [['page', 'd'], 0],
+            [['limit', 'd'], 0],
+            ['advance'],
+        ], $request);
+        $auctionModel = new \app\models\auction\Auction();
+
+        return app('json')->successful($auctionModel->list($data, $request->uid()));
+
+    }
+
+    /**
+     * 预约场馆
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function subscribe(Request $request)
+    {
+
+        $data = UtilService::postMore([
+            ['id']
+        ]);
+        if (!$data['id']) return app('json')->fail('数据传入错误');
+        $auctionModel = new Auction();
+        $auction = $auctionModel->find($data['id']);
+        if (!$auction)return app('json')->fail('没有此数据');
+
+        if (strtotime($auction['radd_time']) < time() or (strtotime($auction['radd_time'])-1800) < time()) return app('json')->fail('预约时间已过');
+
+        if (AuctionBooking::where([['uid', '=', $request->uid()], ['auction_id' , '=', $auction['id']], ['frequency', '=', $auction['frequency']]])->find()){
+            return app('json')->fail('当前场馆已预约');
+        }
+        $userModel = new User();
+        $user = $userModel->find($request->uid());
+        if($auction['lowest'] > $user['now_money'] or $auction['minimum'] > $user['aid_val']) return app('json')->fail('未达到预约门槛');
+        if ($user['aid_val'] < $auction['advert']) return app('json')->fail('广告值不够');
+        $user['aid_val'] = $user['aid_val'] - $auction['advert'];// 扣除广告值
+        User::rollbackTrans();
+        $res = $user->save();
+
+        if ($res){
+            AuctionBooking::booking($user['uid'], $auction);
+            UserBill::expend('预约场馆', $user['uid'], 'aid_val','add_aid_val', $auction['advert'], 0, $user['aid_val'], '预约冻结广告值'); // 写入记录
+
+            User::commitTrans();
+            return app('json')->successful('预约成功');
+        }else{
+
+            User::rollbackTrans();
+            return app('json')->fail('预约失败');
+        }
+
+
+
+    }
+
+
+}

+ 151 - 0
app/api/controller/auction/AuctionProductController.php

@@ -0,0 +1,151 @@
+<?php
+
+namespace app\api\controller\auction;
+
+
+use app\admin\model\system\SystemConfig;
+use app\models\auction\Auction;
+use app\models\auction\AuctionBooking;
+use app\models\auction\AuctionOrder;
+use app\models\auction\AuctionProduct;
+use app\models\user\User;
+use app\models\user\UserBill;
+use app\Request;
+use Monolog\Handler\Curl\Util;
+use think\facade\Cache;
+use crmeb\services\{
+    CacheService,
+    ExpressService,
+    SystemConfigService
+};
+use crmeb\services\UtilService;
+use crmeb\repositories\OrderRepository;
+use think\facade\Db;
+
+
+class AuctionProductController
+{
+    /**
+     * 购买随机返回一张订单
+     * @param Request $request
+     * @return void
+     */
+    public function purchase(Request $request)
+    {
+        $data = UtilService::postMore([
+            ['id']
+        ]);
+        $auction = Auction::find($data['id']);
+        if (!$auction) return app('json')->fail('场次不存在');
+        if (AuctionOrder::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']], ['uid', '=', $request->uid()]])->count() >= 1) return app('json')->fail('当前场次已购买商品');
+
+        $orderCount = AuctionOrder::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']]])->count(); // 查找出当前场次已派单多少
+        $pd = AuctionBooking::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']]])->count(); // 当前预约人数
+        $pds = ceil($pd * ($auction['dispatch']/100));
+        if ($orderCount >= $pds) return app('json')->fail('商品已买完');
+
+
+
+        $show = AuctionProduct::random($data['id'], $request->uid());
+        if ($show == 'false')  return app('json')->fail('购买失败');
+        return app('json')->successful($show);
+    }
+
+
+
+
+    /**
+     * 用户商品
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function user_product(Request  $request)
+    {
+
+        $data = UtilService::getMore([
+            [['page', 'd'], 0],
+            [['limit', 'd'], 0],
+        ]);
+        return app('json')->successful(AuctionProduct::user_product( $data,$request->uid()));
+    }
+
+
+    /**
+     * 用户订单
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function user_auction_order(Request $request)
+    {
+
+        $data = UtilService::getMore([
+            [['type', 'd'], 0],
+            [['page', 'd'], 0],
+            [['limit', 'd'], 0],
+            ['order_id']
+        ]);
+
+        return app('json')->successful(AuctionOrder::userOrder($data,$request->uid()));
+    }
+
+
+    /**
+     * 卖家显示订单
+     * @param Request $request
+     * @return void
+     */
+    public function seller(Request $request)
+    {
+        $data = UtilService::getMore([
+            ['type', 0],
+            [['page', 'd'], 0],
+            [['limit', 'd'], 0],
+            ['order_id']
+        ]);
+
+        return app('json')->successful(AuctionOrder::seller_list($data,$request->uid()));
+    }
+
+    /**
+     * 支付订单
+     * @param Request $request
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function zfpay(Request $request)
+    {
+        $data = UtilService::postMore([
+            ['order_id']
+        ]);
+        $model = new User();
+        $order = AuctionOrder::where('order_id', $data['order_id'])->find();
+        if (!$order) return app('json')->fail('订单不存在');
+        if ($order['status'] == 0 or $order['status'] == 2) return app('json')->fail('订单状态不对');
+        $user = $model->where('uid', $request->uid())->find();
+        if ($user['now_money'] < $order['actual_price']) return app('json')->fail('余额不足');
+
+        try {
+            Db::startTrans();
+            AuctionOrder::pay($order, $request->uid());
+            Db::commit();
+            return app('json')->successful('支付成功');
+        } catch (\Exception $e) {
+            Db::rollback();
+            return app('json')->fail('支付失败');
+        }
+
+
+    }
+
+
+
+
+}

+ 28 - 0
app/common.php

@@ -594,3 +594,31 @@ if (!function_exists('do_request')) {
         return $result;
         return $result;
     }
     }
 }
 }
+
+if (!function_exists('pr')) {
+    function pr($var, $int = '')
+    {
+        $template = PHP_SAPI !== 'cli' ? '<pre>%s</pre>' : "\n%s\n";
+        printf($template, print_r($var, true));
+        if (!empty($int)) {
+            exit($int);
+        }
+
+    }
+}
+
+if (!function_exists('getNewOrderId')) {
+    /**
+     * 生成订单唯一id
+     * @param $uid 用户uid
+     * @return string
+     */
+    function getNewOrderId()
+    {
+        list($msec, $sec) = explode(' ', microtime());
+        $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
+        $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
+        if (\app\models\auction\AuctionOrder::where('order_id', $orderId)) $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
+        return $orderId;
+    }
+}

+ 2 - 0
app/http/middleware/AllowOriginMiddleware.php

@@ -4,6 +4,7 @@
 namespace app\http\middleware;
 namespace app\http\middleware;
 
 
 
 
+use app\models\auction\Auction;
 use app\Request;
 use app\Request;
 use crmeb\interfaces\MiddlewareInterface;
 use crmeb\interfaces\MiddlewareInterface;
 use think\facade\Config;
 use think\facade\Config;
@@ -53,6 +54,7 @@ class AllowOriginMiddleware implements MiddlewareInterface
             $response = $next($request)->header($header);
             $response = $next($request)->header($header);
         }
         }
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
         $request->filter(['htmlspecialchars', 'strip_tags', 'addslashes', 'trim']);
+        Auction::frequency(); // 更新场次
         return $response;
         return $response;
     }
     }
 }
 }

+ 85 - 0
app/models/auction/Auction.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace app\models\auction;
+
+use app\models\store\StoreProduct;
+use crmeb\services\SystemConfigService;
+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 = [];
+        $booking = AuctionBooking::where([['uid', '=', $uid], ['create_time', '>', strtotime(date('Y-m-d'), time())]])->field('auction_id')->select();
+        foreach ($booking as $v) {
+            $id[] = $v['auction_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['rend_time']);
+                $list[$k]['day'] = date('Y-m-d H:i:s', strtotime($v['rend_time']));
+                if (in_array($v['id'], $id)){
+                    $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();
+            }
+        }
+    }
+
+}

+ 50 - 0
app/models/auction/AuctionBooking.php

@@ -0,0 +1,50 @@
+<?php
+
+/**
+ *
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/02
+ */
+
+namespace app\models\auction;
+
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+/**
+ * 预约 Model
+ * Class WechatNews
+ * @package app\admin\model\wechat
+ */
+class AuctionBooking extends BaseModel
+{
+
+    use ModelTrait;
+
+    protected $pk = 'id';
+
+    protected $name = 'auction_booking';
+    protected $autoWriteTimestamp = true;
+
+
+    /**
+     * 添加预约记录
+     * @param $uid
+     * @param $auction
+     * @return void
+     */
+    public static function booKing($uid, $auction)
+    {
+        self::create([
+            'uid' => $uid,
+            'advert' => $auction['advert'],
+            'auction_id' => $auction['id'],
+            'frequency' => $auction['frequency'],
+            'create_time' => time()
+        ]);
+
+    }
+
+
+
+}

+ 306 - 0
app/models/auction/AuctionOrder.php

@@ -0,0 +1,306 @@
+<?php
+
+/**
+ *
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/02
+ */
+
+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;
+
+/**
+ * 预约 Model
+ * Class WechatNews
+ * @package app\admin\model\wechat
+ */
+class AuctionOrder extends BaseModel
+{
+
+    use ModelTrait;
+
+    protected $pk = 'id';
+
+    protected $name = 'auction_order';
+    protected $autoWriteTimestamp = true;
+
+
+    /**
+     * 用户订单
+     * @param $data
+     * @param $uid
+     * @return \think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    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]])->page($data['page'], $data['limit'])->select(); //待支付
+
+            }else if($data['type'] == 2){
+                $list = self::where([['uid', '=', $uid], ['status', '=', 2]])->page($data['page'], $data['limit'])->select(); //完成订单
+
+            }else{
+                $list = self::where([['uid', '=', $uid], ['status', '<', 1]])->page($data['page'], $data['limit'])->select(); //过期订单
+            }
+        }
+
+        $list = !empty($list)? $list->toArray(): [];
+        return $list;
+    }
+
+    /**
+     * 卖家订单
+     * @param $data
+     * @param $uid
+     * @return \think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    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'] == 1){
+                $list = self::alias('a')
+                    ->field('a.*,u.nickname,u.avatar,u.uid as user_id')
+                    ->leftJoin('user u', 'a.uid = u.uid')
+                    ->where([['a.collection_id', '=', $uid], ['a.status', '=', 1]])
+                    ->page($data['page'], $data['limit'])
+                    ->select(); //待支付订单
+
+            }else if($data['type'] == 2){
+                $list = self::alias('a')
+                    ->field('a.*,u.nickname,u.avatar,u.uid as user_id')
+                    ->leftJoin('user u', 'a.uid = u.uid')
+                    ->where([['a.collection_id', '=', $uid], ['a.status', '=', 2]])
+                    ->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')
+                    ->where([['a.collection_id', '=', $uid], ['a.status', '=', 0]])
+                    ->page($data['page'], $data['limit'])
+                    ->select(); //过期订单
+            }
+        }
+        $list = !empty($list)? $list->toArray(): [];
+
+        return $list;
+    }
+
+    /**
+     * 卖家操作
+     * @param $id  //商品所属人
+     * @param $price //卖出价格
+     * @param $product //商品详情
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function earn($id, $price,$product)
+    {
+        $userModel = new \app\models\user\User();
+        $productModel = new AuctionProduct();
+        $user = $userModel->find($id);
+
+        if ($user['spread_uid'] > 0){
+            $s_price = number_format(($price - $product['price']) * 0.1, 2); // 卖出价格减去购买价格的百分之十 为上级直推奖励
+            $spread = $userModel->find($user['spread_uid']);
+            $spread['integral'] = $spread['integral'] + $s_price; //积分增加
+            $spread->save();
+            \app\models\user\UserBill::create([
+                'uid' => $spread['uid'],
+                'link_id' => $id,
+                'pm' => 1,
+                'title' => '积分增加',
+                'category' => 'integral',
+                'type' => 'gain',
+                'mark' => '卖出商品直推'.$s_price.'积分',
+                'add_time' => time(),
+                'number' => $s_price,
+                'balance' => $spread['integral']
+
+            ]);
+        }
+        $user['anticipate'] = $user['anticipate']-$price*($product['deduct']/100); // 扣除当前卖出价格百分比的预约卷
+        $user->save();
+        UserBill::expend('预约卷扣除', $user['uid'], 'anticipate','reduce_anticipate', $price*($product['deduct']/100), 0, $user['anticipate'] ,'卖出扣除预约卷');
+        $productModel->where('id', $product['id'])->save(['price' => $price, 'hanging_price' => ($price+$price*($product['rise']/100))]); //修改当前画价
+
+    }
+
+    /**
+     * 购买成功退预约卷
+     * @param $id
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function return($id)
+    {
+        $data = self::find($id);
+        $userModel = new User();
+        $productModel = new AuctionProduct();
+        $auctionModel = new Auction();
+        $bookingModel = new AuctionBooking();
+
+
+        $user = $userModel->find($data['uid']);
+        if ($user['is_new'] == 1){
+
+            if ($user['spread_uid']) {
+                $spread = $userModel->where('uid', $user['spread_uid'])->find();
+                $spread['green_time'] = strtotime(date('Y-m-d', strtotime('+1 day'))); // 开启明天的绿色通道
+            }
+            $orderCount = AuctionOrder::where([['uid', '=',  $user['uid']], ['status','=', 3]])->count();
+            if ($orderCount >= 5){
+                $user['is_new'] = 0;
+            }
+
+
+        }
+        $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'])->whereBetweenTime('create_time', date('Y-m-d H:i:s', strtotime(date('Y-m-d'))), date('Y-m-d H:i:s', strtotime('+1 day')))->find();
+        if ($booking['status'] > 0){
+            $booking['status'] = 0;
+            $booking->save();
+            $user['anticipate'] = $user['anticipate'] + $auction['anticipate'];// 退还预约卷
+            $user->save();
+
+
+            \app\models\user\UserBill::create([
+                'uid' => $user['uid'],
+                'pm' => 1,
+                'title' => '预约卷退还',
+                'category' => 'anticipate',
+                'type' => 'add_anticipate',
+                'mark' => '退还预约场馆'.number_format($auction['anticipate'],2).'预约卷',
+                'add_time' => time(),
+                'number' => number_format($auction['anticipate'],2),
+                'balance' => $user['anticipate']
+            ]);
+        }
+    }
+
+    /**
+     * 订单过期
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function deduction()
+    {
+        $hour = strtotime(date('Y-m-d H:i:s', strtotime('-1 hour'))); // 一小时以前
+
+        $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){
+                    $user = \app\models\user\User::where('uid', $v['collection_id'])->find();
+                    $user['anticipate'] = $user['anticipate'] + $auction['anticipate']; // 增加预约卷
+                    UserBill::income('增加预约卷', $v['collection_id'], 'anticipate', 'add_anticipate',  $auction['anticipate'], $v['uid'], $user['anticipate'], '卖出订单未上传支付凭证,增加'.$auction['anticipate'].'预约卷');
+
+                    $user->save();
+                    AuctionBooking::where('id', $booking['id'])->update(['status' => 2]); // 修改预约订单状态 为扣除
+                }
+                AuctionOrder::where('create_time', '<', $hour)->where('status', '=', 1)->update(['status' => 0]); // 修改为已过期订单
+            }
+
+        }
+    }
+
+    /**
+     * 退回预约卷
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function th()
+    {
+        $auction = Auction::where('rend_time', '<', 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){
+                        $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'], '预约卷退回');
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * 支付订单
+     * @param $order
+     * @param $uid
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function pay($order, $uid)
+    {
+        $user = User::where('uid', $uid)->find();
+
+        $bk = AuctionBooking::where([['uid', '=', $uid], ['auction_id', '=', $order['auction_id']], ['frequency', '=', $order['frequency']]])->find();
+        $bk['status'] = 0;
+        $user['now_money'] -= $order['actual_price'];
+        $user['aid_val'] += $bk['advert'];
+
+        AuctionProduct::where('id', $order['product_id'])->update(['uid' => $uid]); // 修改商品拥有人
+        $user->save();
+        $bk->save();
+
+        AuctionOrder::where('id', $order['id'])->update(['status' => 2]); // 修改订单状态
+        UserBill::expend('购买商品支付', $uid, 'now_money', 'sub_money', $order['actual_price'], $user['spread_uid'], $user['now_money'], '购买商品支付订单');
+        UserBill::income('广告值退回', $uid, 'aid_val', 'add_aid_val', $bk['advert'], $user['spread_uid'], $user['aid_val'], '购买商品成功退回广告值');
+
+
+    }
+
+
+
+
+}

+ 125 - 0
app/models/auction/AuctionProduct.php

@@ -0,0 +1,125 @@
+<?php
+
+/**
+ *
+ * @author: xaboy<365615158@qq.com>
+ * @day: 2017/11/02
+ */
+
+namespace app\models\auction;
+
+use app\admin\model\system\SystemConfig;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+use http\Env\Request;
+use think\facade\Db;
+
+/**
+ * 竞拍上坪 Model
+ * Class WechatNews
+ * @package app\admin\model\wechat
+ */
+class AuctionProduct extends BaseModel
+{
+
+    use ModelTrait;
+
+    protected $pk = 'id';
+
+    protected $name = 'auction_product';
+    protected $autoWriteTimestamp = true;
+
+    /**
+     * 用户商品
+     * @param $data
+     * @param $uid
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function user_product($data, $uid){
+        $model = self::where('uid', $uid)->order('sort DESC,id DESC');
+        $model->page($data['page'], $data['limit']);
+
+        $list = $model->select()->toArray();
+        return $list;
+    }
+
+    public static function random($id, $uid)
+    {
+        $auction = Auction::find($id);
+        AuctionOrder::startTrans();
+        $order = AuctionOrder::where([['auction_id', '=', $id], ['frequency', '=', $auction['frequency']]])->column('product_id');
+        $product = self::where('auction_id', $auction['id'])->where('id', 'notIn', $order)->orderRaw('rand()')->limit(1)->find(); // 随机出来一个商品
+        if (empty($product)){
+            $config = SystemConfig::where('config_tab_id', 24)->select();
+            $data = [
+                'auction_id' => $auction['id']
+            ];
+            foreach ($config as $v)
+            {
+                if ($v['menu_name'] == 'product_name') $data['name'] = json_decode($v['value']);
+                if ($v['menu_name'] == 'product_image') $data['image'] = json_decode($v['value']);
+                if ($v['menu_name'] == 'product_slider_image') $data['slider_image'] = $v['value'];
+                if ($v['menu_name'] == 'product_price') $data['price'] = json_decode($v['value']);
+                if ($v['menu_name'] == 'product_hanging_price') $data['hanging_price'] = json_decode($v['value']);
+            }
+            $productSave = AuctionProduct::insertGetId($data);// 如果商品卖完,没达到预约量自动创建商品
+            $product = self::find($productSave);
+            // 创建订单
+            $orderData = [
+                'uid' => $uid,
+                'collection_id' => $product['uid'],
+                'order_id' => getNewOrderId(),
+                'auction_id' => $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' => $auction['frequency']
+            ];
+            $res = AuctionOrder::create($orderData);
+            if ($res) {
+
+                AuctionOrder::comimt();
+                return $orderData;
+            }else{
+
+                AuctionOrder::rollbackTrans();
+                return 'false';
+            }
+        }else{
+            // 创建订单
+            $orderData = [
+                'uid' => $uid,
+                'collection_id' => $product['uid'],
+                'order_id' => getNewOrderId(),
+                'auction_id' => $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' => $auction['frequency']
+            ];
+            $res = AuctionOrder::create($orderData);
+            if ($res) {
+
+                AuctionOrder::commitTrans();
+                return $orderData;
+            }else{
+
+                AuctionOrder::rollbackTrans();
+                return 'false';
+            }
+        }
+
+    }
+
+
+
+}

+ 12 - 0
route/api/route.php

@@ -161,6 +161,18 @@ Route::group(function () {
     Route::get('user/level/task/:id', 'user.UserLevelController/task')->name('userLevelTask');//获取等级任务
     Route::get('user/level/task/:id', 'user.UserLevelController/task')->name('userLevelTask');//获取等级任务
     //首页获取未支付订单
     //首页获取未支付订单
     Route::get('order/nopay', 'order.StoreOrderController/get_noPay')->name('getNoPay');//获取未支付订单
     Route::get('order/nopay', 'order.StoreOrderController/get_noPay')->name('getNoPay');//获取未支付订单
+
+    Route::get('auction', 'auction.AuctionController/list')->name('auction');//场次列表
+    Route::post('subscribe', 'auction.AuctionController/subscribe')->name('subscribe');//预约
+    Route::get('purchase', 'auction.AuctionProductController/purchase')->name('purchase');//随机商品
+
+    Route::get('user_auction_order', 'auction.AuctionProductController/user_auction_order')->name('user_auction_order');//用户订单
+    Route::get('seller', 'auction.AuctionProductController/seller')->name('seller');//卖家订单
+    Route::get('user_product', 'auction.AuctionProductController/user_product')->name('user_product');//用户商品
+    Route::post('zfpay', 'auction.AuctionProductController/zfpay')->name('zfpay');//支付订单
+
+
+
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 //未授权接口
 //未授权接口
 Route::group(function () {
 Route::group(function () {