xg 2 years ago
parent
commit
22066474b0

+ 0 - 2
application/admin/controller/Mobile.php

@@ -11,8 +11,6 @@ use app\common\model\MobileInfo;
 use app\common\model\MobileSub;
 use app\common\service\MobileExport;
 use app\common\service\MobileImport;
-use app\common\service\SubService;
-use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
 use PhpOffice\PhpSpreadsheet\IOFactory;
 use PhpOffice\PhpSpreadsheet\Reader\Csv;
 use PhpOffice\PhpSpreadsheet\Reader\Xls;

+ 1 - 1
application/admin/controller/general/Profile.php

@@ -52,7 +52,7 @@ class Profile extends Backend
             $params = $this->request->post("row/a");
             $params = array_filter(array_intersect_key(
                 $params,
-                array_flip(array('phone', 'nickname', 'password', 'avatar'))
+                array_flip(array('phone', 'nickname', 'password', 'avatar','wx_qr'))
             ));
             unset($v);
            /* if (!Validate::is($params['email'], "email")) {

+ 7 - 1
application/admin/model/Admin.php

@@ -7,7 +7,10 @@ use app\common\model\MobileOrderRefundLog;
 use think\db\Query;
 use think\Model;
 use think\Session;
-
+/**
+ *@method static Query|static proxy()
+ *@method static Query|static sub()
+ */
 class Admin extends Model
 {
 
@@ -78,6 +81,9 @@ class Admin extends Model
     public function scopeProxy(Query $query){
         $query->where('proxy',1);
     }
+    public function scopeSub(Query $query){
+        $query->where('sub',1);
+    }
 
     protected static function init()
     {

+ 15 - 1
application/admin/view/general/profile/index.html

@@ -63,6 +63,7 @@
                             <label for="username" class="control-label">{:__('Username')}:</label>
                             <input type="text" class="form-control" id="username" name="row[username]" value="{$admin.username|htmlentities}" disabled/>
                         </div>
+                        {if condition="$admin['is_manager']"}
                         <div class="form-group">
                             <label for="phone" class="control-label">{:__('手机号')}:</label>
                             <input type="text" class="form-control" id="phone" name="row[phone]" value="{$admin.phone|htmlentities}" data-rule="required;mobile"/>
@@ -75,11 +76,24 @@
                             <label for="password" class="control-label">{:__('Password')}:</label>
                             <input type="password" class="form-control" id="password" placeholder="{:__('Leave password blank if dont want to change')}" autocomplete="new-password" name="row[password]" value="" data-rule="password"/>
                         </div>
+                        {/if}
+                        {if condition="$auth->check('admin/_allow_wx_qr_power') and $admin['is_sub']"}
+                        <div class="form-group">
+                            <label class="control-label" style="display: block;">{:__('微信二维码')}:</label>
+                                <div class="input-group">
+                                    <input id="c-wx_qr" class="form-control" size="50" name="row[wx_qr]" type="text" value="{$admin.wx_qr|htmlentities}">
+                                    <div class="input-group-addon no-border no-padding">
+                                        <span><button type="button" id="faupload-wx_qr" class="btn btn-danger faupload" data-input-id="c-wx_qr" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp" data-multiple="false" data-preview-id="p-wx_qr"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
+                                    </div>
+                                    <span class="msg-box n-right" for="c-wx_qr"></span>
+                                </div>
+                            <ul class="row list-inline faupload-preview" id="p-wx_qr"></ul>
+                        </div>
+                        {/if}
                         <div class="form-group">
                             <button type="submit" class="btn btn-success">{:__('Submit')}</button>
                             <button type="reset" class="btn btn-default">{:__('Reset')}</button>
                         </div>
-
                     </div>
                 </form>
             </div>

+ 6 - 0
application/api/controller/Common.php

@@ -276,6 +276,7 @@ class Common extends Api
      * @ApiReturnParams (name="bussiness_contact_mobile",description="商务合作电话")
      */
     public function config(){
+        $chanId=getChanId();
         $data=[
             'site_name'=>\config('site.name'),
             'com_name'=>\config('site.base_company_name'),
@@ -292,6 +293,11 @@ class Common extends Api
             'flow_main_logo'=>config('site.flow_main_logo'),
             'bussiness_contact_mobile'=>config('site.bussiness_contact_mobile'),
         ];
+        if($chanId){
+            if(getSub()->hasAllowWxQrPower() && getSub()->getAdmin('wx_qr')){
+                $data['wxp_qrcode']=getSub()->getAdmin('wx_qr');
+            }
+        }
         $this->success('',$data);
     }
 }

+ 1 - 1
application/common.php

@@ -615,7 +615,7 @@ function getChanId(){
 #分站
 function getSub(){
     $id=input('chanId');
-    return SubService::instance($id);
+    return SubService::instance($id,'api');
 }
 function cache_simple(){
     $instance=null;

+ 1 - 1
application/common/controller/Backend.php

@@ -621,7 +621,7 @@ class Backend extends Controller
     }
 
     protected function service(){
-        return SubService::instance($this->auth->id);
+        return SubService::instance($this->auth->id,'admin');
     }
     protected function checkSubPower($ids){
         if($this->admin('is_sub') && !$this->model->where('admin_id',$this->auth->id)->find($ids)){

+ 34 - 5
application/common/service/SubService.php

@@ -7,16 +7,19 @@ use app\admin\model\AuthRule;
 use traits\think\Instance;
 
 class SubService{
-    use Instance;
     /** @var Admin */
     protected $admin;
     protected $chanId;
     protected $rules=[];
 
-    public function __construct($chanId)
+    public function __construct($chanId,$fromWhere)
     {
         $this->chanId=$chanId;
-        $this->admin=Admin::get($chanId);
+        if($fromWhere=='admin'){
+            $this->admin=Admin::get($chanId);
+        }elseif ($fromWhere=='api'){
+            $this->admin=Admin::sub()->find($chanId);
+        }
         $this->getRules();
     }
 
@@ -37,9 +40,13 @@ class SubService{
     /**
      * @return Admin
      */
-    public function getAdmin()
+    public function getAdmin($field=null)
     {
-        return $this->admin;
+        if(is_null($field)) {
+            return $this->admin;
+        }else{
+            return $this->admin[$field]??null;
+        }
     }
 
     /**
@@ -78,6 +85,11 @@ class SubService{
         return in_array($id,$this->rules);
     }
 
+    public function hasAllowWxQrPower(){
+        $id=$this->getRuleIdByName('admin/_allow_wx_qr_power');
+        return in_array($id,$this->rules);
+    }
+
     protected function getRuleIdByName($name){
         static $names=[];
         if(!isset($names[$name])){
@@ -89,4 +101,21 @@ class SubService{
     public function isFastHand(){
         return $this->chanId=='kuaishou';
     }
+
+    /**
+     * @var null|static 实例对象
+     */
+    protected static $instance = null;
+
+    /**
+     * 获取示例
+     * @param array $options 实例配置
+     * @return static
+     */
+    public static function instance($chanId,$fromWhere)
+    {
+        if (is_null(self::$instance)) self::$instance = new self($chanId,$fromWhere);
+
+        return self::$instance;
+    }
 }