Userhelp.php 4.85 KB
<?php
/**
 * tpshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * 2015-11-21
 */

namespace app\mobile\controller;

use app\home\logic\UsersLogic;
use app\home\model\Message;
use think\Cookie;
use think\Page;
use think\Request;
use think\Session;
use think\Verify;
use think\db;
use think\Cache;
use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;


class Userhelp extends MobileBase
{

    public $user_id = 0;
    public $user = array();

    /*
    * 初始化操作
    */
    public function _initialize()
    {
        parent::_initialize();
        $sid = I('stoid');
        if (session('?user')) {
            $user = session('user');
            unset($_SESSION['user']);
            $user0 = M('users')->where("user_id", $user['user_id'])->where("store_id", $sid)->find();

            session('user', $user0);  //覆盖session 中的 user
            $this->user = $user0;
            $this->user_id = $user0['user_id'];
            $this->assign('user', $user0); //存储用户信息
        } else {
            $usrid = Cookie::get('user_id');
            if ($usrid) {
                $user0 = M('users')->where("user_id", $usrid)->where("store_id", $sid)->find();
                session('user', $user0);  //覆盖session 中的 user
                $this->user = $user0;
                $this->user_id = $user0['user_id'];
                $this->assign('user', $user0); //存储用户信息
            }
        }
    }


    /**-- 助力分享跳转到手店商城--**/
    public function index()
    {
        $stoid = getMobileStoId();
        $fid=I("fid");
        $act=M("marketing_help_form")->where("id",$fid)->find();
        if($act){
            //--判断是不是需要关注--
            if(strpos($act['help_condition'],'1')!==false){
                $gz=M("wx_openlist")->where("wxopenid",$this->user['openid'])->find();
                if($gz && !$gz['issubscribe']){
                     $this->assign("need_gz",1);
                }
            }
            //--判断是不是需要注册--
            if(strpos($act['help_condition'],'2')!==false){
                 if(!$this->user['erpvipid']){
                     $this->assign("need_zc",1);
                 }
            }

        }else{
            $this->error("未找到助力活动","/index.php/mobile/index/index/stoid/".$stoid);
        }
        return $this->fetch('', $stoid);
    }

    public function create_ewm()
    {
        $stoid = getMobileStoId();
        $weixin_config = M('wx_user')->where('store_id=' . getMobileStoId())->field("appid,appsecret")->find(); //获取微信配置
        if (empty($weixin_config)) {
            return json(['code' => -1]);
        }
        $access_token = m_get_access_token($weixin_config);
        mlog('关注开始2:', 'create_ewm/' . $stoid);
        $url = "";
        $return = M('wx_ewmlist')->where(array('store_id' => $stoid, 'scene_id' => ''))->find();
        if (empty($return)) {
            if ($access_token) {
                //获取数据的地址(微信提供)
                $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" . $access_token;
                //发送给微信服务器的数据
                $jsonstr = '{"expire_seconds": 1800, "action_name": "QR_LIMIT_SCENE", "action_info": {"scene": {"scene_id": ""}}}';
                $return = httpRequest($url, 'POST', $jsonstr);
                mlog('关注二维码返回:' . $return, 'mobileindex/' . $stoid);
                $return = json_decode($return, 1);
                if (!empty($return['ticket'])) {
                    $v['ticket'] = $return['ticket'];
                    $v['store_id'] = $stoid;
                    $v['scene_id'] = '';
                    $v['date'] = time();
                    $v['loadurl'] = $return['url'];
                    M('wx_ewmlist')->add($v);
                    $url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $v['ticket'];
                    mlog('关注二维码生成成功', 'mobileindex/' . $stoid);
                } else {
                    mlog('关注二维码生成失败', 'mobileindex/' . $stoid);
                }
            } else {
                mlog('关注access_token失败', 'mobileindex/' . $stoid);
            }
        } else {
            $url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . $return['ticket'];
        }
        return json(['code' => 1, 'url' => $url]);
    }

}