浏览代码

wes 多宝福袋

wesmiler 3 年之前
父节点
当前提交
f9f3d44c1e

+ 1 - 1
app/admin/controller/Ajax.php

@@ -99,7 +99,7 @@ class Ajax extends AdminController
         }
 
         if ($upload['save'] == true) {
-            $this->success($upload['msg'], ['url' => $upload['url']]);
+            $this->success($upload['msg'], ['url' => $upload['url'],'path'=> getUploadPath($upload['url'])]);
         } else {
             $this->error($upload['msg']);
         }

+ 14 - 3
app/admin/logic/ShopGoodsLogic.php

@@ -58,9 +58,10 @@ class ShopGoodsLogic
             ->select()->toArray();
 
         foreach ($list as $k => &$v) {
-//            $v['cate'] = ShopCategoryLogic::getCateById($v['category']);
             $v['id'] = $v['goods_id'];
-//                $v['supplier'] = Db::name('shop_supplier')->where(['id'=>$v['supplier']])->value('name');
+            $v['box_pic'] = isset($v['box_pic'])? getPreviewUrl($v['box_pic']):'';
+            $v['goods_img'] = $v['goods_img']? getPreviewUrl($v['goods_img']):'';
+
             $v['goods_type'] = ShopGoodsTypeLogic::getNameByCache($v['goods_type']);
         }
         return [$count, $list];
@@ -78,7 +79,17 @@ class ShopGoodsLogic
         if ($data['goods_img_banner']) {
             $data['goods_img_banner'] = implode('|', json_decode($data['goods_img_banner'], true));
         }
-        $data['goods_remark'] = htmlspecialchars_decode($data['goods_remark']);
+        $data['goods_img'] = $data['goods_img']? getPreviewUrl($data['goods_img']):'';
+        $data['box_pic'] = $data['box_pic']? getPreviewUrl($data['box_pic']):'';
+        $banners = $data['goods_img_banner']? json_decode($data['goods_img_banner'], true): [];
+        if($banners){
+            foreach ($banners as &$v){
+                $v = getPreviewUrl($v);
+            }
+        }
+
+        $data['goods_img_banner'] = $banners?implode('|',$banners):'';
+        $data['goods_remark'] = getContent(htmlspecialchars_decode($data['goods_remark']));
         $specRelation         = ShopGoodsSpecRelation::getArrListByGoodsId($id);
         $specAttrId           = ShopGoodsSpecType::getPidById($specRelation[0]['spec_id']);
         if ($data['is_exist_many_spec'] == 0) {

+ 0 - 1
app/admin/logic/ShopOrderLogic.php

@@ -106,7 +106,6 @@ class ShopOrderLogic
             } else {
                 $list[$k]['cost_price'] = 0;
             }
-
             if ($v['status'] == 5 || $v['status'] == 6) {
                 // 新的地址
                 $ygOrderInfo              = Db::name('yg_order')->where('order_sn', str_replace('编号:', '', $v['order_sn']))->find();

+ 3 - 0
app/admin/logic/SystemAdminLogic.php

@@ -26,6 +26,9 @@ class SystemAdminLogic
         $list = (new SystemAdmin())
             ->withoutField('password')
             ->where($where)
+            ->withAttr('head_img',function ($value){
+                return getPreviewUrl($value);
+            })
             ->page($page, $limit)
             ->order($sort)
             ->select();

+ 0 - 5
app/api/controller/h5/User.php

@@ -73,7 +73,6 @@ class User
         !$id && abort(403, '页面异常');
         try {
             $info = Db::name('system_faq')->where('id', $id)->where('status', 1)->find();
-//            $info['content'] = imageSrcReplace($info['content']);
             View::assign('info', $info);
         } catch (\Exception $e) {
             abort(403, '页面异常');
@@ -123,7 +122,6 @@ class User
 
                 $userserivce->userRegister($param);
                 return api_succ_return('注册成功');
-//                return api_succ_return(['msg'=>'注册成功','code'=>0]);
             } catch (ValidateException $e) {
                 return api_error_return($e->getMessage());
             } catch (\Exception $e) {
@@ -184,8 +182,6 @@ class User
      * @return string
      */
     public function newhandurl(Request $request){
-
-
         $m_article = new SystemArticleModel();
         $row = $m_article->where(['type' => 5])->findOrEmpty();
         empty($row) && abort(403, '页面异常');
@@ -201,7 +197,6 @@ class User
      */
     public function newguideurl(Request $request){
 
-//        $id = $request->param('id/d', '');
         $m_article = new SystemArticleModel();
         $row = $m_article->where(['type' => 6])->findOrEmpty();
         empty($row) && abort(403, '页面异常');

+ 1 - 3
app/api/controller/v1/Box.php

@@ -83,9 +83,7 @@ class Box
      */
     public function boxRandGoodsList()
     {
-
-        $list = Db::name('shop_goods')->where('on_sale', 1)->limit(12)->orderRaw("rand() , goods_id DESC")->field('goods_id,box_pic,goods_sn')->select()->toArray();
-        return api_succ_return(['msg' => '成功', 'data' => $list]);
+        return api_succ_return(['msg' => '成功', 'data' => ShopGoodsService::make()->getRandomGoods()]);
     }
 
     /**

+ 2 - 1
app/api/controller/v1/Fragment.php

@@ -329,6 +329,7 @@ class Fragment
         if(!in_array($extension, array("jpeg","jpg","png"))){
             return api_error_return('图片格式错误');
         }
+
         if (!in_array($type, ['avatar', 'message'])){
             return api_error_return('参数错误');
         }
@@ -373,7 +374,7 @@ class Fragment
         $iosupdateurl = env('app.API_WEB_URL').'/api/downapp';
         $isandroid_force = 1;
         $isios_force = 1;
-        if ($app_sources == 'ios'){
+        if ($app_sources == 'ios' || $app_sources == 'macos'){
             if ($curIosVersion > $app_version){
                 return api_succ_return(['msg'=>'成功', 'data'=>['has_update'=>1, 'cur_version'=>$curios, 'update_msg'=>$new_udpate_ios, 'update_url'=>$iosupdateurl, 'is_force'=>$isios_force, 'type'=>env('APP.DOWN_ANDROID_TYPE')]]);
             }else{

+ 1 - 1
app/api/controller/v1/Shop.php

@@ -24,7 +24,7 @@ class Shop
     {
         try {
             $pageSize = $request->post('limit', 10);
-            $list = ShopGoodsService::make()->getList($request->all, $pageSize);
+            $list = ShopGoodsService::make()->getList($request->all(), $pageSize);
             return api_succ_return(['msg'=>'成功', 'data'=> isset($list['data'])? $list['data'] : []]);
         }catch(Exception $e){
             return api_error_return('获取失败:'.$e->getMessage());

+ 74 - 154
app/api/controller/v1/Test.php

@@ -13,6 +13,7 @@ use app\common\model\BoxHandleModel;
 use app\common\model\CouponAreaModel;
 use app\common\model\CouponPlanLogModel;
 use app\common\model\CouponPlanModel;
+use app\common\model\GreenScoreLogModel;
 use app\common\model\MachineListModel;
 use app\common\model\MachineModel;
 use app\common\model\ShopGoodsModel;
@@ -48,170 +49,89 @@ class Test
 {
     public function test(Request $request)
     {
-        $list = [
-            5351304 => 503.5,
-            5352276 => 266,
-            5350677 => 285,
-            5352212 => 380,
-            5352211 => 1045,
-            5352210 => 760,
-            5352209 => 380,
-            5352208 => 760,
-            5350403 => 114,
-            5349123 => 285,
-            5349372 => 285,
-            5346924 => 285,
-            5352433 => 760,
-            5349713 => 95,
-            5348017 => 199.5,
-            5351411 => 1463,
-            5352535 => 665,
-            5346982 => 769.5,
-            5345774 => 313.5,
-            5352523 => 665,
-            5346478 => 1187.5,
-            5349879 => 475,
-            5352233 => 760,
-            5348700 => 2584,
-            5344662 => 969,
-            5345278 => 209,
-            5351904 => 551,
-            5345493 => 275.5,
-            5349688 => 1748,
-            5351924 => 380,
-            5348026 => 332.5,
-            5348962 => 4750,
-            5346159 => 693.5,
-            5351619 => 1045,
-            5351807 => 2831,
-            5350426 => 95,
-            5344610 => 608,
-            5344515 => 1197,
-            5350443 => 361,
-            5346094 => 950,
-            5350358 => 1187.5,
-            5347725 => 361,
-            5352458 => 1045,
-            5351189 => 361,
-            5348630 => 522.5,
-            5349709 => 1748,
-            5351373 => 684,
-            5345879 => 950,
-            5350359 => 370.5,
-            5351923 => 1045,
-            5345919 => 579.5,
-            5344810 => 237.5,
-            5352455 => 674.5,
-            5348947 => 133,
-            5348622 => 95,
-            5349735 => 1653,
-            5351621 => 380,
-            5349987 => 95,
-            5350010 => 380,
-            5347898 => 114,
-            5344563 => 893,
-            5344861 => 1881,
-            5351491 => 855];
-
-        $ids = array_keys($list);
-        echo "共要处理记录:".count($list).'个,'.count($ids).'个ID<br>';
-        $users = UserModel::whereIn('id', $ids)->field('id,mobile,money,score')->select();
-        echo "实际用户记录:".count($users).'个<br>';
-        $moneyLogs = [];
-        $scoreLogs = [];
-        $noCatchUsers = [];
         Db::startTrans();
-        foreach($list as $key => $catchMoney){
+        $lists = UserModel::field('id,money,score,profit_money,green_score')->select();
+        $logs = [];
+        foreach($lists as $item){
+            $id = isset($item['id'])? $item['id'] : 0;
+            $score = isset($item['score'])? $item['score'] : 0;
+            $money = isset($item['money'])? $item['money'] : 0;
+            $profit = isset($item['profit_money'])? $item['profit_money'] : 0;
+            $greenScore = UserModel::where('id', $id)->value('green_score');
+            $newGreenScore = $greenScore;
+            if($score>0){
+                echo "用户{$id} {$score}  积分转入<br>";
+                $logs[] = [
+                    'uid'=> $id,
+                    'type'=> 1,
+                    'score'=> $score,
+                    'create_at'=> date('Y-m-d H:i:s'),
+                    'from_id'=> 0,
+                    'uid2'=> 0,
+                    'state'=> 1,
+                    'before_score'=> $greenScore,
+                    'after_score'=> $newGreenScore+$score,
+                    'remark'=> '积分转入'
+                ];
+                $newGreenScore += $score;
+            }
 
-            $userInfo = UserModel::where('id', $key)->field('id,mobile,money,score')->find();
-            $userId = isset($userInfo['id'])? $userInfo['id'] : 0;
-            $money = isset($userInfo['money'])? $userInfo['money'] : 0;
-            $score = isset($userInfo['score'])? $userInfo['score'] : 0;
-            $mobile = isset($userInfo['mobile'])? $userInfo['mobile'] : '';
-            if($userId && $catchMoney>0){
-                if($money>=$catchMoney){
-                    echo "【扣除余额】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户余额[{$money}]-积分[{$score}],扣除后余额 ".max(0,$money-$catchMoney).'<br>';
-                    $moneyLogs[] = [
-                        'uid'=> $userId,
-                        'money'=> $catchMoney,
-                        'type'=> 17,
-                        'create_at'=> date('Y-m-d H:i:s'),
-                        'state'=> 2,
-                        'from_id'=>0,
-                        'before_money'=> $money,
-                        'after_money'=> max(0,$money-$catchMoney),
-                        'remark'=> '提现打款重复扣除',
-                    ];
+            if($money>0){
+                echo "用户{$id} {$money}  余额转入<br>";
+                $logs[] = [
+                    'uid'=> $id,
+                    'type'=> 3,
+                    'score'=> $money,
+                    'create_at'=> date('Y-m-d H:i:s'),
+                    'from_id'=> 0,
+                    'uid2'=> 0,
+                    'state'=> 1,
+                    'before_score'=> $newGreenScore,
+                    'after_score'=> $newGreenScore+$money,
+                    'remark'=> '余额转入'
+                ];
+                $newGreenScore += $money;
+            }
 
-                    // 扣除
-                    /*if(!UserModel::where('id', $userId)->dec('money', $catchMoney)->update()){
-                        DB::rollback();
-                        return 'fail';
-                    }*/
-                }elseif($score>=$catchMoney){
-                    echo "【扣除积分】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户余额[{$money}]-积分[{$score}],扣除后余额 ".($money-$catchMoney).'<br>';
-                    $scoreLogs[] = [
-                        'uid'=> $userId,
-                        'score'=> $catchMoney,
-                        'type'=> 13,
-                        'create_at'=> date('Y-m-d H:i:s'),
-                        'state'=> 2,
-                        'from_id'=>0,
-                        'before_score'=> $score,
-                        'after_score'=> max(0,$score-$catchMoney),
-                        'remark'=> '提现打款重复扣除',
-                    ];
-                    // 处理账户
-                    /*if(!UserModel::where('id', $userId)->dec('score', $catchMoney)->update()){
-                        DB::rollback();
-                        return 'fail';
-                    }*/
-                }elseif(($score+$money)>=$catchMoney){
-                    // 扣除余额后剩余的钱
-                    $money1 = max(0,$catchMoney - $money);
-                    echo "【扣除积分和余额】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户余额[{$money}]-积分[{$score}],扣除后余额 ".max(0,$catchMoney-$money).",扣除后积分 ".($score-$money1).'<br>';
-                    $moneyLogs[] = [
-                         'uid'=> $userId,
-                         'money'=> $money,
-                         'type'=> 17,
-                         'create_at'=> date('Y-m-d H:i:s'),
-                         'state'=> 2,
-                         'from_id'=>0,
-                         'before_money'=> $money,
-                         'after_money'=> 0,
-                         'remark'=> '提现打款重复扣除',
-                     ];
+            if($profit>0){
+                echo "用户{$id} {$profit}  利润转入<br>";
+                $logs[] = [
+                    'uid'=> $id,
+                    'type'=> 2,
+                    'score'=> $profit,
+                    'create_at'=> date('Y-m-d H:i:s'),
+                    'from_id'=> 0,
+                    'uid2'=> 0,
+                    'state'=> 1,
+                    'before_score'=> $newGreenScore,
+                    'after_score'=> $newGreenScore+$profit,
+                    'remark'=> '利润转入'
+                ];
 
-                    // 扣积分
-                    $scoreLogs[] = [
-                        'uid'=> $userId,
-                        'score'=> $money1,
-                        'type'=> 13,
-                        'create_at'=> date('Y-m-d H:i:s'),
-                        'state'=> 2,
-                        'from_id'=>0,
-                        'before_score'=> $score,
-                        'after_score'=> max(0,$score-$money1),
-                        'remark'=> '提现打款重复扣除',
-                    ];
+                $newGreenScore +=$profit;
+            }
 
-                    // 处理账户
-                    /*if(!UserModel::where('id', $userId)->dec('money', $money)->dec('score',$money1)->update()){
-                        DB::rollback();
-                        return 'fail';
-                    }*/
-                }else{
-                    echo "【账户不足】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户余额[{$money}]-积分[{$score}],账户不够<br>";
-                    $noCatchUsers[$userId] = "【账户不足】用户[{$userId}][{$mobile}],账户余额[{$money}]-积分[{$score}],处理金额 {$catchMoney},账户不够";
-                }
-            }else{
-                echo "【未做处理】用户[{$userId}][{$mobile}],处理金额 {$catchMoney},账户积分[{$money}]-积分[{$score}],数据错误未处理<br>";
+            if($newGreenScore>0 && !UserModel::where('id',$id)->inc('green_score',$newGreenScore)->update()){
+                Db::rollback();
+                return 'fail';
+            }
+        }
+
+        if($logs){
+            if(!GreenScoreLogModel::insertAll($logs)){
+                Db::rollback();
+                return 'fail';
+            }
+
+            if(!UserModel::where('id','>',0)->update(['score'=>0,'money'=>0,'profit_money'=>0,'update_time'=>date('Y-m-d H:i:s')])){
+                Db::rollback();
+                return 'fail';
             }
         }
 
         Db::commit();
-        return 'success';
 
+        return 'success';
     }
 
 }

+ 8 - 3
app/api/controller/v1/User.php

@@ -5,6 +5,7 @@ namespace app\api\controller\v1;
 
 use app\api\services\UserServices;
 use app\common\model\ActiveLogModel;
+use app\common\model\GoodsAttensionModel;
 use app\common\model\MoneyLogModel;
 use app\common\model\PaymentModel;
 use app\common\model\ScoreAwayLogModel;
@@ -455,7 +456,9 @@ class User
     public function upgradeLevel (Request $request, UserServices $services)
     {
         try {
-            return $services->upgradeStar($request);
+            if($result = UserService::make()->upgradeLevel($request->uid, $request->post('type', 2))){
+                return api_succ_return($result);
+            }
         } catch (Exception $e) {
             return api_succ_return(['code'=>$e->getCode(), 'msg'=>$e->getMessage()]);
         }
@@ -753,10 +756,12 @@ class User
      */
     public function goodsAttList(Request $request){
         $post = $request->post();
-        $list = Db::name('goods_attension')
-            ->alias('a')
+        $list = GoodsAttensionModel::alias('a')
             ->where('a.uid', '=', $request->uid)
             ->leftJoin('shop_goods g', 'g.goods_id = a.goods_id')
+            ->withAttr('goods_img', function ($value) {
+                return getPreviewUrl($value);
+            })
             ->field('a.id,a.goods_id, g.goods_img, g.goods_name,g.goods_sn, g.attension_count,g.price, g.rebate_score')
             ->page($post['page'], $post['limit'])
             ->select()->toArray();

+ 0 - 1
app/api/middleware/AuthSignMiddleWare.php

@@ -53,7 +53,6 @@ class AuthSignMiddleWare implements MiddlewareInterface
             if (ISNOTREQUESTPASS($request->param())){
                 return api_error_return(['msg'=>'参数错误', 'data'=>null]);
             }
-
         }
 
 

+ 20 - 14
app/api/middleware/AuthTokenMiddleWare.php

@@ -44,27 +44,33 @@ class AuthTokenMiddleWare implements MiddlewareInterface
                 return api_error_return(['msg'=>'更新数据中,请稍后几秒', 'data'=>null]);
             }
 
-            if (env('API.IS_PUBLIC_REQUEST_VERIFY')){
-                if (ISNOTREQUESTPASS($request->param())){
-                    return api_error_return(['msg'=>'参数错误', 'data'=>null]);
-                }
+            // 非上传文件验证签名处理
+            $file = $request->file('file');
+            if(empty($file)){
+                if (env('API.IS_PUBLIC_REQUEST_VERIFY')){
 
-            }
+                    if (ISNOTREQUESTPASS($request->param())){
+                        return api_error_return(['msg'=>'参数错误', 'data'=>null]);
+                    }
 
-            if (env('API.IS_SIGN_VERIFY')){
-                if (empty($request->param('sign'))){
-                    return api_error_return(['msg'=>'签名不存在', 'data'=>null]);
                 }
 
-                $sign = createApiSign($request->param());
-                if ($request->param('sign') != $sign){
-                    return api_error_return(['msg'=>'签名错误', 'data'=>['aa'=>$sign]]);
-                }
-                if (time() - $request->post('timestamp') > 20){
-                    return api_error_return(['msg'=>'请求失败,稍后再试', 'data'=>null]);
+                if (env('API.IS_SIGN_VERIFY')){
+                    if (empty($request->param('sign'))){
+                        return api_error_return(['msg'=>'签名不存在', 'data'=>null]);
+                    }
+
+                    $sign = createApiSign($request->param());
+                    if ($request->param('sign') != $sign){
+                        return api_error_return(['msg'=>'签名错误', 'data'=>['aa'=>$sign]]);
+                    }
+                    if (time() - $request->post('timestamp') > 20){
+                        return api_error_return(['msg'=>'请求失败,稍后再试', 'data'=>null]);
+                    }
                 }
             }
 
+
             $token = trim($request->header('token', ''));
 
             if (empty($token)){

+ 0 - 5
app/api/route/v1.php

@@ -4,11 +4,6 @@ use think\facade\Route;
 
 //Route::any('testredis', 'v1.Test/testredis'); // 测试
 Route::any('test', 'v1.Test/test'); // 测试
-Route::any('test1', 'v1.Test/test1'); // 测试
-Route::get('test2', 'v1.Test/test2'); // 测试
-Route::get('test5', 'v1.Test/test5'); // 测试
-//Route::post('payResult', 'v1.Pay/payResult'); // 支付回调
-
 
 /**
  * 验证sign

+ 0 - 2
app/api/services/UserServices.php

@@ -511,9 +511,7 @@ class UserServices extends BaseServices
             throw new Exception('当前已是最大星级,无需升级', 308);
         }
 
-
         $next_data = Db::name('level_setting')->where('level', $user['level']+1)->find();
-//        $star_config = get_star_config($user['level'] + 1);
 
         if (empty($next_data))
             throw new Exception('配置错误');

+ 43 - 8
app/common.php

@@ -318,18 +318,18 @@ if (!function_exists('object_array')) {
 function ISNOTREQUESTPASS($data)
 {
     if (!isset($data['app_sources'])){
-
         return true;
     }
 
-//    sys_model 系统型号
-    if (in_array($data['app_sources'],['ios', 'android'] )){
+    /**
+     * 来源型号
+     */
+    if (in_array($data['app_sources'],['ios', 'android','macos'] )){
         if (!isset($data['app_version']) || !isset($data['app_sources']) || !isset($data['timestamp']) || !isset($data['sys_version']) || !isset($data['sys_model']) || !isset($data['udid'])){
-
             return true;
         }
     }
-    if (isset($data['app_sources']) && !in_array($data['app_sources'], ['ios', 'android', 'miniapp'])){
+    if (isset($data['app_sources']) && !in_array($data['app_sources'], ['ios', 'android', 'miniapp','macos'])){
         return true;
     }
 
@@ -671,9 +671,6 @@ if (!function_exists('cryption')) {
 
 }
 
-
-
-
 /**
  * 删除字符串中的所有空格
  */
@@ -2474,6 +2471,44 @@ function RSA_openssl($data,$type='encode'){
 
 }
 
+if (!function_exists('getUploadPath')){
+    /**
+     * 获取上传图片的相对路径
+     * @param $url
+     * @return string|string[]|null
+     */
+    function getUploadPath($url){
+        return $url? preg_replace("/(.*)\/upload\//",'/upload/',$url) : '';
+    }
+}
+
+if (!function_exists('getPreviewUrl')){
+    /**
+     * 获取上传图片的相对路径
+     * @param $url
+     * @return string|string[]|null
+     */
+    function getPreviewUrl($url){
+        if($url && preg_match("/^http/", $url) && !preg_match("/fudai.gxnwsoft.com/", $url) && !preg_match("/db.ylshuzi.com/", $url)){
+            return $url;
+        }
+
+        return $url? getWebUrl().preg_replace("/(.*)\/upload\//",'/upload/',$url) : '';
+    }
+}
+
+if (!function_exists('getContent')){
+    /**
+     * 获取去除绝对图片路径的内容
+     * @param $content
+     * @return string|string[]|null
+     */
+    function getContent($content){
+        $url = "(https|http):\/\/db.ylshuzi.com";
+        return $content? preg_replace("/{$url}\/upload/",getWebUrl().'/upload',$content) : '';
+    }
+}
+
 
 
 

+ 16 - 0
app/common/model/GreenScoreLogModel.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 绿色积分记录
+ * Class GreenScoreLogModel
+ * @package app\common\model
+ */
+class GreenScoreLogModel extends Model
+{
+
+    protected $name = 'green_score_log';
+}

+ 20 - 28
app/common/model/ShopGoods.php

@@ -49,23 +49,23 @@ class ShopGoods extends TimeModel
 
         //处理价格及库存
         $default_skus = $goods['default_skus'];
-
+        $goods['goods_img'] = getUploadPath($goods['goods_img']);
+        $goods['box_pic'] = getUploadPath($goods['box_pic']);
         $goods['goods_sn'] = createdGoodsSn();
         $goods['original_price'] = $goods['min_original_price'] = $goods['max_original_price'] = $default_skus['original_price'];
         $goods['price'] = $goods['min_price'] = $goods['max_price'] = $default_skus['price'];
         $goods['cost_price'] = $goods['min_cost_price'] = $goods['max_cost_price'] = $default_skus['cost_price'];
         $goods['inventory'] = $default_skus['stock'];
-        $goods['goods_img_banner'] = explode('|', $goods['goods_img_banner']);
-        $goods['goods_img_banner'] = json_encode($goods['goods_img_banner']);
+        $goodsBanner = explode('|', $goods['goods_img_banner']);
+        if($goodsBanner){
+            foreach ($goodsBanner as &$v){
+                $v = getUploadPath($v);
+            }
+        }
+        $goods['goods_img_banner'] = json_encode($goodsBanner);
         $goods['is_exist_many_spec'] = 0;
         $goods['rebate_score'] = $goods['rebate_score'];
-//        $goods['menu_id'] = $goods['menu_id'];
         $goods['spec_name'] = $goods['spec_name'];
-
-
-//        $goods['box_pic'] = getWebUrl().'/'.$goods['box_pic'];
-
-
         if ($goods['goods_type'] == 1){
             if ($goods['rebate_score'] <=0){
                 sr_throw('返利积分积分不能为0');
@@ -82,12 +82,6 @@ class ShopGoods extends TimeModel
             }
         }
 
-
-//        if ($goods['price'] < $goods['rebate_score']){
-//            sr_throw('所送积分不能高于价格');
-//        }
-
-
         if (!empty($goods['hot_keywords'])) {
             $goods['hot_keywords'] = implode(',', $goods['hot_keywords']);
         }
@@ -96,13 +90,10 @@ class ShopGoods extends TimeModel
             $goods['buynote_template'] = $tmp;
         }
         if (empty($goods['sales_volume'])) {
-//            $goods['sales_volume'] = mt_rand(60, 1000);
             $goods['sales_volume'] = 0;
         }
-//        Db::startTrans();
-//        try {
-            $goodsId = isset($goods['goods_id']) ? $goods['goods_id'] : 0;
 
+            $goodsId = isset($goods['goods_id']) ? $goods['goods_id'] : 0;
 
             //step:1 插入商品表
             if (!empty($goods['goods_id'])) {
@@ -129,13 +120,6 @@ class ShopGoods extends TimeModel
             }
             $specSkus['rebate_score'] = $goods['rebate_score'];
             Db::name('shop_goods_spec')->save($specSkus);
-
-//            Db::commit();
-//            return true;
-//        } catch (\Exception $e) {
-//            Db::rollback();
-//            return false;
-//        }
     }
 
     public static function manySpecGoods ($goods)
@@ -162,8 +146,16 @@ class ShopGoods extends TimeModel
         $goods['min_original_price'] = $mask_original_price['min'];
         $goods['max_original_price'] = $mask_original_price['max'];
 
-        $goods['goods_img_banner'] = explode('|', $goods['goods_img_banner']);
-        $goods['goods_img_banner'] = json_encode($goods['goods_img_banner']);
+        $goods['goods_img'] = getUploadPath($goods['goods_img']);
+        $goods['box_pic'] = getUploadPath($goods['box_pic']);
+        $goodsBanner = explode('|', $goods['goods_img_banner']);
+        if($goodsBanner){
+            foreach ($goodsBanner as &$v){
+                $v = getUploadPath($v);
+            }
+        }
+        $goods['goods_img_banner'] = json_encode($goodsBanner);
+
         //处理销售价 按规格集合中-区间,最低,最高
         $price = multi_minmax_inarray($specSkus, 'price');
         if (count(array_unique($price)) == 1) {

+ 9 - 2
app/common/model/ShopOrder.php

@@ -20,7 +20,10 @@ class ShopOrder extends TimeModel
 
     public function goods ()
     {
-        return $this->hasMany('shopOrderGoods', 'order_id', 'order_id');
+        return $this->hasMany('shopOrderGoods', 'order_id', 'order_id')
+            ->withAttr('goods_img',function($value){
+                return getPreviewUrl($value);
+            });
     }
 
     public function shipping ()
@@ -34,7 +37,11 @@ class ShopOrder extends TimeModel
      */
     public function withOrderGoods ()
     {
-        return self::hasMany(OrderGoods::class, 'order_id', 'order_id')->field('goods_name,goods_id,goods_img,num,price,total_fee,spec_text,goods_spec_id');
+        return self::hasMany(OrderGoods::class, 'order_id', 'order_id')
+            ->field('goods_name,goods_id,goods_img,num,price,total_fee,spec_text,goods_spec_id')
+            ->withAttr('goods_img', function($value){
+                return getPreviewUrl($value);
+            });
     }
 
     /**

+ 16 - 0
app/common/model/UpgradeLogModel.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+/**
+ * 用户升级记录
+ * Class UpgradeLogModel
+ * @package app\common\model
+ */
+class UpgradeLogModel extends Model
+{
+
+    protected $name = 'upgrade_log';
+}

+ 72 - 12
app/common/service/ShopGoodsService.php

@@ -63,12 +63,17 @@ class ShopGoodsService
             $where['menu_id'] = $menuId;
         }
 
+        $goodsType = isset($map['goods_type'])? intval($map['goods_type']) : 0;
+        if ($goodsType>0){
+            $where['goods_type'] = $goodsType;
+        }
+
         $keywords = isset($map['keywords'])? trim($map['keywords']) : '';
         if (!empty($keywords)) {
             $where['goods_name|hot_keywords'] = "%{$map['keywords']}%";
         }
 
-        $field = $field? $field : 'sort,category,goods_sn,goods_name,goods_img,min_original_price as original_price,min_price as price,rebate_score,sales_volume,inventory,attension_count,restrictions_num';
+        $field = $field? $field : 'sort,category,goods_sn,goods_name,goods_type,goods_img,min_original_price as original_price,min_price as price,rebate_score,sales_volume,inventory,attension_count,restrictions_num';
         $order = isset($map['sort']) && $map['sort']? $map['sort'] : 'sort desc,goods_id desc';
         $list = $this->model->where($where)
             ->where(function($query) use($map){
@@ -77,6 +82,9 @@ class ShopGoodsService
                     $query->where('give_vip','>', 0);
                 }
             })
+            ->withAttr('goods_img',function($value){
+                return getPreviewUrl($value);
+            })
             ->field($field)
             ->order($order)
             ->paginate($pageSize);
@@ -89,6 +97,34 @@ class ShopGoodsService
     }
 
     /**
+     * 获取随机商品
+     * @param int $num
+     * @return array|mixed
+     */
+    public function getRandomGoods($num=12)
+    {
+        $cacheKey = "caches:goods:random:{$num}";
+        $data = RedisCache::get($cacheKey);
+        if($data){
+            return $data;
+        }
+        $data = $this->model->where('on_sale', 1)
+            ->withAttr('box_pic',function ($value){
+                return getPreviewUrl($value);
+            })
+            ->orderRaw("rand() , goods_id DESC")
+            ->field('goods_id,box_pic,goods_sn')
+            ->limit($num)
+            ->select()
+            ->toArray();
+        if($data){
+            RedisCache::set($cacheKey, $data, rand(5, 10));
+        }
+
+        return $data?$data : [];
+    }
+
+    /**
      * 获取开奖福袋商品
      * @param int $num
      * @return array|mixed
@@ -107,6 +143,9 @@ class ShopGoodsService
         $data = $this->model->where('box_type', $boxType)
             ->where('goods_type', 2)
             ->where('can_open', $canOpen)
+            ->withAttr('goods_img', function($value){
+                return getPreviewUrl($value);
+            })
             ->field('goods_id,box_type,goods_img,price,goods_name')
             ->limit($num)
             ->select();
@@ -143,13 +182,22 @@ class ShopGoodsService
         $info = RedisCache::get($cacheKey);
         if(empty($info)){
             $field = 'menu_id,spec_name,goods_id,category,goods_sn,goods_name,goods_img,goods_img_banner,goods_remark,min_original_price as original_price,min_price as price,note,inventory,rebate_score,sales_volume,restrictions,rush_buy,buynote_template as buyNote,post_template_id,restrictions_num';
-            $info = $this->model->where($where)->field($field)->withAttr('goods_img_banner', function ($value) {
-                return json_decode($value, true) ?: [];
-            })->withAttr('goods_remark', function ($value) {
-                return htmlspecialchars_decode($value);
-            })->withAttr('buyNote', function ($value) {
-                return htmlspecialchars_decode($value);
-            })->findOrEmpty()->toArray();
+            $info = $this->model->where($where)->field($field)
+                ->withAttr('goods_img_banner', function ($value) {
+                    $banners = $value? json_decode($value, true) : [];
+                    if($banners){
+                        foreach ($banners as &$v){
+                            $v = getPreviewUrl($v);
+                        }
+                    }
+                    return $banners;
+                })->withAttr('goods_img', function ($value) {
+                    return getPreviewUrl($value);
+                })->withAttr('goods_remark', function ($value) {
+                    return getContent(htmlspecialchars_decode($value));
+                })->withAttr('buyNote', function ($value) {
+                    return htmlspecialchars_decode($value);
+                })->findOrEmpty()->toArray();
         }else{
             $isCache = true;
         }
@@ -304,6 +352,9 @@ class ShopGoodsService
         $info = $this->model->alias('a')
             ->leftJoin('shop_supplier s','s.id = a.supplier')
             ->where(['a.goods_sn'=> $goodsSn])
+            ->withAttr('goods_img', function ($value) {
+                return getPreviewUrl($value);
+            })
             ->field($field)
             ->find();
         $info = $info? $info->toArray() : [];
@@ -335,6 +386,9 @@ class ShopGoodsService
         $info = $this->model->alias('a')
             ->leftJoin('shop_supplier s','s.id = a.supplier')
             ->where(['a.goods_id'=> $goodsId])
+            ->withAttr('goods_img', function ($value) {
+                return getPreviewUrl($value);
+            })
             ->field($field)
             ->find();
         $info = $info? $info->toArray() : [];
@@ -359,7 +413,10 @@ class ShopGoodsService
             return $data;
         }
         $field = $field? $field : 'goods_type';
-        $data = $this->model->whereIn('goods_sn', $snArr)->field($field)->findOrEmpty();
+        $data = $this->model->whereIn('goods_sn', $snArr)->field($field)
+            ->withAttr('goods_img', function ($value) {
+            return getPreviewUrl($value);
+        })->findOrEmpty();
         if($data){
             $data = $data->toArray();
             RedisCache::set($cacheKey, $data, rand(5, 10));
@@ -393,10 +450,13 @@ class ShopGoodsService
                     $query->whereIn('box_type', [10,20,30,40]);
                 }
             })
-            ->withAttr('box_img', function ($val, $data) {
-                return getWebUrl() . '.' . $val;
+            ->withAttr('box_pic', function ($value) {
+                return getPreviewUrl($value);
+            })
+            ->withAttr('goods_img', function ($value) {
+                return getPreviewUrl($value);
             })
-            ->field('goods_id,box_type,goods_img,price,goods_name,goods_sn')
+            ->field('goods_id,box_type,box_pic,goods_img,price,goods_name,goods_sn')
             ->order('box_type', 'desc')
             ->paginate($pageSize)
             ->toArray();

+ 90 - 4
app/common/service/UserService.php

@@ -2,8 +2,10 @@
 
 namespace app\common\service;
 
+use app\common\model\UpgradeLogModel;
 use app\common\model\UserModel;
 use app\common\model\UserUnmoneyModel;
+use think\Exception;
 use think\facade\Db;
 use utils\RedisCache;
 
@@ -108,7 +110,7 @@ class UserService
     }
 
     /**
-     * 用户升级
+     * 批量用户升级
      * @return array|string
      */
     public function updateLevel()
@@ -121,7 +123,7 @@ class UserService
         try {
             RedisCache::setnx($cacheKey . 'lock', date('Y-m-d H:i:s'), rand(5, 10));
             $list = $this->model->where('has_update_level', '>', 0)
-                ->field('id,level,pid,path')
+                ->field('id,level,nickname,pid,path')
                 ->select();
             $list = $list? $list->toArray() : [];
             if (empty($list)) {
@@ -140,6 +142,7 @@ class UserService
             foreach ($list as $item) {
                 $uid = isset($item['id']) ? $item['id'] : 0;
                 $path = isset($item['path']) ? $item['path'] : 0;
+                $nickname = isset($item['nickname']) ? $item['nickname'] : '';
                 $userLevel = isset($item['level']) ? intval($item['level']) : 0;
 
                 // 判断团队人数获取可升等级
@@ -158,14 +161,16 @@ class UserService
                 $ztCount = 0;
                 if ($updateLevel > $userLevel) {
                     // 所需直推等级
-                    $ztLevel = isset($levelConfig[$updateLevel]['zt_level']) ? intval($levelConfig[$updateLevel]['zt_level']) : 0;
+                    $nextLevelData = isset($levelConfig[$updateLevel])?$levelConfig[$updateLevel] : [];
+                    $ztLevel = isset($nextLevelData['zt_level']) ? intval($nextLevelData['zt_level']) : 0;
                     $ztCount = $this->getZtCount($uid, $ztLevel);
 
                     // 可升级的等级所需直推人数
-                    $needZtCount = isset($levelConfig[$updateLevel]['zt_num']) ? intval($levelConfig[$updateLevel]['zt_num']) : 0;
+                    $needZtCount = isset($nextLevelData['zt_num']) ? intval($nextLevelData['zt_num']) : 0;
                     if ($needZtCount <= $ztCount) {
                         // 当前用户升级,且去掉可升级状态
                         $this->model->where('id', $uid)->update(['level' => $updateLevel, 'has_update_level' => 0, 'update_time' => date('Y-m-d H:i:s')]);
+                        UpgradeLogModel::insert(['uid' => $uid, 'nickname' => $nickname, 'original_level' => $userLevel, 'level' => $updateLevel, 'condition' => json_encode($nextLevelData), 'type' => 2, 'state' => 1]);
                         $levelIds[] = $uid;
                     }else{
                         $noCatchUids[] = $uid;
@@ -199,6 +204,87 @@ class UserService
     }
 
     /**
+     * 用户升级
+     * @param $uid
+     * @param int $type
+     * @return array
+     * @throws \think\Exception
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function upgradeLevel($uid, $type=2)
+    {
+        $cacheKey = "caches:users:updateLevel:{$uid}_".date('YmdHi');
+        if(RedisCache::get($cacheKey.'_lock')){
+            sr_throw('暂不需要升级');
+        }
+
+        RedisCache::setnx($cacheKey . 'lock', date('Y-m-d H:i:s'), rand(5, 10));
+        $info = $this->model->where('id', $uid)
+            ->field('id,level,nickname,pid,path')
+            ->findOrEmpty();
+        $path = isset($info['path']) ? $info['path'] : 0;
+        $nickname = isset($info['nickname']) ? $info['nickname'] : '';
+        $userLevel = isset($info['level']) ? intval($info['level']) : 0;
+
+        // 等级配置
+        $levelConfig = LevelSettingService::make()->getConfigData(0, 1);
+        if (empty($levelConfig)) {
+            sr_throw('请先配置等级升级参数');
+        }
+
+        // 判断团队人数获取可升等级
+        $updateLevel = 0;
+        $teamCount = $this->getTeamCount($uid, $path);  // 团队人数
+        foreach ($levelConfig as $val) {
+            $needTeamCount = isset($val['team_num']) ? $val['team_num'] : 0;
+            $level = isset($val['level']) ? $val['level'] : 0;
+            // 如果团队人数满足当前等级要求(排除)
+            if ($level > 0 && $needTeamCount && $teamCount >= $needTeamCount) {
+                $updateLevel = $level;
+            }
+        }
+
+        // 如果当前用户需要升级
+        $canUpgrade = false;
+        if ($updateLevel > $userLevel) {
+            // 所需直推等级
+            $nextLevelData = isset($levelConfig[$updateLevel])?$levelConfig[$updateLevel] : [];
+            $ztLevel = isset($nextLevelData['zt_level']) ? intval($nextLevelData['zt_level']) : 0;
+            $ztCount = $this->getZtCount($uid, $ztLevel);
+
+            // 可升级的等级所需直推人数
+            $needZtCount = isset($nextLevelData['zt_num']) ? intval($nextLevelData['zt_num']) : 0;
+            if ($needZtCount <= $ztCount) {
+                $canUpgrade == true;
+            }
+        }
+
+        if($type == 2){
+            if($canUpgrade){
+                return ['code'=>206, 'msg'=>'当前可以升级'];
+            }else{
+                throw new Exception('未达到升级条件', 205);
+            }
+        }
+
+        if($type == 1 && $canUpgrade){
+            // 当前用户升级,且去掉可升级状态
+            $this->model->where('id', $uid)->update(['level' => $updateLevel, 'has_update_level' => 0, 'update_time' => date('Y-m-d H:i:s')]);
+            UpgradeLogModel::insert(['uid' => $uid, 'nickname' => $nickname, 'original_level' => $userLevel, 'level' => $updateLevel, 'condition' => json_encode($nextLevelData), 'type' => 2, 'state' => 1]);
+
+            // 用户升级后,处理上层用户升级(设置为可升级状态)
+            if ($path) {
+                $this->model->whereIn('id', explode(',', $path))->update(['has_update_level' => 1, 'update_time' => date('Y-m-d H:i:s')]);
+            }
+
+            return ['msg' => '升级成功,当前等级为:' . $nextLevelData['name'], 'data'=>['level_name' => $nextLevelData['name']]];
+        }
+
+        sr_throw('未达到升级条件');
+    }
+    /**
      * 统计有效直推人数
      * @param $uid
      * @param int $level 等级