Przeglądaj źródła

新人注册优惠券

shish 6 lat temu
rodzic
commit
6944588228

+ 1 - 1
app/mall/controllers/UserController.php

@@ -159,7 +159,7 @@ class UserController extends BaseController
 		UserService::becomeVip($userId, $this->merchantId, $update);
 		util::complete('注册成功');
 	}
-
+	
 	//用户基本信息和资产 shish 2019.12.19
 	public function actionMyProfile()
 	{

Plik diff jest za duży
+ 512 - 511
app/saas/controllers/WxController.php


+ 53 - 2
biz/coupon/classes/CouponAssetClass.php

@@ -6,12 +6,63 @@ use biz\goods\services\GoodsCategoryService;
 use biz\goods\services\GoodsStyleService;
 use common\components\business;
 use common\components\stringUtil;
+use common\services\xhTMessageService;
 use Yii;
 use biz\base\classes\BaseClass;
 
 class CouponAssetClass extends BaseClass
 {
-
+	
 	public static $baseFile = '\biz\coupon\models\CouponAsset';
-
+	
+	//新人注册获取优惠券 shish 2020.5.5
+	public static function giveCoupon($user, $merchant, $userAsset)
+	{
+		$userId = $user['id'];
+		$asset = self::getByCondition(['merchantId' => $merchantId]);
+		$time = time();
+		$merchantId = $merchant['id'];
+		$date = date("Y-m-d H:i:s");
+		//商家开启注册会员送券
+		if (isset($asset['switch']) && $asset['switch'] == 1) {
+			//客户没有消费过且没有领过优惠券
+			if ($userAsset['getCouponNum'] == 0 && $userAsset['totalBuyNum'] == 0) {
+				$duration = $asset['duration'];
+				$deadline = $time + $duration * 86400;
+				$amount = $asset['amount'];
+				$mobile = isset($user['mobile']) ? $user['mobile'] : '';
+				$addData['userId'] = $userId;
+				$addData['merchantId'] = $merchantId;
+				$addData['mobile'] = $mobile;
+				$addData['name'] = '新人优惠券';
+				$addData['miniCost'] = $asset['miniCost'];
+				$addData['amount'] = $amount;
+				$addData['beginTime'] = $time;
+				$addData['deadline'] = $deadline;
+				$addData['source'] = 0;
+				$addData['status'] = 0;
+				$addData['addTime'] = $time;
+				$addData['createTime'] = $date;
+				CouponClass::add($addData);
+				if (isset($user['subscribe']) && $user['subscribe'] == 1) {
+					$allTM = xhTMessageService::getList($merchantId);
+					$shortTempId = 'OPENTM207422813';//收入提醒
+					$tempId = $allTM[$shortTempId];
+					$openId = $user['openId'];
+					$data = [
+						"touser" => $openId,
+						"template_id" => $tempId,
+						"url" => Yii::$app->params['mallDomain'] . '/center/coupon?account=' . $merchantId,
+						"data" => [
+							"first" => ["value" => "送您一张代金劵。", "color" => "#173177"],
+							"keyword1" => ["value" => '代金劵', "color" => "#173177"],
+							"keyword2" => ["value" => $amount . '元', "color" => "#173177"],
+							"keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
+							"remark" => ["value" => "点击查看详情", "color" => "#173177"]]];
+					wxUtil::sendTaskInform($data, $merchant);
+				}
+			}
+		}
+	}
+	
 }

+ 223 - 211
biz/user/services/UserService.php

@@ -3,10 +3,12 @@
 namespace biz\user\services;
 
 use biz\base\services\BaseService;
+use biz\coupon\classes\CouponAssetClass;
 use biz\merchant\classes\MerchantAssetClass;
 use biz\merchant\services\MerchantAssetService;
 use biz\merchant\services\MerchantExtendService;
 use biz\order\services\OrderService;
+use biz\user\classes\UserAssetClass;
 use biz\user\classes\UserClass;
 use common\components\util;
 use common\components\validate;
@@ -18,215 +20,225 @@ use common\components\wxUtil;
 
 class UserService extends BaseService
 {
-
-    public static $baseFile = '\biz\user\classes\UserClass';
-
-    //获取客户列表 shish 2019.11.30
-    public static function getUserList($where, $delStatus = 0)
-    {
-        //默认取没有删除的用户
-        $where['delStatus'] = $delStatus;
-        $data = UserClass::getList('*', $where, 'visitTime DESC');
-        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
-        if (empty($list)) {
-            return $data;
-        }
-        $data['list'] = UserClass::groupUserBaseInfo($list);
-        return $data;
-    }
-
-    //获取客户基本和资产信息 shish 2019.11.30
-    public static function getUserInfo($id, $sensitive = true)
-    {
-        return UserClass::getUserInfo($id, $sensitive);
-    }
-
-    //获取客户基本、资产和订单信息 shish 2019.11.30
-    public static function getFullUserInfo($id)
-    {
-        $userInfo = UserClass::getUserInfo($id);
-        $order = OrderService::getUserOrder($id, 10, 'addTime desc');
-        $userInfo['orderList'] = $order;
-        return $userInfo;
-    }
-
-    //根据手机号查询客户 shish 2019.12.1
-    public static function getByMobile($mobile, $merchantId)
-    {
-        return UserClass::getByMobile($mobile, $merchantId);
-    }
-
-    //添加更新客户 shish 2020.2.7
-    public static function replaceUser($userInfo, $source, $merchantId)
-    {
-        return UserClass::replaceUser($userInfo, $source, $merchantId);
-    }
-
-    public static function getByOpenId($openId, $merchantId)
-    {
-        return UserClass::getByOpenId($openId, $merchantId);
-    }
-
-    public static function getByMiniOpenId($miniOpenId, $merchantId)
-    {
-        return UserClass::getByMiniOpenId($miniOpenId, $merchantId);
-    }
-
-    //同步微信用户 shish 2020.2.8
-    public static function syncWxAllUser($merchantId)
-    {
-        $return = UserClass::syncWxUser($merchantId);
-        while (isset($return['count']) && $return['count'] > 0 && isset($return['nextOpenId']) && !empty($return['nextOpenId'])) {
-            $nextOpenId = $return['nextOpenId'];
-            $return = UserClass::syncWxUser($merchantId, $nextOpenId);
-        }
-        return ['total' => $return['total']];
-    }
-
-    //更新微信头像 shish 2020.1.12
-    public static function syncAvatar($merchantId, $nextOpenId = '')
-    {
-        set_time_limit(0);
-        $merchant = xhMerchantService::getById($merchantId);
-        //一次拉取调用最多拉取10000个关注者的OpenID
-        $result = wxUtil::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::stop("完成更新\n");
-        }
-        $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 = wxUtil::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) {
-                $headImgUrl = $val['headimgurl'];
-                $openId = $val['openid'];
-                $img = ImageService::generateAvatar($merchantId, $headImgUrl);
-                if (!empty($img)) {
-                    UserClass::updateByCondition(['openId' => $openId], ['avatar' => $img]);
-                }
-            }
-        }
-        echo "更新成功\n";
-    }
-
-    /**
-     * 更新用户的访问时间
-     */
-    public static function updateVisitTime($merchantId, $userId)
-    {
-        $date = date("Ymd");
-        if (empty($userId)) {
-            return false;
-        }
-        //每5分钟更新一次访问时间
-        $key = 'UserVisitTime_' . $date . '_' . $merchantId . '_' . $userId;
-        $respond = Yii::$app->redis->executeCommand('GET', [$key]);
-        //每过5分钟更新访问时间
-        if (empty($respond)) {
-            Yii::$app->redis->executeCommand('SET', [$key, $date]);
-            Yii::$app->redis->executeCommand('EXPIRE', [$key, 300]);
-            $time = time();
-            self::updateById($userId, ['visitTime' => $time]);
-        }
-    }
-
-    //注册成为会员,并更新用户相关信息 shish 2019.9.7
-    public static function becomeVip($userId, $merchantId, $data)
-    {
-        self::updateById($userId, $data);
-        //会员数+1
-        MerchantAssetService::addMemberNum($merchantId);
-    }
-
-    //取消关注 shish 2019.9.8
-    public static function unFocus($userId, $merchantId)
-    {
-        self::updateById($userId, ['subscribe' => 0, 'hasSubscribe' => 1]);
-        //商家粉丝减少
-        MerchantAssetClass::reduceFans($merchantId);
-    }
-
-    //批量获取用户信息,图片等信息处理好了 shish 2019.11.28
-    public static function getUserByIds($ids)
-    {
-        return UserClass::getUserByIds($ids);
-    }
-
-    //验证支付密码是否正确 shish 2019.12.6
-    public static function validPayPassword($password, $user)
-    {
-        if (isset($user['hasPayPwd']) == false || $user['hasPayPwd'] == 0) {
-            util::fail('您还没有设置支付密码');
-        }
-        $payPassword = $user['payPassword'];
-        if (password_verify($password, $payPassword) == false) {
-            util::fail('密码错误');
-        }
-    }
-
-    //验证用户权限
-    public static function valid($info, $merchantId)
-    {
-        return UserClass::valid($info, $merchantId);
-    }
-
-    //根据消费次数和有没领优惠券来判断是不是新人
-    public static function newUser($userInfo)
-    {
-        return UserClass::newUser($userInfo);
-    }
-
-    //添加新客户 shish 2020.1.10
-    public static function addUser($data)
-    {
-        //merchantId $source $realName $member $growth $balance $mobile
-        //必传参数
-        validate::easyCheck(['merchantId', 'mobile'], $data);
-
-        $merchantId = $data['merchantId'];
-        $source = isset($data['source']) ? $data['source'] : 'official';
-        $mobile = $data['mobile'];
-        $realName = isset($data['realName']) ? $data['realName'] : $mobile;
-        $member = isset($data['member']) ? $data['member'] : -1;
-        $balance = isset($data['balance']) ? $data['balance'] : 0;
-        $growth = isset($data['growth']) ? $data['growth'] : 0;
-
-        $originalInfo = [];
-        $originalInfo['merchantId'] = $merchantId;
-        $originalInfo['mobile'] = $mobile;
-        $originalInfo['realName'] = $realName;
-        $originalInfo['userName'] = $realName;
-
-        $user = UserClass::replaceUser($originalInfo, $source, $merchantId);
-
-        $extend = MerchantExtendService::getByMerchantId($merchantId);
-
-        //等级
-        if ($member > 0) {
-            $gradeList = xhMerchantExtendService::getGradeList($extend, 'desc');
-            $growth = isset($gradeList[$member]['growth']) ? $gradeList[$member]['growth'] : 0;
-        }
-
-        //余额成长值更新
-        $userId = $user['id'];
-        $data = [];
-        $data['growth'] = $growth;
-        $data['balance'] = $balance > 0 ? $balance : 0;
-        UserAssetService::updateByUserId($userId, $data);
-
-        //会员升级
-        UserIntegralService::increaseToUpgrade(0, $growth, 0, $userId, $merchantId, $extend);
-        return $user;
-    }
-
+	
+	public static $baseFile = '\biz\user\classes\UserClass';
+	
+	//获取客户列表 shish 2019.11.30
+	public static function getUserList($where, $delStatus = 0)
+	{
+		//默认取没有删除的用户
+		$where['delStatus'] = $delStatus;
+		$data = UserClass::getList('*', $where, 'visitTime DESC');
+		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+		if (empty($list)) {
+			return $data;
+		}
+		$data['list'] = UserClass::groupUserBaseInfo($list);
+		return $data;
+	}
+	
+	//获取客户基本和资产信息 shish 2019.11.30
+	public static function getUserInfo($id, $sensitive = true)
+	{
+		return UserClass::getUserInfo($id, $sensitive);
+	}
+	
+	//获取客户基本、资产和订单信息 shish 2019.11.30
+	public static function getFullUserInfo($id)
+	{
+		$userInfo = UserClass::getUserInfo($id);
+		$order = OrderService::getUserOrder($id, 10, 'addTime desc');
+		$userInfo['orderList'] = $order;
+		return $userInfo;
+	}
+	
+	//根据手机号查询客户 shish 2019.12.1
+	public static function getByMobile($mobile, $merchantId)
+	{
+		return UserClass::getByMobile($mobile, $merchantId);
+	}
+	
+	//添加更新客户 shish 2020.2.7
+	public static function replaceUser($userInfo, $source, $merchantId)
+	{
+		return UserClass::replaceUser($userInfo, $source, $merchantId);
+	}
+	
+	public static function getByOpenId($openId, $merchantId)
+	{
+		return UserClass::getByOpenId($openId, $merchantId);
+	}
+	
+	public static function getByMiniOpenId($miniOpenId, $merchantId)
+	{
+		return UserClass::getByMiniOpenId($miniOpenId, $merchantId);
+	}
+	
+	//同步微信用户 shish 2020.2.8
+	public static function syncWxAllUser($merchantId)
+	{
+		$return = UserClass::syncWxUser($merchantId);
+		while (isset($return['count']) && $return['count'] > 0 && isset($return['nextOpenId']) && !empty($return['nextOpenId'])) {
+			$nextOpenId = $return['nextOpenId'];
+			$return = UserClass::syncWxUser($merchantId, $nextOpenId);
+		}
+		return ['total' => $return['total']];
+	}
+	
+	//更新微信头像 shish 2020.1.12
+	public static function syncAvatar($merchantId, $nextOpenId = '')
+	{
+		set_time_limit(0);
+		$merchant = xhMerchantService::getById($merchantId);
+		//一次拉取调用最多拉取10000个关注者的OpenID
+		$result = wxUtil::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::stop("完成更新\n");
+		}
+		$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 = wxUtil::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) {
+				$headImgUrl = $val['headimgurl'];
+				$openId = $val['openid'];
+				$img = ImageService::generateAvatar($merchantId, $headImgUrl);
+				if (!empty($img)) {
+					UserClass::updateByCondition(['openId' => $openId], ['avatar' => $img]);
+				}
+			}
+		}
+		echo "更新成功\n";
+	}
+	
+	/**
+	 * 更新用户的访问时间
+	 */
+	public static function updateVisitTime($merchantId, $userId)
+	{
+		$date = date("Ymd");
+		if (empty($userId)) {
+			return false;
+		}
+		//每5分钟更新一次访问时间
+		$key = 'UserVisitTime_' . $date . '_' . $merchantId . '_' . $userId;
+		$respond = Yii::$app->redis->executeCommand('GET', [$key]);
+		//每过5分钟更新访问时间
+		if (empty($respond)) {
+			Yii::$app->redis->executeCommand('SET', [$key, $date]);
+			Yii::$app->redis->executeCommand('EXPIRE', [$key, 300]);
+			$time = time();
+			self::updateById($userId, ['visitTime' => $time]);
+		}
+	}
+	
+	//注册成为会员,并更新用户相关信息 shish 2019.9.7
+	public static function becomeVip($userId, $merchantId, $data)
+	{
+		$data['member'] = 0;
+		self::updateById($userId, $data);
+		UserAssetClass::updateByCondition(['userId' => $userId, ['member' => 0]]);
+		MerchantAssetService::addMemberNum($merchantId);
+	}
+	
+	//取消关注 shish 2019.9.8
+	public static function unFocus($userId, $merchantId)
+	{
+		self::updateById($userId, ['subscribe' => 0, 'hasSubscribe' => 1]);
+		//商家粉丝减少
+		MerchantAssetClass::reduceFans($merchantId);
+	}
+	
+	//关注公众号的后续 shish 2020.5.5
+	public static function focus($user, $merchant)
+	{
+		$userId = $user['id'];
+		UserClass::updateById($userId, ['subscribe' => 1]);
+		$userAsset = UserAssetClass::getByUserId($userId);
+		CouponAssetClass::giveCoupon($user, $merchant, $userAsset);
+	}
+	
+	//批量获取用户信息,图片等信息处理好了 shish 2019.11.28
+	public static function getUserByIds($ids)
+	{
+		return UserClass::getUserByIds($ids);
+	}
+	
+	//验证支付密码是否正确 shish 2019.12.6
+	public static function validPayPassword($password, $user)
+	{
+		if (isset($user['hasPayPwd']) == false || $user['hasPayPwd'] == 0) {
+			util::fail('您还没有设置支付密码');
+		}
+		$payPassword = $user['payPassword'];
+		if (password_verify($password, $payPassword) == false) {
+			util::fail('密码错误');
+		}
+	}
+	
+	//验证用户权限
+	public static function valid($info, $merchantId)
+	{
+		return UserClass::valid($info, $merchantId);
+	}
+	
+	//根据消费次数和有没领优惠券来判断是不是新人
+	public static function newUser($userInfo)
+	{
+		return UserClass::newUser($userInfo);
+	}
+	
+	//添加新客户 shish 2020.1.10
+	public static function addUser($data)
+	{
+		//merchantId $source $realName $member $growth $balance $mobile
+		//必传参数
+		validate::easyCheck(['merchantId', 'mobile'], $data);
+		
+		$merchantId = $data['merchantId'];
+		$source = isset($data['source']) ? $data['source'] : 'official';
+		$mobile = $data['mobile'];
+		$realName = isset($data['realName']) ? $data['realName'] : $mobile;
+		$member = isset($data['member']) ? $data['member'] : -1;
+		$balance = isset($data['balance']) ? $data['balance'] : 0;
+		$growth = isset($data['growth']) ? $data['growth'] : 0;
+		
+		$originalInfo = [];
+		$originalInfo['merchantId'] = $merchantId;
+		$originalInfo['mobile'] = $mobile;
+		$originalInfo['realName'] = $realName;
+		$originalInfo['userName'] = $realName;
+		
+		$user = UserClass::replaceUser($originalInfo, $source, $merchantId);
+		
+		$extend = MerchantExtendService::getByMerchantId($merchantId);
+		
+		//等级
+		if ($member > 0) {
+			$gradeList = xhMerchantExtendService::getGradeList($extend, 'desc');
+			$growth = isset($gradeList[$member]['growth']) ? $gradeList[$member]['growth'] : 0;
+		}
+		
+		//余额成长值更新
+		$userId = $user['id'];
+		$data = [];
+		$data['growth'] = $growth;
+		$data['balance'] = $balance > 0 ? $balance : 0;
+		UserAssetService::updateByUserId($userId, $data);
+		
+		//会员升级
+		UserIntegralService::increaseToUpgrade(0, $growth, 0, $userId, $merchantId, $extend);
+		return $user;
+	}
+	
 }

+ 1 - 3
common/services/xhCouponService.php

@@ -126,9 +126,7 @@ class xhCouponService {
 		self::refreshUserCoupon($userId);
 	}
 
-	/**
-	 * 关注公众号,赠送代金劵
-	 */
+	//关注公众号时,判断商家是否开启新客注册送券,并且客户提供了手机号,是则送券 shish 2020.5.5
 	public static function focusGiveCoupon($userId,$merchant,$merchantExtend)
 	{
 		$giveCouponPrice			= $merchantExtend['giveCouponPrice'];//代金劵金额

+ 3 - 0
console/controllers/UpgradeController.php

@@ -1417,6 +1417,9 @@ ALTER TABLE `xhApply` CHANGE `userId` `adminId` INT NOT NULL DEFAULT 0 COMMENT '
 		$sql = "ALTER TABLE `xhMerchantExtend` MODIFY `alipayKey` VARCHAR(5000) NOT NULL DEFAULT '' COMMENT '商户密钥';
 ALTER TABLE `xhMerchantExtend` MODIFY `alipayPublicKey` VARCHAR(5000) NOT NULL DEFAULT '' COMMENT '支付宝公钥';";
 		Yii::$app->db->createCommand($sql)->execute($sql);
+
+		$sql = "ALTER TABLE `xhCouponAsset` MODIFY `switch` TINYINT NOT NULL DEFAULT 1 COMMENT '新客注册会员送券 1开启 0关闭';";
+		Yii::$app->db->createCommand($sql)->execute($sql);
 	}
 
 	//数据迁移 shish 2020.1.12

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików