| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace bizHd\wx\services;
- use bizHd\base\services\BaseService;
- use biz\sj\services\MerchantService;
- use bizHd\promote\services\CouponService;
- use common\components\util;
- use common\services\xhTMessageService;
- use Yii;
- use linslin\yii2\curl;
- use common\components\stringUtil;
- use common\components\wxUtil;
- class WxSceneService extends BaseService
- {
-
- public static $baseFile = '\bizHd\wx\classes\WxSceneClass';
-
- //生成刮刮卡的场景id ssh 2019.9.5
- public static function generateGuaGuaScene($id, $sjId)
- {
- $merchant = MerchantService::getById($sjId);
- $time = time();
- $sceneId = stringUtil::generateSceneId($sjId);
- $type = 0;
- $data = ['targetId' => $id, 'sceneId' => $sceneId, 'addTime' => $time, 'type' => $type, 'sjId' => $sjId];
- //过期时间默认30天,即2592000
- $respond = wxUtil::qrcodeCreate($merchant, $sceneId, 2592000);
- $url = isset($respond['url']) ? $respond['url'] : '';
- if (empty($url)) {
- util::fail('没有生成微信场景二维码');
- }
- self::add($data);
- return $url;
- }
-
- //生成支付成功领卷的场景 ssh 2019.9.17
- public static function generatePayGetCouponScene($userId,$sjId,$merchant)
- {
- $time = time();
- $sceneId = stringUtil::generateSceneId($sjId);
- $type = 1;
- $data = ['targetId' => $userId, 'sceneId' => $sceneId, 'addTime' => $time, 'type' => $type, 'sjId' => $sjId];
- //过期时间默认30天,即2592000
- $respond = wxUtil::qrcodeCreate($merchant, $sceneId, 2592000);
- $url = isset($respond['url']) ? $respond['url'] : '';
- if (empty($url)) {
- util::fail('没有生成微信场景二维码');
- }
- self::add($data);
- return $url;
- }
-
- //响应扫码场景事件 ssh 2019.9.5
- public static function respondScanEvent($merchant, $user, $sceneId)
- {
- $sjId = $merchant['id'];
- $info = self::getByCondition(['sjId' => $sjId, 'sceneId' => (string)$sceneId], true);
- if (empty($info)) {
- Yii::info('sjId:' . $sjId . ' sceneId:' . $sceneId . '没有找到场景信息');
- return false;
- }
- //刮刮卡
- if ($info->type == 0) {
- $targetId = $info->targetId;
- $openId = $user['openId'];
- $allTM = xhTMessageService::getList($sjId);
- $shortTempId = 'OPENTM207430125';
- if (isset($allTM[$shortTempId])) {
- $tempId = $allTM[$shortTempId];
- $url = Yii::$app->params['mobileUrl'] . '/gua/index?account=' . $sjId . '&id=' . $targetId;
- $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);
- }
- } elseif ($info->type == 1) {
- if ($info->status == 1) {
- return false;
- }
- CouponService::paySuccessGetCoupon($userId,$sjId);
- $info->status = 1;
- $info->save();
- } else {
-
- }
- }
-
- }
|