示例#1
0
文件: site.php 项目: ChainBoy/wxfx
 public function doWebRedGifts()
 {
     global $_W, $_GPC;
     if (!$_W['ispost']) {
         $this->doWebAuth();
         checklogin();
     }
     $modulePublic = '../addons/wwx_fxxt/style/static/';
     $foo = $_GPC['foo'];
     $foos = array('list', 'create', 'modify', 'delete', 'search');
     $foo = in_array($foo, $foos) ? $foo : 'list';
     require_once WWX_FXXT_ROOT . '/class/Gift.class.php';
     if ($foo == 'search') {
         $fuzzy = $_GPC['fuzzy'];
         $filters = array();
         $filters['title'] = $fuzzy;
         $g = new Gift();
         $ds = $g->getAll($filters, 1, 20);
         /**GIFT:2.查询所有活动礼品分类**/
         $rs = array();
         if (!empty($ds)) {
             foreach ($ds as $row) {
                 $rs[] = array_elements(array('id', 'type', 'title'), $row);
             }
         }
         exit(json_encode($rs));
     }
     if ($foo == 'create') {
         if ($_W['ispost']) {
             $input = array_elements(array('title', 'type', 'remark'), $_GPC);
             $input['remark'] = htmlspecialchars_decode($input['remark']);
             if ($input['type'] == 'cash') {
                 $input['tag'] = serialize($_GPC['cash']);
             } else {
                 $input['tag'] = '';
             }
             $g = new Gift();
             $ret = $g->create($input);
             /**GIFT:3.编辑活动礼品分类**/
             if (is_error($ret)) {
                 message($ret['message']);
             } else {
                 message('成功保存礼品信息', $this->createWebUrl('redgifts'));
             }
         }
         $entity = array();
         $entity['type'] = 'cash';
         $entity['tag'] = array();
         load()->func('tpl');
         include $this->template('redgifts_form');
     }
     if ($foo == 'modify') {
         $id = $_GPC['id'];
         $g = new Gift();
         $entity = $g->getOne($id);
         /**GIFT:1.根据ID查询活动礼品分类**/
         if (empty($entity)) {
             message('访问错误');
         }
         if ($_W['ispost']) {
             $input = array_elements(array('title', 'type', 'remark'), $_GPC);
             $input['remark'] = htmlspecialchars_decode($input['remark']);
             if ($input['type'] == 'cash') {
                 $input['tag'] = serialize($_GPC['cash']);
             } else {
                 $input['tag'] = '';
             }
             $g = new Gift();
             $ret = $g->modify($id, $input);
             /**GIFT:4.根据ID编辑活动礼品分类**/
             if (is_error($ret)) {
                 message($ret['message']);
             } else {
                 message('成功保存礼品信息', $this->createWebUrl('redgifts'));
             }
         }
         load()->func('tpl');
         include $this->template('redgifts_form');
     }
     if ($foo == 'delete') {
         $id = $_GPC['id'];
         $g = new Gift();
         $g->remove($id);
         /**GIFT:5.根据ID删除活动礼品分类**/
         message('成功删除礼品信息', $this->createWebUrl('redgifts'));
     }
     if ($foo == 'list') {
         $a = new Gift();
         $ds = $a->getAll(array());
         /**GIFT:2.查询所有活动礼品分类**/
         include $this->template('redgifts_list');
     }
 }
示例#2
0
 public function queryRecordCode($code)
 {
     global $_W;
     $condition = "`uniacid`=:uniacid AND `code`=:code";
     $pars = array();
     $pars[':uniacid'] = $_W['uniacid'];
     $pars[':code'] = $code;
     $sql = "SELECT * FROM " . tablename('wwx_fxxt_red_records') . " WHERE {$condition}";
     $rec = pdo_fetch($sql, $pars);
     if (empty($rec)) {
         return error(-1, '消费码错误');
     }
     if ($rec['status'] == 'complete') {
         $time = date('Y-m-d H:i', $rec['completed']);
         $rec['error'] = error(-2, "这个消费码已经于 {$time} 使用过了");
     }
     require_once WWX_FXXT_ROOT . '/class/Gift.class.php';
     $g = new Gift();
     $gift = $g->getOne($rec['gift']);
     if (empty($gift)) {
         $rec['error'] = error(-3, '这个消费码的商品已经失效了');
     }
     if ($gift['type'] != 'coupon') {
         $rec['error'] = error(-3, '这个消费码的商品属于现金产品, 不能被消费');
     }
     $rec['tag'] = @unserialize($rec['tag']);
     $rec['gift'] = $gift;
     $rec['activity'] = $this->getOne($rec['activity']);
     return $rec;
 }
示例#3
0
        if (is_error($ret)) {
            message($ret['message']);
        } else {
            message('成功保存礼品信息', $this->createWebUrl('gifts'));
        }
    }
    $entity = array();
    $entity['type'] = 'cash';
    $entity['tag'] = array();
    load()->func('tpl');
    include $this->template('gifts-form');
}
if ($foo == 'modify') {
    $id = $_GPC['id'];
    $g = new Gift();
    $entity = $g->getOne($id);
    if (empty($entity)) {
        message('访问错误');
    }
    if ($_W['ispost']) {
        $input = array_elements(array('title', 'type', 'remark'), $_GPC);
        $input['remark'] = htmlspecialchars_decode($input['remark']);
        if ($input['type'] == 'cash') {
            $input['tag'] = serialize($_GPC['cash']);
        } else {
            $input['tag'] = '';
        }
        $g = new Gift();
        $ret = $g->modify($id, $input);
        if (is_error($ret)) {
            message($ret['message']);
示例#4
0
     }
 }
 protected function send($activity, $record, $user)
 {
     global $_W;
     $uniacid = $_W['uniacid'];
     $api = $this->module['config']['api'];
     if (empty($api)) {
         return error(-2, '系统还未开放');
     }
     require_once MB_ROOT . '/source/Activity.class.php';
     require_once MB_ROOT . '/source/Gift.class.php';
     $a = new Activity();
     if (empty($record) || $record['status'] == 'complete') {
         return error(-1, '没有获得现金红包或已经领取过这个现金红包了');
     }
     $g = new Gift();
     $gift = $g->getOne($record['gift']);
     if (empty($gift) && $gift['type'] != 'cash') {
         return error(-1, '没有获得现金红包');
     }
     $fee = floatval($record['fee']) * 100;
     $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack';
     $pars = array();
     $pars['nonce_str'] = random(32);
     $pars['mch_billno'] = $api['mchid'] . date('Ymd') . sprintf('%010d', $record['id']);
     $pars['mch_id'] = $api['mchid'];
     $pars['wxappid'] = $api['appid'];
     $pars['nick_name'] = $gift['tag']['provider'];
     $pars['send_name'] = $gift['tag']['provider'];
     $pars['re_openid'] = $user['openid'];
     $pars['total_amount'] = $fee;
     $pars['min_value'] = $pars['total_amount'];
     $pars['max_value'] = $pars['total_amount'];
     $pars['total_num'] = 1;
     $pars['wishing'] = $gift['tag']['wish'];
     $pars['client_ip'] = $api['ip'];
     $pars['act_name'] = $activity['title'];
     $pars['remark'] = $gift['tag']['remark'];
     $pars['logo_imgurl'] = tomedia($gift['tag']['image']);
     $pars['share_content'] = $gift['tag']['content'];
     $pars['share_imgurl'] = tomedia($gift['tag']['image']);
     $pars['share_url'] = $_W['siteroot'] . 'app/' . substr($this->createMobileUrl('entry', array('owner' => $user['uid'], 'actid' => $activity['actid'])), 2);
     ksort($pars, SORT_STRING);
     $string1 = '';
     foreach ($pars as $k => $v) {
         $string1 .= "{$k}={$v}&";
     }
     $string1 .= "key={$api['password']}";
     $pars['sign'] = strtoupper(md5($string1));
     $xml = array2xml($pars);
     $extras = array();
     $extras['CURLOPT_CAINFO'] = MB_ROOT . '/cert/rootca.pem.' . $uniacid;
     $extras['CURLOPT_SSLCERT'] = MB_ROOT . '/cert/apiclient_cert.pem.' . $uniacid;
     $extras['CURLOPT_SSLKEY'] = MB_ROOT . '/cert/apiclient_key.pem.' . $uniacid;
     load()->func('communication');
     $procResult = null;
     $resp = ihttp_request($url, $xml, $extras);
     if (is_error($resp)) {
         $procResult = $resp;
     } else {
         $xml = '<?xml version="1.0" encoding="utf-8"?>' . $resp['content'];
         $dom = new \DOMDocument();
         if ($dom->loadXML($xml)) {
             $xpath = new \DOMXPath($dom);
             $code = $xpath->evaluate('string(//xml/return_code)');
             $ret = $xpath->evaluate('string(//xml/result_code)');
             if (strtolower($code) == 'success' && strtolower($ret) == 'success') {
                 $procResult = true;
             } else {
                 $error = $xpath->evaluate('string(//xml/err_code_des)');
                 $procResult = error(-2, $error);
             }
         } else {
             $procResult = error(-1, 'error response');
         }
     }
     if (is_error($procResult)) {
         $filters = array();
         $filters['uniacid'] = $uniacid;
         $filters['id'] = $record['id'];
         $rec = array();
         $rec['log'] = $procResult['message'];
         pdo_update('mbsk_records', $rec, $filters);
         return $procResult;
     } else {
         $a->confirm($record['id'], sprintf('%.2f', $fee / 100));
         return true;