status == 0) { return false; } $userId = $order['userId']; $hasRight = self::getByCondition(['userId' => $userId, 'modelId' => $id]); //已经有这个权利不再进行发放 if ($hasRight) { return false; } $orderId = $order['id']; $sjId = $order['sjId']; $time = time(); $data = ['userId' => $userId, 'modelId' => $id, 'orderId' => $orderId, 'sjId' => $sjId, 'type' => $theRight['type'], 'targetId' => $theRight['targetId'], 'amount' => $theRight['amount'], 'meetAmount' => $theRight['meetAmount'], 'addTime' => $time]; self::add($data); $modelInfo->rightNum += 1; $modelInfo->save(); //消息通知 $allTM = xhTMessageService::getList($sjId); $user = UserService::getById($userId); if ($user['subscribe'] == 1) { $shortTempId = 'OPENTM207422813';//收入提醒 if (isset($allTM[$shortTempId])) { $tempId = $allTM[$shortTempId]; $openId = $user['openId']; $data = ["touser" => $openId, "template_id" => $tempId, "url" => Yii::$app->params['mobileUrl'] . '/center/my-right?account=' . $merchant['id'], "data" => [ "first" => ["value" => '您获得一张老带新优惠卷', "color" => "#173177"], "keyword1" => ["value" => '点击查看', "color" => "#173177"], "keyword2" => ["value" => '老带新活动', "color" => "#173177"], "keyword3" => ["value" => date("Y-m-d H:i"), "color" => "#173177"], "remark" => ["value" => "点击查看明细", "color" => "#173177"]]]; wxUtil::sendTaskInform($data, $merchant); } } } //分享出去之后领取优惠卷 ssh public static function gainCoupon($data,$userId) { validate::easyCheck(['rightId'], $data); $rightId = $data['rightId']; $right = self::getById($rightId); if (empty($right)) { util::fail('没有找到优惠卷'); } if ($right['userId'] == $userId) { util::fail('不能领自己发的卷'); } $sjId = $right['sjId']; $modelId = $right['modelId']; $model = CouponModelService::getById($modelId); if (empty($model)) { util::fail('没有找到优惠卷!'); } if ($model['delStatus'] == 1) { util::fail('优惠卷已经删除!'); } if ($model['status'] == 0) { util::fail('优惠卷已经停止领取'); } $isNew = UserAssetService::isNewCustomer($userId); if ($isNew == false) { util::fail('新客才能领取哦'); } $has = CouponService::hasGained(); if ($has) { util::fail('您已经领取过优惠卷了'); } $userInfo = UserService::getById($userId); $mobile = isset($userInfo['mobile']) ? $userInfo['mobile'] : ''; $data = []; $time = time(); $date = date("Y-m-d H:i:s"); $data['deadline'] = empty($model['validTime']) ? 4294967295 : ($time + $model['validTime'] * 86400); $data['name'] = $model['name']; $data['amount'] = $model['amount']; $data['meetAmount'] = $model['meetAmount']; $data['userId'] = $userId; $data['introUserId'] = $right['userId']; $data['sjId'] = $model['sjId']; $data['reward'] = $model['reward']; $data['type'] = $model['type']; $data['targetId'] = $model['targetId']; $data['beginTime'] = $time; $data['orderId'] = 0; $data['addTime'] = $time; $data['mobile'] = $mobile; $data['createTime'] = $date; $data['rightId'] = $rightId; $data['modelId'] = $modelId; CouponService::add($data); //领卷数+1 $getNum = $model['getNum'] + 1; CouponModelService::updateById($modelId, ['getNum' => $getNum]); $merchant = MerchantService::getById($sjId); //通知领卷人 if (isset($userInfo['subscribe']) && !empty($userInfo['subscribe'])) { $openId = $userInfo['openId']; $allTM = xhTMessageService::getList($sjId); $shortTempId = 'OPENTM207430125'; if (isset($allTM[$shortTempId])) { $tempId = $allTM[$shortTempId]; $url = Yii::$app->params['mobileUrl'] . '/center/my-coupon?account=' . $sjId; $data = [ "touser" => $openId, "template_id" => $tempId, "url" => $url, "data" => ["first" => ["value" => '恭喜您', "color" => "#173177"], "keyword1" => ["value" => "领卷成功,点此查看。", "color" => "#173177"], "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"], "remark" => ["value" => "", "color" => "#173177"]]]; wxUtil::sendTaskInform($data, $merchant); } } //通知发卷人 $introduceUserId = $right['userId']; $introduceUserInfo = UserService::getById($introduceUserId); if (isset($introduceUserInfo['subscribe']) && !empty($introduceUserInfo['subscribe'])) { $openId = $introduceUserInfo['openId']; $allTM = xhTMessageService::getList($sjId); $shortTempId = 'OPENTM207430125'; if (isset($allTM[$shortTempId])) { $tempId = $allTM[$shortTempId]; $url = Yii::$app->params['mobileUrl'] . '/center/get-coupon?account=' . $sjId; $data = [ "touser" => $openId, "template_id" => $tempId, "url" => $url, "data" => ["first" => ["value" => '恭喜您', "color" => "#173177"], "keyword1" => ["value" => "您的伙伴【{$userInfo['userName']}】已经领取您的优惠券。", "color" => "#173177"], "keyword2" => ["value" => date("Y-m-d H:i"), "color" => "#173177"], "remark" => ["value" => "点此查看", "color" => "#173177"]]]; wxUtil::sendTaskInform($data, $merchant); } } return true; } }