Kaynağa Gözat

Wesmiler 三勾多商户商城提交

wesmiler 4 yıl önce
ebeveyn
işleme
4a4c1b2f24

+ 5 - 0
app/api/controller/Index.php

@@ -8,6 +8,7 @@ use app\common\enum\settings\SettingEnum;
 use app\common\model\app\AppUpdate as AppUpdateModel;
 use app\common\model\supplier\Service as ServiceModel;
 use app\api\model\plus\chat\Chat as ChatModel;
+use app\common\model\supplier\Supplier;
 use think\facade\Cache;
 
 /**
@@ -30,6 +31,10 @@ class Index extends Controller
             'officia' => SettingModel::getItem('officia'),
             'homepush' => SettingModel::getItem('homepush'),
         );
+
+        $shop_supplier_id = input('shop_supplier_id', 0);
+        $data['dyLink']= Supplier::getDyLink($shop_supplier_id, $this->app_id);
+
         // 扫一扫参数
         $data['signPackage'] = $this->getScanParams($url)['signPackage'];
         return $this->renderSuccess('', $data);

+ 5 - 1
app/api/controller/user/Index.php

@@ -9,6 +9,7 @@ use app\api\model\order\Order as OrderModel;
 use app\api\model\settings\Setting as SettingModel;
 use app\api\model\plus\coupon\UserCoupon as UserCouponModel;
 use app\common\enum\settings\GetPhoneTypeEnum;
+use app\common\model\supplier\Supplier;
 use think\facade\Cache;
 use app\api\model\supplier\Supplier as SupplierModel;
 use app\api\model\plus\chat\Chat as ChatModel;
@@ -42,6 +43,8 @@ class Index extends Controller
         // 充值功能是否开启
         $balance_setting = SettingModel::getItem('balance');
         $balance_open = intval($balance_setting['is_open']);
+
+        $shop_supplier_id = input('shop_supplier_id', 0);
         return $this->renderSuccess('', [
             'coupon' => $coupon,
             'userInfo' => $user,
@@ -60,7 +63,8 @@ class Index extends Controller
             'sign' => SettingModel::getItem('sign'),
             'getPhone' => $this->isGetPhone(),
             'msgcount' => (new ChatModel)->mCount($user),
-            'menus' => UserModel::getMenus($user, $source)   // 个人中心菜单列表
+            'menus' => UserModel::getMenus($user, $source),   // 个人中心菜单列表
+            'dyLink'=> Supplier::getDyLink($shop_supplier_id, $this->app_id),
         ]);
     }
 

+ 1 - 1
app/common/model/product/Category.php

@@ -64,7 +64,7 @@ class Category extends BaseModel
                 }
                 array_push($tree, $first);
             }
-            Cache::tag('cache')->set('category_' . $model::$app_id, compact('all', 'tree'));
+            Cache::tag('cache')->set('category_' . $model::$app_id, compact('all', 'tree'), 3600);
         }
         return Cache::get('category_' . $model::$app_id);
     }

+ 33 - 0
app/common/model/supplier/Supplier.php

@@ -3,6 +3,7 @@
 namespace app\common\model\supplier;
 
 use app\common\model\BaseModel;
+use think\facade\Cache;
 
 /**
  * 商家供应商模型
@@ -71,5 +72,37 @@ class Supplier extends BaseModel
         return true;
     }
 
+    /**
+     * 获取商家抖音推广口令
+     * @param $shop_supplier_id 商家ID
+     * @param int $app_id 平台ID
+     * @return false|mixed|string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public static function getDyLink($shop_supplier_id, $app_id=0){
+        $data = Cache::get('supplier:dyLink:link_' . $app_id . '_' . $shop_supplier_id);
+        if($data){
+            return $data;
+        }
+
+        $where = ['shop_supplier_id'=> $shop_supplier_id];
+        if($app_id){
+            $where['app_id'] = $app_id;
+        }
+        $data = (new static())->where($where)->field('name,dy_name,dy_link')->find();
+        $name = isset($data['name'])? $data['name'] : '';
+        $dy_name = isset($data['dy_name'])? $data['dy_name'] : '';
+        $dy_link = isset($data['dy_link'])? $data['dy_link'] : '';
+        if(empty($dy_link)){
+            return false;
+        }
+
+        $shop_name = $dy_name? $dy_name : $name;
+        $link = rand(1,10)."【{$shop_name}的个人主页】点击打开{$dy_link} 或长按复制此条消息,打开抖音,查看TA的更多作品。";
+        Cache::tag('cache')->set('supplier:dyLink:link_' . $app_id . '_' . $shop_supplier_id, $link, rand(10, 30));
+        return $link;
+    }
 
 }

+ 8 - 0
app/supplier/model/supplier/Supplier.php

@@ -80,9 +80,17 @@ class Supplier extends SupplierModel
             $this->error = '店铺名称已存在';
             return false;
         }
+
+        if($data['dy_link'] && !preg_match("/^http/", $data['dy_link'])){
+            $this->error = '请输入正确的抖音推广链接地址';
+            return false;
+        }
+
         return $this->save([
             'link_name' => $data['link_name'],
             'link_phone' => $data['link_phone'],
+            'dy_name' => $data['dy_name'],
+            'dy_link' => $data['dy_link'],
             'address' => $data['address'],
             'description' => $data['description'],
             'logo_id' => $data['logo_id'],