소스 검색

商家列表开始

shish 6 년 전
부모
커밋
1eb7b93b68

+ 11 - 415
app/saas/controllers/MerchantController.php

@@ -1,424 +1,20 @@
 <?php
+
 namespace saas\controllers;
 
-use Yii;
-use common\models\xhShop;
-use yii\data\Pagination;
-use common\models\xhUser;
-use common\models\xhMerchant;
-use common\services\xhShopService;
-use common\services\xhUserTagService;
-use common\services\xhMerchantAssetService;
-use common\services\xhMerchantExtendService;
-use common\services\xhMerchantService;
-use common\services\xhUserService;
-use common\services\xhUserTagClassService;
-use common\services\xhDrawCashService;
-use common\services\xhTMessageService;
-use common\services\xhMerchantCapitalService;
+use biz\merchant\services\MerchantService;
 use common\components\util;
-use common\components\configDict;
-use common\components\weixinUtil;
-use common\components\page;
-use common\components\stringUtil;
-use common\services\xhAdminToMerchantService;
+use Yii;
 
-class MerchantController extends PlatformController
+class MerchantController extends BaseController
 {
-    /**
-     * 商家列表
-     */
-    public function actionList()
-    {
-        $query 				= xhMerchant::find();
-        $query->orderBy('id desc');
-        $countQuery 		= clone $query;
-        $pages      		= new Pagination(['totalCount' => $countQuery->count(),'pageSize' => 20]);
-        $merchant     		= $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
-        $merchantStatus		= configDict::getConfig('merchantStatus');
-		$merchantStatusName	= configDict::getConfig('merchantStatusName');
-		$accountStyle		= configDict::getConfig('accountStyleName');
-		$manageStyle		= configDict::getConfig('manageStyleName');
-        return $this->render('list', ['merchantStatus'=>$merchantStatus,'merchant' => $merchant,'accountStyle' => $accountStyle,'manageStyle' => $manageStyle, 'merchantStatusName'=> $merchantStatusName,'pages' => $pages]);
-    }
-
-    /**
-     * 商家详细
-     */
-    public function actionDetail()
-    {
-        $get				= Yii::$app->request->get();
-        $id    	 			= isset($get['id']) ? $get['id'] : 0;
-        $info				= xhMerchantService::getById($id);
-        $status				= configDict::getConfig('merchantStatusName');
-        $asset				= xhMerchantAssetService::getByMerchantId($id);
-        $extend				= xhMerchantExtendService::getByMerchantId($id);
-        $merchantStatus		= configDict::getConfig('merchantStatus');
-        $merchantStatusName	= configDict::getConfig('merchantStatusName');
-        $isDemoMerchant		= false;
-        $trainDemo			= configDict::getConfig('trainDemo');
-        $merchantAccount	= $trainDemo['merchant']['account'];
-        if($merchantAccount == $info['account']){
-        	$isDemoMerchant	= true;
-        }
-        return $this->render('detail',['isDemoMerchant'=>$isDemoMerchant,'merchantStatus'=>$merchantStatus,'merchantStatusName'=>$merchantStatusName,'asset' => $asset,'info' => $info,'status'=> $status,'extend'=>$extend]);
-    }
-
-    /**
-     * 审核等操作
-     */
-    public function actionDeal()
-    {
-    	$get				= Yii::$app->request->get();
-    	$merchantId			= isset($get['id']) ? $get['id'] : 0;
-    	$status				= isset($get['status']) ? $get['status'] : 0;
-    	$merchantStatus		= configDict::getConfig('merchantStatus');
-    	$merchant			= xhMerchantService::getById($merchantId);
-    	$admin				= xhAdminToMerchantService::getAdminByMerchantId($merchantId);
-    	if(empty($admin)){
-    		util::failInfo('此商家没有绑定管理员');
-    	}
-    	switch ($status){
-    		case $merchantStatus['pass']://审核通过
-    			xhMerchantService::pass($admin);
-    			break;
-    		case $merchantStatus['freeze']:
-
-    			break;
-    	}
-    	xhMerchantService::updateById($merchantId, ['status' => $status]);
-    	util::successInfo();
-    }
-
-    public function actionSyncUserInfo()
-    {
-    	set_time_limit(0);
-    	$get				= Yii::$app->request->get();
-    	$nextOpenId			= isset($get['nextOpenId']) ? $get['nextOpenId'] : '';
-    	$merchantId			= isset($get['merchantId']) ? $get['merchantId'] : '';
-    	$merchant			= xhMerchantService::getById($merchantId);
-
-    	$result				= weixinUtil::getSubscribeUserList($merchant,$nextOpenId);
-    	$total				= isset($result['total']) ? $result['total'] : 0;
-    	$next_openid		= isset($result['next_openid']) ? $result['next_openid'] : '';
-    	$count				= isset($result['count']) ? $result['count'] : 0;
-    	$openIdList			= isset($result['data']['openid']) ? $result['data']['openid'] : [];
-    	if($count == 0){
-    		util::successInfo('完成更新','A0001',['next_openid' => '','count' => 0]);
-    	}
-    	$total				= count($openIdList);
-    	$totalPage			= $total > 100 ? ceil($total / 100) : 1;
-    	for($m=1;$m<=$totalPage;$m++){
-    		$offset			= ($m - 1) * 100;
-    		$subIdList		= array_slice($openIdList,$offset,100);
-    		$info			= weixinUtil::batchGetUserInfo($merchant,$subIdList);
-    		if(empty($info) || isset($info['user_info_list']) == false || empty($info['user_info_list'])){
-    			continue;
-    		}
-    		$user_info_list	= $info['user_info_list'];
-    		foreach ($user_info_list as $val){
-    			$openId							= $val['openid'];
-    			$user							= xhUserService::getByOpenId($openId,$merchantId);
-    			if(!empty($user)){
-    				$upData						= [];
-    				$upData['merchantId']		= $merchantId;
-    				$upData['sex']				= isset($val['sex']) ? $val['sex'] : 0;
-    				$upData['subscribe']		= $val['subscribe'];
-    				$upData['subscribeTime']	= $val['subscribe_time'];
-    				$upData['hasSubscribe']	= $val['subscribe'];
-    				if(isset($val['unionid']) && !empty($val['unionid'])){
-    					$upData['unionId']	= $val['unionid'];
-    				}
-    				if(isset($user['id']) == false){
-    					util::failInfo('出错了');
-    				}
-    				xhUserService::updateById($user['id'], $upData);
-    			}
-    		}
-    	}
-    	xhMerchantAssetService::updateByMerchantId($merchantId, ['totalFans'=>$count]);
-    	util::successInfo('获取成功','A0001',['next_openid' => $next_openid,'count' => $count]);
-    }
-
-    /**
-     * 微信门店拉取
-     */
-    public function actionSyncShop()
-    {
-    	$get = Yii::$app->request->get();
-    	$merchantId	= isset($get['merchantId']) ? $get['merchantId'] : 0;
-    	$merchant = xhMerchantService::getById($merchantId);
-        $xhShopService = new xhShopService();
-        $re = $xhShopService->saveShopList($merchant);//查看门店申请数据
-        $mcInfo = xhMerchantService::getById($merchantId);
-        if($re === false){//无门店,自动建门店
-            $re = xhShop::getByCondition(['businessName' => $mcInfo['merchantName']]);
-            if(!$re){
-                $return = $xhShopService->platformInitStore($mcInfo, $merchant);
-                if($return === true){
-                    util::successInfo('系统自动创建门店成功');
-                }
-                util::failInfo($re);
-            }else{
-                util::failInfo('已创建好门店,正在审批中...');
-            }
-        }
-
-        //无申请成功的门店,自动再申请一家
-        //$re = ['total' => $num, 'success' => $successApply, 'applying' => $applying, 'fail' => $faileApply];
-        if($re['success'] == 0 && $re['applying'] == 0){
-            $return = $xhShopService->platformInitStore($mcInfo, $merchant);
-            if(!$return){
-                util::failInfo('暂无门店申请成功,系统自动创建门店失败');
-            }
-            util::successInfo('暂无门店申请成功,系统自动创建门店成功');
-            exit();
-        }
-        $msg = '门店总数:'.$re['total'].'家,' . '申请成功:' . $re['success'] . '家,'.'审批中:' . $re['applying'] . '家,'.'未通过:' . $re['fail'] . '家。';
-        util::successInfo($msg);
-    }
-
-    /**
-     * 同步微信用户标签
-     */
-    public function actionSyncTag()
-    {
-    	set_time_limit(0);
-    	$get			= Yii::$app->request->get();
-    	$merchantId		= isset($get['merchantId']) ? $get['merchantId'] : 0;
-    	$merchant		= xhMerchantService::getById($merchantId);
-    	$allTag			= weixinUtil::getTag($merchant);//取微信里保存的用户标签
-    	if(empty($allTag)){
-    		util::failInfo('没有用户标签信息');
-    	}
-    	$tagList		= $allTag['tags'];
-    	$wxTag			= [];
-    	if(!empty($tagList)){
-    		foreach($tagList as $key => $val){
-    			$wxTag[$val['id']] = $val['name'];
-    		}
-    	}
-    	$reWxTag		= array_flip($wxTag);
-    	$dbTag			= xhUserTagClassService::getMerchantTag($merchantId);
-    	$reDbTag		= array_flip($dbTag);
-    	$delTag			= array_diff($reDbTag,$reWxTag);//删除商家微信里没有的标签
-    	if(!empty($delTag)){
-    		foreach($delTag as $key => $val){
-    			xhUserTagClassService::deleteByCondition(['tagId' => $val,'merchantId' => $merchantId],$merchantId);
-    			$delTagRelation			= xhUserTagService::getAllByCondition(['tagId' => $val,'merchantId' => $merchantId]);
-    			if(!empty($delTagRelation)){
-    				foreach($delTagRelation as $delTagVal){
-    					$userId		= $delTagVal['userId'];
-    					xhUserService::refreshById($userId);
-    					$tId		= $delTagVal['id'];
-    					xhUserTagService::delById($tId);
-    				}
-    			}
-    		}
-    	}
-    	$saveTag		= array_diff($reWxTag,$reDbTag);//保存商家的标签
-    	if(!empty($saveTag)){
-    		foreach($saveTag as $key => $val){
-    			$data	=  ['merchantId' => $merchantId,'tagId' => $val,'name' => $key];
-    			xhUserTagClassService::add($data,$merchantId);
-    		}
-    	}
-    	$updateTag		= array_intersect($reWxTag,$reDbTag);//更新商家的标签
-    	if(!empty($updateTag)){
-    		foreach($updateTag as $key => $val){
-    			xhUserTagClassService::updateByCondition(['merchantId' => $merchantId,'tagId' => $val], ['name' => $key],$merchantId);
-    		}
-    	}
-    	util::successInfo('同步成功');
-    }
-
-    public function actionSyncUserTag()
-    {
-    	set_time_limit(0);
-    	$get				= Yii::$app->request->get();
-    	$merchantId			= isset($get['merchantId']) ? $get['merchantId'] : 0;
-    	$merchant			= xhMerchantService::getById($merchantId);
-    	$tagList			= xhUserTagClassService::getMerchantTag($merchantId);
-    	if(empty($tagList)){
-    		util::failInfo('请先同步商家标签');
-    	}
-    	$wx					= new weixinUtil($merchant);
-    	foreach($tagList as $tagId => $tag){
-    		$nextOpenId		= '';
-    		$this->__updateCategory($wx, $tagId, $nextOpenId,$merchantId);
-    	}
-    	util::successInfo('同步成功');
-    }
-
-    public function __updateCategory($wx,$tagId,$nextOpenId,$merchantId)
-    {
-    	$return			= $wx->getUserTag($tagId,$nextOpenId);
-    	$count			= isset($return['count']) ? $return['count'] : 0;
-    	$nextOpenId		= isset($return['next_openid']) ? $return['next_openid'] : '';
-    	$openIdList		= isset($return['data']['openid']) ? $return['data']['openid'] : [];
-    	if(!empty($openIdList)){
-    		foreach($openIdList as $openId){
-    			$user		= xhUserService::getByOpenId($openId,$merchantId);
-    			if(empty($user)){
-    				continue;
-    			}
-    			$userId		= $user['id'];
-    			$tagData	= ['merchantId'=>$merchantId,'tagId'=>$tagId,'userId'=>$userId];
-    			$userTag	= xhUserTagService::getAllByCondition(['tagId'=>$tagId,'userId'=>$userId]);
-    			if(empty($userTag)){
-    				xhUserTagService::add($tagData);
-    			}
-    		}
-    		if($count > 0){
-    			$this->__updateCategory($wx, $tagId, $nextOpenId,$merchantId);
-    		}
-    	}
-    }
-
-    public function actionFans()
-    {
-    	$get			= Yii::$app->request->get();
-    	$merchantId		= isset($get['merchantId']) ? $get['merchantId'] : 0;
-    	$get			= Yii::$app->request->get();
-    	$query			= xhUser::find();
-    	$query->where(['merchantId' =>$merchantId]);
-    	if(isset($get['content']) && !empty($get['content'])){
-    		$content			= $get['content'];
-    		if(stringUtil::isMobieNumber($content)){
-    			$query->andWhere(['mobile' => $content]);
-    		}else{
-    			$query->andWhere(['like', 'userName', $content]);
-    		}
-    	}
-    	if(isset($get['class']) && $get['class'] == 1){
-    		$query->andWhere(['isMember' => 1]);
-    	}
-    	$countQuery			= clone $query;
-    	$count				= $countQuery->count();
-    	$page				= isset($get['page']) ? $get['page'] : 1;
-    	$pageSize			= 20;
-    	$offset				= ($page - 1) * $pageSize;
-    	$models				= $query->offset($offset)->orderBy('id desc')->limit($pageSize)->asArray()->all();
-    	$page				= new page($count,$page,$pageSize);
-    	$paging 			= $page->fpage();
-    	$auth				= xhMerchantService::isAuth($merchantId);
-    	$merchantTag		= xhUserTagClassService::getMerchantTag($merchantId);
-    	$merchantAsset		= xhMerchantAssetService::getByMerchantId($merchantId);
-    	$merchantExtend		= xhMerchantExtendService::getByMerchantId($merchantId);
-    	$memberIntegral		= xhMerchantExtendService::getGradeList($merchantExtend,'desc');
-    	$merchant			= xhMerchantService::getById($merchantId);
-    	return $this->render('fans', [
-    			'merchantTag' 		=> $merchantTag,
-    			'models' 			=> $models,
-    			'pages' 			=> $paging,
-    			'merchant' 			=> $merchant,
-    			'memberIntegral'	=> $memberIntegral,
-    			'merchantAsset'		=> $merchantAsset,
-    			'merchantExtend'	=> $merchantExtend,
-    			]);
-    	
-    }
-
-    /**
-     * 进行提现操作,全额提现
-     */
-    public function actionDrawCash()
-    {
-    	$connection				= Yii::$app->db;//事务处理
-    	$transaction			= $connection->beginTransaction();
-    	$get					= Yii::$app->request->get();
-    	$merchantId				= isset($get['id']) ? $get['id'] : 0;
-    	$merchantAsset			= xhMerchantAssetService::getByMerchantId($merchantId);
-    	try {
-    		$amount				= $merchantAsset['balance'];
-    		$mBalance			= stringUtil::calcSub($merchantAsset['balance'], $amount);
-    		$date				= date("Y-m-d H:i:s");
-    		$id					= 'D'.stringUtil::buildOrderNo();//订单号
-    		$cashData			= ['amount'=>$amount,'merchantId'=>$merchantId,'balance'=>$mBalance,'addTime'=>time(),'id'=>$id,'createTime'=>$date];
-    		$order				= xhDrawCashService::add($cashData);
-    		$orderId			= $order['id'];
-    		xhMerchantAssetService::updateByMerchantId($merchantId, ['balance'=>$mBalance,'freezeBalance'=>$amount]);
-
-    		$now				= time();
-    		$capitalTypeArray	= configDict::getConfig('capitalType','xhDrawCash');
-    		$capitalType		= $capitalTypeArray['id'];
-    		$mIncome			= $merchantAsset['totalIncome'];
-    		$mExpend			= $merchantAsset['totalExpend'];
-    		$payWay				= configDict::getConfig('payWay','other');
-    		$capitalData		= [
-                'relateId'		=> (string)$orderId,
-                'balance'		=> $mBalance,
-                'totalIncome'	=> $mIncome,
-                'totalExpend'	=> $mExpend,
-                'amount'		=> $amount,
-                'io'			=> 0,
-                'payWay'		=> $payWay,
-                'event'			=> '申请提现',
-                'merchantId'	=> $merchantId,
-                'userId'		=> 0,
-                'userName'		=> '',
-                'alipayId'		=> '',
-                'affectBalance'	=> 1,//会影响商家的余额
-                'createTime'	=> $date,
-                'addTime'		=> $now,
-                'capitalType'	=> $capitalType,
-                'operateId'		=> $this->adminId,
-    		];
-    		xhMerchantCapitalService::add($capitalData);//商家资金流水记录增加
-
-    		$transaction->commit();
-    		util::successInfo();
-    	}catch (Exception $e) {
-    		$transaction->rollBack();
-    		util::failInfo();
-    	}
-    }
-
-    public function actionInit()
-    {
-    	$get				= Yii::$app->request->get();
-    	$merchantId			= isset($get['id']) ? $get['id'] : 0;
-    	$merchant			= xhMerchantService::getById($merchantId);
-    	$extend				= xhMerchantExtendService::getByMerchantId($merchantId);
-    	$gradeList			= xhMerchantExtendService::getGradeList($extend);
-    	$wxPayMerchantId	= '';
-    	$wxPayKey			= '';
-    	$trainDemo			= configDict::getConfig('trainDemo');
-    	if($merchant['id'] == $trainDemo['merchant']['account']){
-    		$wxPayMerchantId	= $trainDemo['merchant']['wxPayMerchantId'];
-    		$wxPayKey			= $trainDemo['merchant']['wxPayKey'];    		
-    	}
-    	if($merchant['id'] == $trainDemo['platform']['account']){
-    		$wxPayMerchantId	= $trainDemo['platform']['wxPayMerchantId'];
-    		$wxPayKey			= $trainDemo['platform']['wxPayKey'];
-    	}
-    	return $this->render('init',['extend' => $extend,'gradeList' => $gradeList,'merchantId'=>$merchantId,'wxPayMerchantId'=>$wxPayMerchantId,'wxPayKey'=>$wxPayKey]);
-    }
-
-    public function actionInitSet()
-    {
-    	$post			= Yii::$app->request->post();
-    	$merchantId		= isset($post['merchantId']) ? $post['merchantId'] : 0;
-    	$extend			= xhMerchantExtendService::getByMerchantId($merchantId);
-    	$merchant		= xhMerchantService::getById($merchantId);
-    	if(empty($extend['wxTMessageInit'])){//开通创建模板消息
-    		xhTMessageService::init($merchant, $extend);
-    	}else{//补充新增加的模板消息
-    		xhTMessageService::supplement($merchant);
-    	}
-    	unset($post['_csrf']);
-    	$post['init']	= 1;//完成初始化
-    	xhMerchantExtendService::updateByMerchantId($merchantId, $post);//上面要先初始化,再执行这边的更新
-    	util::successInfo();
-    }
 
-    public function actionSetAgent()
-    {
-    	$get				= Yii::$app->request->get();
-    	$id					= isset($get['id']) ? $get['id'] : 0;
-    	$data['agentLevel']	= 1;
-    	xhMerchantService::updateById($id, $data);
-    	util::successInfo();
-    }
+	//商家列表 shish 2019.12.20
+	public function actionList()
+	{
+		$where = [];
+		$list = MerchantService::getSaasMerchant($where);
+		util::success($list);
+	}
 
 }

+ 7 - 1
biz/merchant/classes/MerchantClass.php

@@ -7,7 +7,7 @@ use biz\base\classes\BaseClass;
 
 class MerchantClass extends BaseClass
 {
-	
+
 	public static $baseFile = '\biz\merchant\models\Merchant';
 
 	//常用链接
@@ -17,4 +17,10 @@ class MerchantClass extends BaseClass
 		['id' => 2, 'url' => '/mall/index?account=12358', 'sign' => 'mall', 'name' => '点我付款'],
 	];
 
+	//商家信息组合 shish 2019.12.20
+	public static function groupMerchantBaseInfo($list)
+	{
+		return $list;
+	}
+
 }

+ 17 - 1
biz/merchant/services/AdminService.php

@@ -3,6 +3,8 @@
 namespace biz\merchant\services;
 
 use biz\base\services\BaseService;
+use biz\merchant\classes\AdminClass;
+use common\components\business;
 use common\components\error;
 use common\components\stringUtil;
 use common\services\xhTMessageService;
@@ -17,7 +19,7 @@ class AdminService extends BaseService
 	{
 		return 'SID_HT_' . $account . '_' . date("mdHis") . '_' . stringUtil::charsShuffle(18);
 	}
-
+	
 	//发送到手机上 shish 2019.8.11
 	public static function sendUrlToMobile($url, $merchant)
 	{
@@ -33,4 +35,18 @@ class AdminService extends BaseService
 		return true;
 	}
 	
+	//根据管理员id取管理员 shish 2019.12.20
+	public static function getAdminByIds($ids, $order = null, $indexBy = null)
+	{
+		$admin = AdminClass::getByIds($ids, $order, $indexBy);
+		if (empty($admin)) {
+			return $admin;
+		}
+		$imgPrefix = Yii::$app->params['imgUrl'];
+		foreach ($admin as $key => $val) {
+			//$admin[$key]['avatarUrl'] = $imgPrefix . $val['avatar'];
+			business::
+		}
+	}
+	
 }

+ 19 - 1
biz/merchant/services/MerchantService.php

@@ -63,12 +63,30 @@ class MerchantService extends BaseService
 		$merchant['extend'] = $extend;
 		return $merchant;
 	}
-
+	
 	//常用链接 shish 2019.12.19
 	public static function getCommonUrl()
 	{
 		$list = MerchantClass::$commonUrl;
 		return $list;
 	}
+	
+	//取平台下的商家
+	public static function getSaasMerchant($where)
+	{
+		$data = MerchantClass::getList('*', $where, 'addTime DESC');
+		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+		if (empty($list)) {
+			return $data;
+		}
+		$adminIdList = array_column($list, 'adminId');
+		$admin = AdminService::getByIds($adminIdList,null,'id');
+		$merchantIdList = array_column($list, 'merchantId');
+		$asset = MerchantAssetService::getByIds($merchantIdList, null, 'merchantId');
+		foreach ($list as $key => $val) {
+
+		}
+		return $data;
+	}
 
 }

+ 6 - 0
common/components/business.php

@@ -109,6 +109,12 @@ class business
 		$info['imgUrl'] = $middle;
 		return $info;
 	}
+
+	//头像处理 shish 2019.12.20
+	public static function formatAvatar($info)
+	{
+	
+	}
 	
 	//取中图 shish 2019.12.4
 	public static function getMiddleImg($imgUrl)

+ 2 - 0
sql.txt

@@ -1,6 +1,8 @@
 2019.12.19 20:14 商家相关再更新
 ALTER TABLE `xhMerchantAsset` MODIFY `totalOrder` INT NOT NULL DEFAULT 0 COMMENT '订单总数,包括所有的';
 ALTER TABLE `xhMerchantAsset` ADD `payOrder` INT NOT NULL DEFAULT 0 COMMENT '付款订单数' AFTER `totalOrder`;
+ALTER TABLE `xhMerchant` ADD `addTime` INT NOT NULL DEFAULT 0 COMMENT '添加时间' AFTER `status`;
+ALTER TABLE `xhAdmin` ADD `avatar` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '头像' AFTER `adminName`;
 
 2019.12.19 商家资产更新 shish
 ALTER TABLE `xhMerchantAsset` MODIFY `totalOrder` INT NOT NULL DEFAULT 0 COMMENT '订单数;已付款订单数';