shish 6 лет назад
Родитель
Сommit
9590fca64a

+ 36 - 33
app/business/controllers/InviteController.php

@@ -5,63 +5,66 @@
 
 namespace business\controllers;
 
+use biz\invite\services\InviteService;
 use common\components\stringUtil;
+use common\components\util;
 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);
+		$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 = InviteService::getInviteList($where);
+		util::success($list);
 	}
 	
 	//邀请有礼明细
-	/*public function actionDetail()
+	public function actionDetail()
 	{
-		//要验证只有商家自己的才能看,别人的不能看,如果不清楚留空,后面我会给你补验证
-		//涉及用户和头像的从UserService调用,头像分原图和小图,不清楚留空或问我
-	}*/
-
+		$id = Yii::$app->request->get('id');
+		$invite = InviteService::getById($id);
+		InviteService::valid($invite, $this->merchantId);
+		$detail = InviteService::getDetail($id);
+		util::success($detail);
+	}
+	
 	//确认发奖
 	public function actionGive()
 	{
-		//要验证只有商家自己的才能确认发放,别人的不能,如果不清楚留空,后面我会给你补验证
+		$id = Yii::$app->request->get('id');
+		$invite = InviteService::getById($id);
+		InviteService::valid($invite, $this->merchantId);
+		InviteService::give($invite);
+		util::ok();
 	}
 
 	//奖励设置详情
 	public function actionSet()
 	{
-
+	
 	}
-
+	
 	//奖励设置更新
 	public function actionSetUpdate()
 	{
-
+	
 	}
-
+	
 }

+ 21 - 0
biz/invite/classes/InviteClass.php

@@ -3,6 +3,7 @@
 namespace biz\invite\classes;
 
 use biz\user\classes\UserClass;
+use biz\user\services\UserService;
 use Yii;
 use biz\base\classes\BaseClass;
 
@@ -11,6 +12,26 @@ class InviteClass extends BaseClass
 	
 	public static $baseFile = '\biz\invite\models\Invite';
 	
+	public static function groupInviteBaseInfo($list)
+	{
+		if (empty($list)) {
+			return [];
+		}
+		$ids = array_column($list, 'userId');
+		$introUserIds = array_column($list, 'introUserId');
+		$idList = array_merge($ids, $introUserIds);
+		$idList = array_unique(array_filter($idList));
+		$userInfo = UserService::getUserByIds($idList);
+		foreach ($list as $key => $val) {
+			$userId = $val['userId'];
+			$introUserId = $val['introUserId'];
+			$list[$key]['userAvatar'] = isset($userInfo[$userId]['avatar']) ? $userInfo[$userId]['avatar'] : '';
+			$list[$key]['introUserName'] = isset($userInfo[$userId]['userName']) ? $userInfo[$userId]['userName'] : '';
+			$list[$key]['introUserAvatar'] = isset($userInfo[$userId]['avatar']) ? $userInfo[$userId]['avatar'] : '';
+		}
+		return $list;
+	}
+	
 	//判断用户是否被邀请并领过优惠券 shish 2019.12.14
 	public static function hasInvited($user)
 	{

+ 45 - 0
biz/invite/services/InviteService.php

@@ -15,6 +15,31 @@ class InviteService extends BaseService
 	
 	public static $baseFile = '\biz\invite\classes\InviteClass';
 	
+	//取详情 shish 2019.12.18
+	public static function getDetail($id)
+	{
+		$list = InviteClass::getByIds([$id]);
+		$list = InviteClass::groupInviteBaseInfo($list);
+		$info = current($list);
+		$introUserId = $info['introUserId'];
+		//用户的邀请资产
+		$stat = InviteStatService::getStat($introUserId);
+		$info['inviteNum'] = isset($stat['inviteNum']) ? $stat['inviteNum'] : 0;
+		$info['orderNum'] = isset($stat['orderNum']) ? $stat['orderNum'] : 0;
+		return $info;
+	}
+	
+	public static function getInviteList($where)
+	{
+		$data = InviteClass::getList('*', $where, 'addTime DESC');
+		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+		if (empty($list)) {
+			return $data;
+		}
+		$data['list'] = InviteClass::groupInviteBaseInfo($list);
+		return $data;
+	}
+	
 	//用户是否被邀请过 shish 2019.12.14
 	public static function hasInvited($user)
 	{
@@ -78,4 +103,24 @@ class InviteService extends BaseService
 		InviteClass::updateById($id, ['couponId' => $couponId]);
 	}
 	
+	//检查邀请有礼的权限 shish 2019.12.18
+	public static function valid($invite, $merchantId)
+	{
+		if (empty($invite)) {
+			util::fail('邀请无效');
+		}
+		if ($invite['merchantId'] != $merchantId) {
+			util::fail('您没有权限操作');
+		}
+	}
+	
+	public static function give($invite)
+	{
+		if ($invite['status'] != 1) {
+			util::fail('请确认是否可以兑奖');
+		}
+		$time = time();
+		InviteClass::updateBy($id, ['status' => 2, 'giveTime' => $time]);
+	}
+	
 }

+ 8 - 1
biz/invite/services/InviteStatService.php

@@ -3,10 +3,17 @@
 namespace biz\invite\services;
 
 use biz\base\services\BaseService;
+use biz\invite\classes\InviteStatClass;
 
 class InviteStatService extends BaseService
 {
 	
 	public static $baseFile = '\biz\invite\classes\InviteStatClass';
-	
+
+	//取用户的邀请资产 shish 2019.12.18
+	public static function getStat($userId)
+	{
+		return InviteStatClass::getByCondition(['userId' => $userId]);
+	}
+
 }

+ 2 - 0
sql.txt

@@ -6,6 +6,8 @@ ALTER TABLE `xhUserGrowth` MODIFY `relateId` int NOT NULL DEFAULT 0 COMMENT '关
 UPDATE `xhUserCapital` SET `relateId`=0;!!!!!!这条要使用php来转换
 ALTER TABLE `xhUserCapital` MODIFY `relateId` int NOT NULL DEFAULT 0 COMMENT '关联id';
 ALTER TABLE xhUsage ADD `inTurn` INT NOT NULL DEFAULT 0 COMMENT '排序' AFTER `usageName`;
+ALTER TABLE `xhInvite` ADD amount DECIMAL(9,2) NOT NULL DEFAULT 0.00 COMMENT '下单金额' AFTER `couponId`;
+ALTER TABLE `xhInvite` ADD giveTime INT NOT NULL DEFAULT 0 COMMENT '兑奖时间' AFTER `orderTime`;
 
 2019.12.17 shish 用途相关的统计
 drop table if exists `xhStatIncomeUsage`;