shishao-home 6 лет назад
Родитель
Сommit
93a3eab0f6

+ 120 - 117
app/business/controllers/BaseController.php

@@ -12,120 +12,123 @@ use common\components\util;
 
 class BaseController extends PublicController
 {
-	public $admin, $adminId, $adminAvatar, $account;
-	public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantAsset, $merchantLogo, $signPackage;
-	public $openMerchant, $openMerchantId;
-	public $appId;
-	public $isWeixin = false;
-	public $isLogin = false;
-	public $withoutLogin = [];//不需要登陆的方法名
-	public $validate = true;
-	
-	// Service 模型实例
-	protected $service;
-	// 设置允许与不允许方法 shizq 2019-12-05
-	protected $allowActions = [];
-	protected $notAllowActions = [];
-	
-	public function beforeAction($action)
-	{
-		//token验证
-		//$adminId = jwt::getLoginId();
-		$adminId = 1;
-		if (empty($adminId)) {
-			$this->validate = false;
-		}
-		
-		//方法开放设置 shizq 2019-12-05
-		if (in_array($action->id, $this->notAllowActions)) {
-			util::fail($action->id . ' not allow');
-		}
-		
-		//游客可以访问的方法
-		if (in_array($action->id, $this->withoutLogin)) {
-			$this->validate = true;
-		}
-		if ($this->validate == false) {
-			util::notLogin();
-		}
-		$admin = AdminService::getById($adminId);
-		if (empty($admin)) {
-			util::fail('没有找到管理员');
-		}
-		$merchantId = $admin['merchantId'];
-		if (empty($merchantId)) {
-			util::fail('没有找到商家信息');
-		}
-		$merchant = MerchantService::getById($merchantId);
-		$merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
-		$merchantAsset = MerchantAssetService::getByMerchantId($merchantId);
-		Yii::$app->params['adminId'] = $adminId;
-		Yii::$app->params['admin'] = $admin;
-		Yii::$app->params['merchantId'] = $merchantId;
-		Yii::$app->params['merchant'] = $merchant;
-		Yii::$app->params['merchant'] = $merchant;
-		Yii::$app->params['merchantAsset'] = $merchantAsset;
-		Yii::$app->params['merchantExtend'] = $merchantExtend;
-		$this->adminId = $adminId;
-		$this->merchantId = $merchantId;
-		$this->merchant = $merchant;
-		$this->merchantExtend = $merchantExtend;
-		$this->merchantAsset = $merchantAsset;
-		return parent::beforeAction($action);
-	}
-	
-	public function actionList()
-	{
-		$numargs = func_num_args();
-		$select = $numargs >= 1 ? func_get_arg(0) : '*';
-		$where = $numargs >= 2 ? func_get_arg(1) : null;
-		$order = $numargs >= 3 ? func_get_arg(2) : '';
-		$with = $numargs >= 4 ? func_get_arg(3) : '';
-		
-		$service = $this->service;
-		$list = $service::getList($select, $where, $order, $with);
-		util::success($list);
-	}
-	
-	public function actionAdd()
-	{
-		$data = Yii::$app->request->post();
-		$service = $this->service;
-		$re = $service::add($data);
-		util::success($re);
-	}
-	
-	public function actionDetail()
-	{
-		$id = Yii::$app->request->get('id');
-		$service = $this->service;
-		$data = $service::getById($id);
-		if (!empty($data)) {
-			util::success($data);
-		}
-		
-		util::fail('');
-	}
-	
-	public function actionUpdate()
-	{
-		$data = Yii::$app->request->post();
-		$id = $data['id'];
-		$service = $this->service;
-		$re = $service::updateById($id, $data);
-		if ($re['status'] === true) {
-			util::success($re);
-		}
-		
-		util::fail();
-	}
-	
-	public function actionDelete()
-	{
-		$id = Yii::$app->request->get('id');
-		$service = $this->service;
-		$service::deleteById($id);
-		util::ok('删除成功');
-	}
-	
-}
+    public $admin, $adminId, $adminAvatar, $account;
+    public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantAsset, $merchantLogo, $signPackage;
+    public $openMerchant, $openMerchantId;
+    public $appId;
+    public $isWeixin = false;
+    public $isLogin = false;
+    public $withoutLogin = [];//不需要登陆的方法名
+    public $validate = true;
+
+    // Service 模型实例
+    protected $service;
+    // 设置允许与不允许方法 shizq 2019-12-05
+    protected $allowActions = [];
+    protected $notAllowActions = [];
+
+    public function beforeAction($action)
+    {
+        //token验证
+        //$adminId = jwt::getLoginId();
+        $adminId = 1;
+        if (empty($adminId)) {
+            $this->validate = false;
+        }
+
+        //方法开放设置 shizq 2019-12-05
+        if (in_array($action->id, $this->notAllowActions)) {
+            util::fail($action->id . ' not allow');
+        }
+
+        //游客可以访问的方法
+        if (in_array($action->id, $this->withoutLogin)) {
+            $this->validate = true;
+        }
+        if ($this->validate == false) {
+            util::notLogin();
+        }
+        $admin = AdminService::getById($adminId);
+        if (empty($admin)) {
+            util::fail('没有找到管理员');
+        }
+        $merchantId = AdminToMerchantService::getDefaultMerchant($adminId);
+        if (empty($merchantId)) {
+            util::fail('没有找到商家信息');
+        }
+        $merchant = MerchantService::getById($merchantId);
+        $merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
+        $merchantAsset = MerchantAssetService::getByMerchantId($merchantId);
+        Yii::$app->params['adminId'] = $adminId;
+        Yii::$app->params['admin'] = $admin;
+        Yii::$app->params['merchantId'] = $merchantId;
+        Yii::$app->params['merchant'] = $merchant;
+        Yii::$app->params['merchant'] = $merchant;
+        Yii::$app->params['merchantAsset'] = $merchantAsset;
+        Yii::$app->params['merchantExtend'] = $merchantExtend;
+        $this->adminId = $adminId;
+        $this->merchantId = $merchantId;
+        $this->merchant = $merchant;
+        $this->merchantExtend = $merchantExtend;
+        $this->merchantAsset = $merchantAsset;
+        return parent::beforeAction($action);
+    }
+
+    public function actionList()
+    {
+        $numargs = func_num_args();
+        $select = $numargs >= 1 ? func_get_arg(0) : '*';
+        $where = $numargs >= 2 ? func_get_arg(1) : null;
+        $order = $numargs >= 3 ? func_get_arg(2) : '';
+        $with = $numargs >= 4 ? func_get_arg(3) : '';
+
+        $service = $this->service;
+        $list = $service::getList($select, $where, $order, $with);
+        util::success($list);
+    }
+
+    public function actionAdd()
+    {
+        $data = Yii::$app->request->post();
+        $service = $this->service;
+        $re = $service::add($data);
+        util::success($re);
+    }
+
+    public function actionDetail()
+    {
+        $id = Yii::$app->request->get('id');
+        $service = $this->service;
+        $data = $service::getById($id);
+        if (isset($data['merchantId']) == false || $this->merchantId != $data['merchantId']) {
+            util::fail('没有权限');
+        }
+        if (!empty($data)) {
+            util::success($data);
+        }
+
+        util::fail('');
+    }
+
+    public function actionUpdate()
+    {
+        $data = Yii::$app->request->post();
+        $id = $data['id'];
+        $service = $this->service;
+        $re = $service::updateById($id, $data);
+        if ($re['status'] === true) {
+            util::success($re);
+        }
+
+        util::fail();
+    }
+
+    public function actionDelete()
+    {
+        $id = Yii::$app->request->get('id');
+        $service = $this->service;
+        $service::deleteById($id);
+        util::success([], '删除成功');
+    }
+}
+

+ 24 - 3
app/business/controllers/InviteController.php

@@ -5,25 +5,46 @@
 
 namespace business\controllers;
 
+use common\components\stringUtil;
 use Yii;
 
 
 class InviteController extends BaseController
 {
+    protected $service = '\biz\invite\services\InviteService';
+
+    // list,detail,create,update,delete
+    protected $notAllowActions = ['update', 'delete']; // 设置方法过滤
 	
 	//邀请有礼
 	//写法参考 business/controller/UserController/list
 	public function actionList()
 	{
-
+        $get = Yii::$app->request->get();
+        $status = isset($get['status']) ? $get['status'] : '';
+        $search = isset($get['search']) ? $get['search'] : '';
+        $where = [];
+        $where['merchantId'] = $this->merchantId;
+        if($status != ''){
+            $where['status'] = $status;
+        }
+        if (!empty($search)) {
+            if (stringUtil::isMobieNumber($search)) {
+                $where['mobile'] = $search;
+            } else {
+                $where['userName'] = ['like', $search];
+            }
+        }
+        $list = parent::actionList('*', $where);
+        util::success($list);
 	}
 	
 	//邀请有礼明细
-	public function actionDetail()
+	/*public function actionDetail()
 	{
 		//要验证只有商家自己的才能看,别人的不能看,如果不清楚留空,后面我会给你补验证
 		//涉及用户和头像的从UserService调用,头像分原图和小图,不清楚留空或问我
-	}
+	}*/
 
 	//确认发奖
 	public function actionGive()

+ 7 - 0
biz/base/models/Base.php

@@ -324,4 +324,11 @@ class Base extends ActiveRecord
 	{
 		return self::updateAllCounters($counters, $condition, $params);
 	}
+
+    // 获取图书的作者
+    public function getAuthor()
+    {
+        //同样第一个参数指定关联的子表模型类名
+        return $this->hasOne(Author::className(), ['id' => 'author_id']);
+    }
 }

+ 5 - 0
sql.txt

@@ -102,6 +102,9 @@ ALTER TABLE xhOrder ADD `evaluate` VARCHAR(800) NOT NULL DEFAULT '' COMMENT '评
 DROP TABLE IF EXISTS `xhInvite`;
 CREATE TABLE IF NOT EXISTS `xhInvite`(
 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+merchantId INT NOT NULL DEFAULT 0 COMMENT '商家id',
+`userName` varchar(50) NOT NULL DEFAULT '' COMMENT '邀请人的昵称',
+mobile VARCHAR(20) NOT NULL DEFAULT '' COMMENT '邀请人手机号',
 userId INT NOT NULL DEFAULT 0 COMMENT '受邀人',
 introUserId INT NOT NULL DEFAULT 0 COMMENT '介绍人',
 couponId INT NOT NULL DEFAULT 0 COMMENT '优惠券id',
@@ -110,6 +113,7 @@ prize VARCHAR(50) NOT NULL DEFAULT '' COMMENT '介绍人的奖励',
 orderTime INT NOT NULL DEFAULT 0 COMMENT '下单时间',
 `addTime` INT NOT NULL DEFAULT 0 COMMENT '添加时间'
 )COMMENT='邀请有礼记录';
+
 DROP TABLE IF EXISTS xhInviteAsset;
 CREATE TABLE IF NOT EXISTS `xhInviteAsset`(
 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -121,6 +125,7 @@ duration SMALLINT NOT NULL DEFAULT 0 COMMENT '有效时长,天数',
 prize VARCHAR(50) NOT NULL DEFAULT '' COMMENT '介绍人的奖励',
 `addTime` INT NOT NULL DEFAULT 0 COMMENT '添加时间'
 )COMMENT='商家邀请有礼设置';
+
 DROP TABLE IF EXISTS `xhInviteStat`;
 CREATE TABLE IF NOT EXISTS `xhInviteStat`(
 id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,