소스 검색

加评论

zhangdehua 1 년 전
부모
커밋
bebd27b970
2개의 변경된 파일72개의 추가작업 그리고 12개의 파일을 삭제
  1. 66 12
      app/index/controller/User.php
  2. 6 0
      app/index/model/Goods.php

+ 66 - 12
app/index/controller/User.php

@@ -2,6 +2,7 @@
 
 namespace app\index\controller;
 
+use app\index\model\Goods;
 use app\index\model\ShareKey;
 use app\index\service\passport\MailCaptcha as MailCaptchaService;
 use app\index\model\OrderAddress;
@@ -429,10 +430,19 @@ class User extends Controller
         return $this->renderSuccess([], 'Successful!');
     }
 
+    /**
+     * 评论生成器
+     * @return \think\response\Json
+     * @throws \Exception
+     */
     public function genGoodsComments()
     {
-        $others = ['very realistic',];
-        $favor = ['tastes very good',
+        //113
+        $favor = [
+            'very realistic',
+            'I no longer have to worry about not finding an ashtray.',
+            'very portable',
+            'tastes very good',
             'like fresh strawberries',
             'refreshing but not overwhelming',
             'very refreshing',
@@ -541,7 +551,9 @@ class User extends Controller
             'Crisp',
             'Complex',
             'Satisfying',
+            'very realistic',
         ];
+        //50
         $price = [
             'Affordable',
             'Budget-friendly',
@@ -594,12 +606,17 @@ class User extends Controller
             'Money-saving',
             'On a budget',
         ];
-        $amount = ['the amount of smoke is very large', 'very large', 'On sale',
+        //22
+        $amount = ['the amount of smoke is very large',
+            'very large',
+            'On sale',
             'Abundant',
             'Plentiful',
+            'this vapor is plentiful',
             'Ample',
             'Copious',
             'Generous',
+            'Generous vapor',
             'Substantial',
             'Bountiful',
             'Overflowing',
@@ -609,17 +626,54 @@ class User extends Controller
             'Prolific',
             'Luxuriant',
             'In abundance',
+            'good',
+            'my favorite',
+            'will buy again'
         ];
-        $delivery = [];
-        $end = ['good', 'my favorite'];
 
-        $pool = [
-            'The taste of this e-cigarette is really great, completely different from the bitterness and throat irritation of traditional cigarettes.',
-            'The smoke effect of electronic cigarettes is very realistic, as if I can truly feel the pleasure of smoking, and the amount of smoke is very large, so I can enjoy the smoking experience for a long time.',
-            'After switching to e-cigarettes, I found that my body seemed to be healthier and there was no intake of harmful substances like traditional cigarettes. It was really great.',
-            'Electronic cigarettes are very environmentally friendly, do not produce smoke, and have no negative impact on the environment, which makes me feel very proud.',
-            'very portable', ' I can use them anytime, anywhere. They are very convenient, and I no longer have to worry about not finding an ashtray.'
-        ];
+        /*        $pool = [
+                    'The taste of this e-cigarette is really great, completely different from the bitterness and throat irritation of traditional cigarettes.',
+                    'The smoke effect of electronic cigarettes is very realistic, as if I can truly feel the pleasure of smoking, and the amount of smoke is very large, so I can enjoy the smoking experience for a long time.',
+                    'After switching to e-cigarettes, I found that my body seemed to be healthier and there was no intake of harmful substances like traditional cigarettes. It was really great.',
+                    'Electronic cigarettes are very environmentally friendly, do not produce smoke, and have no negative impact on the environment, which makes me feel very proud.',
+                    'very portable', ' I can use them anytime, anywhere. They are very convenient, and I no longer have to worry about not finding an ashtray.'
+                ];*/
+        $goodsModel = new Goods();
+        $goods = $goodsModel->getListSimple()->toArray();
+        $score = [40, 50];
+        //所有的马甲号userid
+        $userModel = new  \app\index\model\User();
+        $userIds = $userModel->where('salt', 'xxxxxx')->column('user_id');
+        $userNum = count($userIds);
+
+        $now = time();
+        $commentModel = new \app\index\model\Comment();
+        foreach ($goods as $item) {
+            $commentsNum = rand(30, 100);
+            $comments = [];
+            for ($i = 0; $i < $commentsNum; $i++) {
+
+                $comment = [
+                    'score' => $score[rand(0, 1)],
+                    'content' => $favor[rand(0, 112)] . ', ' . $price[rand(0, 49)] . ', ' . $amount[rand(0, 21)],
+                    'is_picture' => 0,
+                    'status' => 1,
+                    'sort' => rand(0, 99),
+                    'user_id' => $userIds[rand(0, $userNum - 1)],
+                    'order_id' => 0,
+                    'goods_id' => $item['goods_id'],
+                    'order_goods_id' => 0,
+                    'store_id' => 10001,
+                    'is_delete' => 0,
+                    'create_time' => $now,
+                    'update_time' => $now,
+                ];
+                $comments[] = $comment;
+            }
+
+            $commentModel->saveAll($comments);
+        }
+        return $this->renderSuccess([], 'Successful!');
     }
 
 }

+ 6 - 0
app/index/model/Goods.php

@@ -90,6 +90,12 @@ class Goods extends GoodsModel
         return $this->setGoodsListDataFromApi($list);
     }
 
+    public function getListSimple()
+    {
+        return self::field('goods_id')->where('is_delete', '=', 0)
+            ->select();
+    }
+
     /**
      * 获取商品详情 (详细数据用于页面展示)
      * @param int $goodsId 商品ID