|
|
@@ -13,67 +13,78 @@ 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'];
|
|
|
- $merchantId = $merchant['id'];
|
|
|
- $asset = self::getByCondition(['merchantId' => $merchantId]);
|
|
|
- $time = time();
|
|
|
- $date = date("Y-m-d H:i:s");
|
|
|
|
|
|
- //商家开启注册会员送券
|
|
|
- if (isset($asset['switch']) && $asset['switch'] == 1) {
|
|
|
- //客户没有消费过 且没有领过优惠券 且登陆了手机号 且关注了公众号
|
|
|
- if ($userAsset['getCouponNum'] == 0 && $userAsset['totalBuyNum'] == 0 && !empty($user['mobile'])) {
|
|
|
- $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) {
|
|
|
- $tm = xhTMessageService::getList($merchantId);
|
|
|
- $shortTempId = 'OPENTM207422813';//收入提醒
|
|
|
- $tempId = isset($tm[$shortTempId]) ? $tm[$shortTempId] : '';
|
|
|
- $openId = isset($user['openId']) ? $user['openId'] : '';
|
|
|
- $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
|
|
|
- if (!empty($tempId) && !empty($openId)) {
|
|
|
- $data = [
|
|
|
- "touser" => $openId,
|
|
|
- "template_id" => $tempId,
|
|
|
- "url" => Yii::$app->params['mallDomain'] . '/#/pages/coupon/list?account=' . $merchantId,
|
|
|
- "data" => [
|
|
|
- "first" => ["value" => "恭喜,您获得一张优惠劵。", "color" => "#173177"],
|
|
|
- "keyword1" => ["value" => $amount . '元', "color" => "#173177"],
|
|
|
- "keyword2" => ["value" => '优惠劵', "color" => "#173177"],
|
|
|
- "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
|
|
|
- "remark" => ["value" => "点击查看详情", "color" => "#173177"]
|
|
|
- ]
|
|
|
- ];
|
|
|
- if (!empty($miniOpenId)) {
|
|
|
- $data['miniprogram']['appid'] = $merchant['miniAppId'];
|
|
|
- $data['miniprogram']['pagepath'] = 'pages/coupon/list';
|
|
|
- }
|
|
|
- wxUtil::sendTaskInform($data, $merchant);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ public static $baseFile = '\biz\coupon\models\CouponAsset';
|
|
|
+
|
|
|
+ //新人注册获取优惠券 shish 2020.5.5
|
|
|
+ public static function giveCoupon($user, $merchant, $userAsset)
|
|
|
+ {
|
|
|
+ $userId = $user['id'];
|
|
|
+ $merchantId = $merchant['id'];
|
|
|
+ $asset = self::getByCondition(['merchantId' => $merchantId]);
|
|
|
+ $time = time();
|
|
|
+ $date = date("Y-m-d H:i:s");
|
|
|
+
|
|
|
+ //商家开启注册会员送券
|
|
|
+ if (isset($asset['switch']) && $asset['switch'] == 1) {
|
|
|
+ //客户没有消费过 且没有领过优惠券 且登陆了手机号 且关注了公众号
|
|
|
+ if ($userAsset['getCouponNum'] == 0 && $userAsset['totalBuyNum'] == 0 && !empty($user['mobile'])) {
|
|
|
+ $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) {
|
|
|
+ self::wxNotice($user, $merchant);
|
|
|
+ } else {
|
|
|
+ //还未关注公众号的等关注公众号之后通知
|
|
|
+ $key = 'get_a_new_coupon_to_notice_' . $userId;
|
|
|
+ Yii::$app->redis->executeCommand('SET', [$key, 'yes']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //获得新优惠券通知 shish 2020.5.29
|
|
|
+ public static function wxNotice($user, $merchant)
|
|
|
+ {
|
|
|
+ $merchantId = $merchant['id'];
|
|
|
+ $tm = xhTMessageService::getList($merchantId);
|
|
|
+ $shortTempId = 'OPENTM207422813';//收入提醒
|
|
|
+ $tempId = isset($tm[$shortTempId]) ? $tm[$shortTempId] : '';
|
|
|
+ $openId = isset($user['openId']) ? $user['openId'] : '';
|
|
|
+ $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
|
|
|
+ if (!empty($tempId) && !empty($openId)) {
|
|
|
+ $data = [
|
|
|
+ "touser" => $openId,
|
|
|
+ "template_id" => $tempId,
|
|
|
+ "url" => Yii::$app->params['mallDomain'] . '/#/pages/coupon/list?account=' . $merchantId,
|
|
|
+ "data" => [
|
|
|
+ "first" => ["value" => "恭喜,您获得一张优惠劵。", "color" => "#173177"],
|
|
|
+ "keyword1" => ["value" => $amount . '元', "color" => "#173177"],
|
|
|
+ "keyword2" => ["value" => '优惠劵', "color" => "#173177"],
|
|
|
+ "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"],
|
|
|
+ "remark" => ["value" => "点击查看详情", "color" => "#173177"]
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ if (!empty($miniOpenId)) {
|
|
|
+ $data['miniprogram']['appid'] = $merchant['miniAppId'];
|
|
|
+ $data['miniprogram']['pagepath'] = 'pages/coupon/list';
|
|
|
+ }
|
|
|
+ wxUtil::sendTaskInform($data, $merchant);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|