Quellcode durchsuchen

wesmiler 抢表商城

APPLE vor 3 Jahren
Ursprung
Commit
7f378d57fe

+ 164 - 18
app/Helpers/common.php

@@ -591,24 +591,17 @@ if (!function_exists('format_mobile')) {
 if (!function_exists('get_random_code')) {
 
     /**
-     * 获取指定位数的随机码
-     * @param int $num 随机码长度
-     * @return string 返回字符串
-     * @author laravel开发员
-     * @date 2019/5/23
+     * 生成唯一字符串
+     * @param int $length
+     * @param string $prefix
+     * @param string $ext
+     * @return string
      */
-    function get_random_code($num = 12)
-    {
-        $codeSeeds = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-        $codeSeeds .= "abcdefghijklmnopqrstuvwxyz";
-        $codeSeeds .= "0123456789";
-        $len = strlen($codeSeeds);
-        $code = "";
-        for ($i = 0; $i < $num; $i++) {
-            $rand = rand(0, $len - 1);
-            $code .= $codeSeeds[$rand];
-        }
-        return $code;
+    function get_random_code($length=8, $prefix='', $ext=''){
+        $length = $length<9? 9 : $length;
+        $code = strtoupper(md5(uniqid(mt_rand(), true).$ext.microtime()));
+        $start = rand(1, strlen($code)-$length);
+        return $prefix.mb_substr($code, $start, $length);
     }
 }
 
@@ -1683,4 +1676,157 @@ if (!function_exists('get_images_preview')){
         unset($item);
         return $urls;
     }
-}
+}
+
+if (!function_exists('httpRequest')) {
+    /**
+     *
+     * 接口请求
+     * @author wesmiler
+     * @param $url 接口地址
+     * @param $data
+     * @param $type
+     * @param int $timeout
+     * @return mixed
+     */
+    function httpRequest($url, $data = '', $type = 'post', $cookie = '', $timeout = 60)
+    {
+        try {
+            set_time_limit($timeout);
+            $data = $data && is_array($data) ? http_build_query($data) : $data;
+            $url = strtolower($type) == 'get' ? $url . (strpos($url, '?') === false ? '?' : '&') . $data : $url;
+            $ch = curl_init($url);
+            if (!empty($cookie)) {
+                curl_setopt($ch, CURLOPT_COOKIE, $cookie);
+            }
+            if ($type == 'post') {
+                curl_setopt($ch, CURLOPT_POST, 1);
+                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+            }
+
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    //禁止 cURL 验证对等证书
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);    //是否检测服务器的域名与证书上的是否一致
+            curl_setopt($ch, CURLOPT_HEADER, 0);
+            curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+            curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
+            curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+            $ret = curl_exec($ch);
+            $ret = trim($ret);
+            curl_close($ch);
+            if (!preg_match("/^{/", $ret)) {
+                return ['code' => 'err', 'msg' => $ret];
+            }
+            $retArr = $ret ? json_decode($ret, true) : ['code' => 'err', 'msg' => 'unknow error'];
+            if(empty($retArr)){
+                $ret = iconv('gb2312','utf-8', $ret);
+                $retArr = json_decode($ret, true);
+            }
+
+        } catch (\Exception $exception) {
+            $retArr = ['code' => 'error', 'msg' => 'request error'];
+        }
+
+        return $retArr;
+    }
+}
+
+/**
+ *
+ * 接口请求
+ * @author wesmiler
+ * @param $url 接口地址
+ * @param $data
+ * @param $type
+ * @param int $timeout
+ * @return mixed
+ */
+function requestGetCookies($url, $data = '', $header = '', $timeout = 60)
+{
+    try {
+        set_time_limit($timeout);
+        $ch = curl_init($url);
+
+        if ($header) {
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+        }
+
+        if ($data) {
+            curl_setopt($ch, CURLOPT_POST, 1);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+        }
+
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    //禁止 cURL 验证对等证书
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);    //是否检测服务器的域名与证书上的是否一致
+        curl_setopt($ch, CURLOPT_HEADER, 1);
+        curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
+        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //do not output directly, use variable
+        curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //do a binary transfer
+        curl_setopt($ch, CURLOPT_FAILONERROR, 1);
+        curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
+        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+        $ret = curl_exec($ch);
+
+        curl_close($ch);
+        $cookie = '';
+
+        //file_put_contents("./logs/page_".date('YmdHis').".html",  $url."\n".$ret);
+        $preg_cookie = '/(Set-Cookie|set-cookie): (.*?);/m';
+        if ($ret && preg_match_all($preg_cookie, $ret, $cookies)) {
+            if (isset($cookies[2])) {
+                array_filter($cookies[2]);
+                $cookie = implode(';', $cookies[2]);
+            }
+        }
+
+
+        //file_put_contents("./logs/cookies_".date('YmdHis').".txt",  $cookie);
+
+    } catch (\Exception $exception) {
+        $cookie = '';
+    }
+
+    return $cookie;
+}
+
+/**
+ * HTTP请求
+ * @param $url 链接
+ * @param $data 提交数据
+ * @param string $type 请求类型:get post
+ * @param string $dataType 返回数据类型 array json
+ * @param int $timeout
+ * @return mixed
+ */
+function grabRequest($url, $header = [], $data = [], $type = 'get', $dataType = 'array', $cookie = '', $timeout = 60)
+{
+    $getData = $data && is_array($data) ? http_build_query($data) : '';
+    $url = strtolower($type) == 'get' ? $url . (strpos($url, '?') === false && $getData ? '?' : '') . $getData : $url;
+    $ch = curl_init($url);
+    if ($header) {
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
+    } else {
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+    }
+
+    if (!empty($cookie)) {
+        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
+    }
+
+    curl_setopt($ch, CURLOPT_POST, 1);
+    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
+    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查,0-规避ssl的证书检查
+    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
+    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
+    $ret = curl_exec($ch);
+    curl_close($ch);
+    if (strtolower($dataType) == 'array' && !is_array($ret)) {
+        $ret = json_decode($ret, true);
+    }
+    return $ret;
+}

+ 28 - 20
app/Http/Controllers/Api/v1/LoginController.php

@@ -19,19 +19,23 @@ class LoginController extends webApp
      * 用户登录
      * @return array
      */
-    public function login(MemberValidator  $validator)
+    public function login(MemberValidator $validator)
     {
-        $params = request()->all();
-        $params = $validator->check($params, 'login');
-        if(!is_array($params)){
-            return message($params, false);
-        }
+        try {
+            $params = request()->all();
+            $params = $validator->check($params, 'login');
+            if (!is_array($params)) {
+                return message($params, false);
+            }
 
-        if(!$result = MemberService::make()->login($params)){
-            return message(MemberService::make()->getError(), false);
-        }
+            if (!$result = MemberService::make()->login($params)) {
+                return message(MemberService::make()->getError(), false);
+            }
 
-        return message(2004, true, $result);
+            return message(2004, true, $result);
+        } catch (\Exception $exception) {
+            return message(2003, false);
+        }
     }
 
     /**
@@ -39,19 +43,23 @@ class LoginController extends webApp
      * @param MemberValidator $validator
      * @return array
      */
-    public function register(MemberValidator  $validator)
+    public function register(MemberValidator $validator)
     {
-        $params = request()->all();
-        $params = $validator->check($params, 'register');
-        if(!is_array($params)){
-            return message($params, false);
-        }
+        try {
+            $params = request()->all();
+            $params = $validator->check($params, 'register');
+            if (!is_array($params)) {
+                return message($params, false);
+            }
 
-        if(!MemberService::make()->register($params)){
-            return message(MemberService::make()->getError(), false);
-        }
+            if (!MemberService::make()->register($params)) {
+                return message(MemberService::make()->getError(), false);
+            }
 
-        return message(2008);
+            return message(2008);
+        } catch (\Exception $exception) {
+            return message(2007, false);
+        }
     }
 
 }

+ 123 - 2
app/Http/Controllers/Api/v1/TestController.php

@@ -3,6 +3,9 @@
 namespace App\Http\Controllers\Api\v1;
 
 use App\Http\Controllers\Api\webApp;
+use App\Services\RedisService;
+use Illuminate\Support\Facades\DB;
+use QL\QueryList;
 
 /**
  * 测试
@@ -12,8 +15,126 @@ use App\Http\Controllers\Api\webApp;
 class TestController extends webApp
 {
 
-    public function index(){
+    public function index()
+    {
         $key = md5('clearTrade');
-        return message(1002,true, $key);
+        return message(1002, true, $key);
+    }
+
+    public function betList1()
+    {
+        //第一步:获取cookie
+        $cookieFile = ROOT_PATH . '/public/cookie.tmp';
+        $url = 'http://86524391-jf.for9dong.com/login';
+        $data = array(
+            'type' => 2,
+            'account' => 'xxcc666',
+            'password' => 'AAbb1122',
+            'code' => '6497',
+            'facode' => '',
+        );
+        //curl初始化
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        //设置为post请求
+        curl_setopt($ch, CURLOPT_POST, true);
+        //设置附带返回header信息为空
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        //post数据
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+        //cookie保存文件位置
+        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
+        //设置数据返回作为变量储存,而不是直接输出
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        //执行请求
+        $ret = curl_exec($ch);
+        var_dump($ret);
+        //关闭连接
+        curl_close($ch);
+
+        //第二步:附带cookie请求需要登陆的页面
+        $url = 'https://86524391-jf.for9dong.com/agent/report/list?detail=true&begin=2023-02-28&end=2023-02-28&settle=true&lottery=PK10JSC';
+
+        //curl初始化
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        //设置为post请求
+        curl_setopt($ch, CURLOPT_POST, true);
+        //设置附带返回header信息为空
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        //设置cookie信息文件位置, 注意与第二步中的获取不同,这里是读取
+        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
+        //设置数据返回作为变量储存,而不是直接输出
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        //执行请求
+        $ret = curl_exec($ch);
+
+        var_dump($ret);
+        //关闭连接
+        curl_close($ch);
+    }
+
+    public function betList()
+    {
+        /**
+         *
+         * 东郲
+         * 213808.app
+         * 661182FF
+         * xxcc666
+         * AAbb1122
+         */
+
+        set_time_limit(0);
+        $cookie = 'ssid1=ac7aeb26742b7642d45a0605d4749266; random=549; token=f06742d5c5d6f66606d86bc28f279f12a3d831fa';
+        $url = 'https://86524391-jf.for9dong.com/agent/report/bets?username=bnm368&lottery=PK10JSC&begin=2023-02-28&end=2023-02-28&settle=true';
+        $header = ["Cookie: ssid1=a6d82ef49895683ce8789c1ef0141163; random=9338; token=e11c72348bc5f0b654957495154f6dbaff1307d7","User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","Host: 86524391-jf.for9dong.com","Connection:  keep-alive","Referer: https://86524391-jf.for9dong.com/agent/report/list?username=yyy1999&lottery=PK10JSC&detail=true&begin=2023-02-28&end=2023-02-28&settle=true"];
+
+        $page = request('page');
+//        $html = grabRequest($url.'&page='.$page, $header, '', 'get', 'text', '',10);
+//var_dump($html);
+//        return 0;
+        $pageNum = 2730;
+        $endPage = 50;
+        $datas = [];
+        $page = request('page');
+        $endPage = request('endPage');
+        for($i = $page; $i<=$endPage;){
+            $html = grabRequest($url.'&page='.$i, $header, '', 'get', 'text', '',10);
+            $queryList = QueryList::html($html)->rules([
+                'order_sn'=> ['td>a:eq(0)','text'],
+                'time'=> ['td:eq(1)','text'],
+                'gameName'=> ['td.period','html','-div'],
+                'period'=> ['td.period>div','text'],
+                'account'=> ['td:eq(3)','html','-div'],
+                'region'=> ['td:eq(3)>div','text'],
+                'code'=> ['td>span:eq(0)','text'],
+                'odds'=> ['.odds','text'],
+                'money'=> ['.money','text'],
+                'commission'=> ['.commission','text'],
+                'result'=> ['.dividend','text'],
+                'share'=> ['.share','text'],
+                'result1'=> ['td:eq(9)','text'],
+            ])->range('tr')->query()->getData();
+
+            $queryList = $queryList->all();
+            if($queryList){
+                foreach ($queryList as $item ){
+                    if($item['order_sn'] && !DB::table('test_logs')->where(['order_sn'=> $item['order_sn'],'page'=> $i])->value('id')){
+                        $item['page'] = $i;
+                        $item['money'] = floatval($item['money']);
+                        $item['code'] = str_replace(['『','』'],['[',']'], $item['code']);
+                        $datas[] = $item;
+                        //RedisService::set('order:'.$item['order_sn'], 11, 60000);
+                    }
+                }
+            }
+
+            $i++;
+        }
+
+        DB::table('test_logs')->insert($datas);
+
+        return message(1002, true, $datas);
     }
 }

+ 6 - 4
app/Services/BaseService.php

@@ -62,10 +62,12 @@ class BaseService
     public function checkExists($field, $value, $pk='id',$status=1)
     {
         $where = [$field=> $value,'mark'=>1];
-        if($status>0){
-            $where['status'] = $status;
-        }
-        return $this->model->where($where)->value($pk);
+        return $this->model->where($where)->where(function($query) use($status){
+            if($status){
+                $status = is_array($status)? $status : [$status];
+                $query->whereIn('status', $status);
+            }
+        })->value($pk);
     }
 
     /**

+ 2 - 1
app/Services/Common/AccountService.php

@@ -222,12 +222,13 @@ class AccountService extends BaseService
         $logData = [
             'user_id'=> $userId,
             'shop_id'=> $userInfo['login_shop_id'],
+            'source_uid'=> isset($params['source_uid'])?  intval($params['source_uid']) : 0,
             'type'=> 3,
             'coin_type'=> 2,
             'money'=> $money,
             'balance'=> $bonus,
             'create_time'=> time(),
-            'remark'=> '佣金调整',
+            'remark'=> isset($params['remark']) && $params['remark']? trim($params['remark']) : '佣金调整',
             'status'=> 1,
             'mark'=>1
         ];

+ 7 - 8
app/Services/Common/GoodsService.php

@@ -332,7 +332,7 @@ class GoodsService extends BaseService
             $datas[] = [
                 'user_id' => $goods['user_id'],
                 'shop_id' => $goods['shop_id'],
-                'goods_name' => $goods['goods_name'],
+                'goods_name' => 'HY'.$goods['code'] . '-' . $i,
                 'code' => $goods['code'] . '-' . $i,
                 'source_price' => $sourcePrice,
                 'sell_price' => $sellPrice,
@@ -359,12 +359,12 @@ class GoodsService extends BaseService
                 return false;
             }
 
-            if (!$this->model->where(['id' => $goods['id'], 'mark' => 1])->update(['status' => 2, 'mark' => 0, 'remark' => '已被拆分', 'update_time' => time()])) {
+            if (!$this->model->where(['id' => $goods['id'], 'mark' => 1])->update(['mark' => 0, 'remark' => '已被拆分', 'update_time' => time()])) {
                 DB::rollBack();
                 return false;
             }
 
-            if ($info && !TradeModel::where(['id' => $info['id'], 'mark' => 1])->update(['is_split' => 1, 'mark' => 0, 'remark' => '已被拆分', 'update_time' => time()])) {
+            if ($info && !TradeModel::where(['id' => $info['id'], 'mark' => 1])->update(['is_split' => 1,'is_sell'=>2, 'remark' => '已被拆分', 'update_time' => time()])) {
                 DB::rollBack();
                 return false;
             }
@@ -452,7 +452,7 @@ class GoodsService extends BaseService
             $datas[] = [
                 'user_id' => $goods['user_id'],
                 'shop_id' => $goods['shop_id'],
-                'goods_name' => $goods['goods_name'],
+                'goods_name' => 'HY'.$goods['code'] . '-' . $i,
                 'code' => $goods['code'] . '-' . $i,
                 'source_price' => $sourcePrice,
                 'sell_price' => $sellPrice,
@@ -480,13 +480,13 @@ class GoodsService extends BaseService
                 return false;
             }
 
-            if (!$this->model->where(['id' => $goods['id'], 'mark' => 1])->update(['status' => 2, 'mark' => 0, 'remark' => '已被手动拆分', 'update_time' => time()])) {
+            if (!$this->model->where(['id' => $goods['id'], 'mark' => 1])->update(['mark' => 0, 'remark' => '已被手动拆分', 'update_time' => time()])) {
                 DB::rollBack();
                 $this->error = 2070;
                 return false;
             }
 
-            if ($tradeInfo && !TradeModel::where(['id' => $tradeInfo['id'], 'mark' => 1])->update(['is_split' => 1, 'mark' => 0, 'remark' => '已被手动拆分', 'update_time' => time()])) {
+            if ($tradeInfo && !TradeModel::where(['id' => $tradeInfo['id'], 'mark' => 1])->update(['is_split' => 1, 'is_sell' => 2, 'remark' => '已被手动拆分', 'update_time' => time()])) {
                 DB::rollBack();
                 $this->error = 2070;
                 return false;
@@ -651,8 +651,7 @@ class GoodsService extends BaseService
 
         $result = parent::delete(); // TODO: Change the autogenerated stub
         $code = isset($result['success'])? $result['success'] : '';
-        var_dump($ids);
-        var_dump($result);
+
         if(!$code){
             DB::rollBack();
             return $result;

+ 15 - 11
app/Services/Common/MemberService.php

@@ -79,7 +79,7 @@ class MemberService extends BaseService
             $info['bonus'] = round($info['bonus'],0);
             $info['mobile_text'] = $info['mobile'];
             $info['mobile'] = $info['mobile']? format_mobile($info['mobile']):'';
-            $info['show_bonus'] = GoodsService::make()->checkNewGoods($info['id']);
+
 
             // 积分
             $scoreRate = isset($info['score_rate'])? $info['score_rate'] : 1;
@@ -107,6 +107,7 @@ class MemberService extends BaseService
                     'seconds'=> 0,
                 ];
                 $shopInfo['snap_time'] = $snapTime;
+                $shopInfo['cur_time'] = $curTime;
                 $shopInfo['snap_time_lock'] = max(0,$curTime - $startTime);
                 $shopInfo['start_time_num'] = $startTime;
                 $shopInfo['end_time_lock'] = max(0,$endTime - $startTime);
@@ -125,7 +126,7 @@ class MemberService extends BaseService
 
                 $info['shop_info'] = $shopInfo;
             }
-            $info['parent_info'] = [];
+            $info['parent_info'] = ['nickname'=>'无','code'=>'无'];
             if(isset($info['parent_id']) && $info['parent_id']){
                 $info['parent_info'] = $this->model->where(['id'=>$info['parent_id'],'mark'=>1])
                     ->select(['id','nickname','username','code'])
@@ -175,10 +176,10 @@ class MemberService extends BaseService
             $info['bonus_total'] = round($info['bonus_total'],0);
             $info['mobile'] = $info['mobile']? format_mobile($info['mobile']):'';
             // 今日是否有拍过商品(业绩有入账)
-            $info['show_bonus'] = strtotime($info['merits_time'])>=strtotime(date('Y-m-d'))? 1 : 0;
-            if($info['show_bonus']<=0){
-                $info['bonus_total']= max(0,$info['bonus_total']-$info['bonus']);
-            }
+            $tradeCount = TradeService::make()->getCountByDay($info['id']);
+            $showBonusLimitCount = ConfigService::make()->getConfigByCode('show_bonus_limit');
+            $showBonusLimitCount = $showBonusLimitCount>0? $showBonusLimitCount : 1;
+            $info['show_bonus'] = $tradeCount>=$showBonusLimitCount?1:0;
 
             $info['shop_info'] = [];
             if(isset($info['login_shop_id']) && $info['login_shop_id']) {
@@ -316,7 +317,7 @@ class MemberService extends BaseService
     public function register($params)
     {
         // 检测账号是否存在
-        if ($this->checkExists('mobile', $params['mobile'])) {
+        if ($this->checkExists('mobile', $params['mobile'],'id',[1,2])) {
             $this->error = '2005';
             return false;
         }
@@ -335,23 +336,26 @@ class MemberService extends BaseService
         $parentId = isset($inviteInfo['id'])? $inviteInfo['id'] : 0;
         $parents = isset($inviteInfo['parents'])? $inviteInfo['parents'] : '';
         $parents = $parents? rtrim($parents,',').",{$parentId}," : "{$parentId},";
+        $id = $this->model->max('id')+1;
 
         $data = [
-            'nickname' => $nickname? $nickname : '用户u'.get_random_code(6),
-            'username' => strtoupper('U'.get_random_code(7)),
+            'nickname' => $nickname? $nickname : get_random_code(6,'用户u'),
+            'username' => strtoupper(get_random_code(7,'U')),
             'password' => get_password($password),
             'safe_password' => get_password($safePassword),
+            'code'=> strtoupper(get_random_code(8,'Q', "{$id}")),
             'mobile' => $mobile,
             'parents' => $parents,
             'parent_id' => $parentId,
             'status' => 1,
+            'score' => 0,
             'mark' => 1,
             'merits_time' => date('Y-m-d H:i:s'),
             'create_time' => time(),
         ];
 
         if ($id = $this->model->edit($data)) {
-            $this->model->where(['id'=> $id])->update(['code'=> strtoupper('Q'.get_random_code(8))]);
+            //$this->model->where(['id'=> $id])->update(['code'=> strtoupper(get_random_code('Q',8, "{$id}"))]);
             $this->error = 2008;
             return true;
         }
@@ -984,7 +988,7 @@ class MemberService extends BaseService
             }
         }
 
-        return true;
+        return false;
     }
 
     /**

+ 118 - 19
app/Services/Common/TradeService.php

@@ -247,7 +247,7 @@ class TradeService extends BaseService
                     $query->where('a.pay_time', '>=', $time)->orWhere('a.create_time', '>=', $time);
                 }
             })
-            ->select(['a.*', 'b.nickname', 'b.code as user_code', 'b.mobile as mobile', 'c.name as shop_name', 'c.code as shop_code', 'g.goods_name', 'g.thumb'])
+            ->select(['a.*', 'b.nickname', 'b.code as user_code', 'b.mobile as mobile', 'c.name as shop_name', 'c.code as shop_code', 'g.goods_name','g.code', 'g.thumb'])
             ->orderBy('a.create_time', 'desc')
             ->orderBy('a.id', 'desc')
             ->paginate($pageSize > 0 ? $pageSize : 9999999);
@@ -390,6 +390,29 @@ class TradeService extends BaseService
     }
 
     /**
+     * 获取用户当天
+     * @param $userId
+     * @return array|mixed
+     */
+    public function getCountByDay($userId)
+    {
+        $cacheKey = "caches:trade:count:{$userId}";
+        $data = RedisService::get($cacheKey);
+        if($data){
+            return $data;
+        }
+
+        $data = $this->model->where(['user_id'=> $userId, 'status'=> 4,'is_sell'=> 2,'mark'=>1])
+            ->where('create_time','>=',strtotime(date('Y-m-d')))
+            ->count('id');
+        if($data){
+            RedisService::set($cacheKey, $data, rand(3,5));
+        }
+
+        return $data;
+    }
+
+    /**
      * 添加或编辑
      * @return array
      * @since 2020/11/11
@@ -752,6 +775,34 @@ class TradeService extends BaseService
     }
 
     /**
+     * 获取用户抢拍数量
+     * @param $userId
+     * @param string $time
+     * @return array|mixed
+     */
+    public function getTradeByDay($userId, $time=''){
+        $cacheKey = "caches:trade:snapNum:{$userId}";
+        $data = RedisService::get($cacheKey);
+        if($data){
+            return $data;
+        }
+
+        $data = $this->model->where(['user_id'=> $userId,'mark'=>1])
+            ->whereIn('status',[1,2,3,4])
+            ->where(function($query) use($time){
+                if($time){
+                    $query->where('create_time','>=', $time);
+                }
+            })
+            ->count('id');
+        if($data){
+            RedisService::set($cacheKey, $data, rand(3,5));
+        }
+
+        return $data;
+    }
+
+    /**
      * 抢购
      * @param $params
      * @param $userId
@@ -798,8 +849,15 @@ class TradeService extends BaseService
         $startTime = isset($shopInfo['start_time']) ? $shopInfo['start_time'] : '';
         $endTime = isset($shopInfo['end_time']) ? $shopInfo['end_time'] : '';
 
+        // 抢拍数量限制
+        $snapNum = ConfigService::make()->getConfigByCode('member_snap_num');
+        $snapNum = $snapNum>0? $snapNum : 5;
+
         // 店长自己抢
         if ($shopInfo['user_id'] == $userId) {
+            $shopownerSnapNum = ConfigService::make()->getConfigByCode('shopowner_snap_num');
+            $snapNum = $shopownerSnapNum>0? $shopownerSnapNum : 5;
+
             $snapTime = ConfigService::make()->getConfigByCode('snap_time');
             $snapTime = $snapTime ? $snapTime : 5;
             $curTime = strtotime(date('Y-m-d') . ' ' . $startTime) + 1;
@@ -820,6 +878,13 @@ class TradeService extends BaseService
             }
         }
 
+        // 抢拍数量验证
+        $curSnapNum = TradeService::make()->getTradeByDay($userId, strtotime(date('Y-m-d')));
+        if($curSnapNum>=$snapNum){
+            $this->error = lang(2096,['num'=> $snapNum]);
+            return false;
+        }
+
         // 验证收款账号
         if (!MemberBankService::make()->getBindInfo($userId)) {
             $this->error = 2037;
@@ -883,6 +948,8 @@ class TradeService extends BaseService
         DB::commit();
         $this->error = 2041;
         RedisService::keyDel($lockCacheKey);
+        // 抢拍成功,清除当天已抢拍数量统计
+        RedisService::keyDel("caches:trade:snapNum:{$userId}");
         return true;
     }
 
@@ -1190,25 +1257,22 @@ class TradeService extends BaseService
 
         // 满足涨价上架
         if ($price1 + $addPrice < $info['split_price']) {
-            // 平台服务费
-            $serviceRate = ConfigService::make()->getConfigByCode('service_fee_rate');
-            $serviceRate = $serviceRate ? $serviceRate : 8;
-            $serviceFee = round(($realPrice) * $serviceRate / 100, 0);
-            if (!$this->model->where(['id' => $id])->update(['status' => 4, 'service_fee' => $serviceFee, 'new_price' => $price1 + $addPrice, 'new_real_price' => $realPrice + $addPrice, 'is_sell' => 2, 'update_time' => time()])) {
+            // 更新价格
+            if (!$this->model->where(['id' => $id])->update(['status' => 4, 'new_price' => $price1 + $addPrice, 'new_real_price' => $realPrice + $addPrice, 'is_sell' => 2, 'update_time' => time()])) {
                 $this->error = 2056;
                 DB::rollBack();
                 return false;
             }
 
-            if (!GoodsModel::where(['id' => $info['goods_id']])->update(['last_sell_time' => time(), 'price' => $price1 + $addPrice, 'real_price' => $realPrice + $addPrice, 'is_trade' => 2, 'confirm_status' => 1, 'remark' => '上架审核 ' . date('Y-m-d H:i:s'), 'update_time' => time()])) {
+            // 更新其他交易状态
+            $this->model->where(['goods_id' => $info['goods_id'], 'status' => 4, 'mark' => 1])->whereNotIn('id', [$id])->update(['is_out' => 1, 'update_time' => time()]);
+
+            if (!GoodsModel::where(['id' => $info['goods_id']])->update(['user_id'=>$info['user_id'],'last_sell_time' => time(), 'price' => $price1 + $addPrice, 'real_price' => $realPrice + $addPrice, 'is_trade' => 2, 'confirm_status' => 1, 'remark' => '上架审核 ' . date('Y-m-d H:i:s'), 'update_time' => time()])) {
                 $this->error = 2056;
                 DB::rollBack();
                 return false;
             }
 
-            // 服务费统计
-            FinanceService::make()->settleBonus($serviceFee, 1);
-
             DB::commit();
 
             // 佣金结算
@@ -1220,7 +1284,21 @@ class TradeService extends BaseService
             return true;
         } // 停止拆分
         else if ($info['sell_price'] == $stopSplitPrice) {
-            if (!GoodsModel::where(['id' => $info['goods_id']])->update(['status' => 2, 'confirm_status' => 1, 'split_stop' => 1, 'update_time' => time()])) {
+            // 更新审核状态
+            if (!$this->model->where(['id' => $id])->update(['status' => 4, 'is_sell' => 2, 'update_time' => time()])) {
+                $this->error = 2056;
+                DB::rollBack();
+                return false;
+            }
+
+            // 更改商品归属人
+            if (!GoodsModel::where(['id' => $info['goods_id'], 'mark' => 1])->update(['user_id' => $info['user_id'], 'update_time' => time()])) {
+                $this->error = 2050;
+                DB::rollBack();
+                return false;
+            }
+
+            if (!GoodsModel::where(['id' => $info['goods_id']])->update(['status' => 1, 'confirm_status' => 2, 'split_stop' => 1, 'update_time' => time()])) {
                 $this->error = 2054;
                 DB::rollBack();
                 return false;
@@ -1236,6 +1314,23 @@ class TradeService extends BaseService
             return true;
         } // 满足拆分
         else if ($info['split_price']) {
+            // 更新审核状态
+            if (!$this->model->where(['id' => $id])->update(['status' => 4, 'is_sell' => 2, 'update_time' => time()])) {
+                $this->error = 2056;
+                DB::rollBack();
+                return false;
+            }
+
+            // 更新其他交易状态
+            $this->model->where(['goods_id' => $info['goods_id'], 'status' => 4, 'mark' => 1])->whereNotIn('id', [$id])->update(['is_out' => 1, 'update_time' => time()]);
+
+            // 更改商品归属人
+            if (!GoodsModel::where(['id' => $info['goods_id'], 'mark' => 1])->update(['user_id' => $info['user_id'], 'update_time' => time()])) {
+                $this->error = 2050;
+                DB::rollBack();
+                return false;
+            }
+
             if (!GoodsService::make()->split($info['goods_id'], $info)) {
                 $this->error = 2058;
                 DB::rollBack();
@@ -1267,14 +1362,7 @@ class TradeService extends BaseService
     {
         // 更新商品交易状态
         DB::beginTransaction();
-        $this->model->where(['goods_id' => $info['goods_id'], 'status' => 4, 'mark' => 1])->whereNotIn('id', [$tradeId])->update(['is_out' => 1, 'update_time' => time()]);
 
-        // 更改商品归属人
-        if (!GoodsModel::where(['id' => $info['goods_id'], 'mark' => 1])->update(['user_id' => $info['user_id'], 'update_time' => time()])) {
-            $this->error = 2050;
-            DB::rollBack();
-            return false;
-        }
 
         $memberInfo = MemberModel::where(['id' => $info['user_id'], 'mark' => 1])->first();
         $parentId = isset($memberInfo['parent_id']) ? $memberInfo['parent_id'] : 0;
@@ -1294,12 +1382,23 @@ class TradeService extends BaseService
         $profitRate = ConfigService::make()->getConfigByCode('profit_rate');
         $profitRate = $profitRate ? $profitRate : 0;
         $profit = $info['real_price'] * $profitRate / 100;
-        if (!$this->model->where(['id' => $tradeId, 'mark' => 1])->update(['bonus' => $bonus, 'profit' => $profit, 'update_time' => time()])) {
+
+        // 平台服务费
+        $serviceRate = ConfigService::make()->getConfigByCode('service_fee_rate');
+        $serviceRate = $serviceRate ? $serviceRate : 8;
+        $serviceFee = round($info['real_price'] * $serviceRate / 100, 0);
+
+        if (!$this->model->where(['id' => $tradeId, 'mark' => 1])->update(['bonus' => $bonus,'service_fee'=> $serviceFee, 'profit' => $profit, 'update_time' => time()])) {
             $this->error = 2051;
             DB::rollBack();
             return true;
         }
 
+        // 服务费统计
+        if($serviceFee>0){
+            FinanceService::make()->settleBonus($serviceFee, 1);
+        }
+
         // 收益记录
         $data = [
             'user_id' => $info['user_id'],