public function createCard($id, $is_edit = 0) { $info = M('Member_card_coupon')->where('id=' . $id)->find(); if ($info['company_id'] == 0) { $company = M('Company')->where('token="' . $info['token'] . '" AND location_id!=0')->order('isbranch ASC')->select(); } else { $company = M('Company')->where('token="' . $info['token'] . '" AND id=' . $info['company_id'])->select(); } if (empty($company)) { return array('errcode' => '-1', 'errmsg' => '商家门店未导入'); exit; } $logo_url = $this->getLogoUrl($info['logourl'], $id); $location_id_list = array(); foreach ($company as $key => $value) { if ($value['location_id']) { $location_id_list[] = $value['location_id']; } } switch ($info['type']) { case '0': $card_type = 'CASH'; $coupon_type = 2; break; case '1': $card_type = 'GENERAL_COUPON'; $coupon_type = 1; break; case '2': $card_type = 'GIFT'; $coupon_type = 3; break; default: $card_type = 'GENERAL_COUPON'; break; } $base_info = new BaseInfo($logo_url['url'], $company[0]['name'], 0, $info['title'], $info['color'], '使用时向店员员出示此券', $company[0]['tel'], $info['info'], new DateInfo(1, intval($info['statdate']), intval($info['enddate'])), new Sku($info['total'])); $base_info->set_sub_title(''); $base_info->set_use_limit(1); $base_info->set_get_limit(intval($info['people'])); $base_info->set_use_custom_code(false); $base_info->set_bind_openid(false); $base_info->set_can_share(false); $base_info->set_can_give_friend(false); $base_info->set_location_id_list($location_id_list); $base_info->set_url_name_type(1); $base_info->set_custom_url_name('立即使用'); $base_info->set_custom_url(U('Wap/Card/consume', array('token' => $info['token'], 'cardid' => $info['cardid'], 'from' => 'weixin'), '', '', true)); $card = new Card($card_type, $base_info); switch ($info['type']) { case '0': $card->get_card()->set_least_cost($info['least_cost'] * 100); $card->get_card()->set_reduce_cost($info['reduce_cost'] * 100); break; case '1': $card->get_card()->set_default_detail($company[0]['intro']); break; case '2': $card->get_card()->set_gift($info['gift_name']); break; default: $card->get_card()->set_default_detail($company[0]['intro']); break; } $post_data = $card->toJson(); $url = 'https://api.weixin.qq.com/card/create?access_token=' . $this->access_token; $res = $this->https_request($url, $post_data); return $res; }
<?php namespace Weixin\Model; // ------------------------set base_info----------------------------- $base_info = new BaseInfo("http://www.supadmin.cn/uploads/allimg/120216/1_120216214725_1.jpg", "海底捞", 0, "132元双人火锅套餐", "Color010", "使用时向服务员出示此券", "020-88888888", "不可与其他优惠同享\n 如需团购券发票,请在消费时向商户提出\n 店内均可使用,仅限堂食\n 餐前不可打包,餐后未吃完,可打包\n 本团购券不限人数,建议2人使用,超过建议人数须另收酱料费5元/位\n 本单谢绝自带酒水饮料", new DateInfo(1, 1397577600, 1399910400), new Sku(50000000)); $base_info->set_sub_title(""); $base_info->set_use_limit(1); $base_info->set_get_limit(3); $base_info->set_use_custom_code(false); $base_info->set_bind_openid(false); $base_info->set_can_share(true); $base_info->set_url_name_type(1); $base_info->set_custom_url("http://www.qq.com"); // ---------------------------set_card-------------------------------- $card = new Groupon($base_info, "以下锅底2 选1(有菌王锅、麻辣锅、大骨锅、番茄锅、清补凉锅、酸菜鱼锅可选):\n 大锅1 份12 元\n 小锅2 份16 元\n 以下菜品2 选1\n 特级肥牛1 份30 元\n 洞庭鮰鱼卷1 份20元\n 其他\n鲜菇猪肉滑1 份18 元\n 金针菇1 份16 元\n 黑木耳1 份9 元\n 娃娃菜1 份8 元\n 冬瓜1份6 元\n 火锅面2 个6 元\n 欢乐畅饮2 位12 元\n 自助酱料2 位10 元"); // ----------------------check signature------------------------ $signature = new Signature(); $signature->add_data("123"); $signature->add_data("wasda"); $signature->add_data("_()@#(&"); echo $signature->get_signature();
/** * 创建卡券 * @param $merchant_type : 券类型 *[必填] * @param $base_info : 基本的卡券字段数据 *[必填] * @param $extra_data :不同类型卡券特有的字段 *[必填] * @param $custom_cells:自定义cell * $custom_cells = array( * "custom_url_name"=>"xxxxx", //使用场景 【最多5个汉字】 * "custom_url"=>"http://www.xxx.com", //使用场景链接 * "custom_url_sub_title"=>"xxxxxx", //使用场景提示语 【最多6个汉字】 * "promotion_url_name"=>"xxxxx", //营销场景 【最多5个汉字】 * "promotion_url"=>"http://www.xxx.com", //营销场景链接 * "promotion_url_sub_title"=>"xxxxxx" //营销场景提示语 【最多6个汉字】 * ); * 其他参数均为基本卡券字段中的选填项 [非必填] * @return array */ function card_create($merchant_type, $base_data, $extra_data, $location_id_list = "", $sub_title = "", $use_limit = "", $get_limit = "", $url_name_type = "", $custom_cells = false, $source = "", $can_share = true, $can_give_friend = true, $use_custom_code = false, $bind_openid = false) { //exit(); $card_type = $this->get_card_type($merchant_type); //有效期 $date_info = new DateInfo($base_data["date_info"]["type"], $base_data["date_info"]["arg0"], $base_data["date_info"]["arg1"]); //库存 $sku = new Sku($base_data["sku"]); //颜色转换 $colorname = "Color010"; $colorinfo = $this->card_getcolors(); foreach ($colorinfo["colors"] as $color) { if ($color["value"] == $base_data["color"]) { $colorname = $color["name"]; break; } } //必填基础字段 $code_type = $this->get_code_type($base_data["code_type"]); $base_info = new BaseInfo($base_data["logo_url"], $base_data["brand_name"], $code_type, $base_data["title"], $colorname, $base_data["notice"], $base_data["service_phone"], $base_data["description"], $date_info, $sku); $card = new Card($card_type, $base_info); //选填字段 $base_info->set_location_id_list($location_id_list); $base_info->set_sub_title($sub_title); $base_info->set_use_limit($use_limit); $base_info->set_get_limit($get_limit); $base_info->set_use_custom_code($use_custom_code); $base_info->set_bind_openid($bind_openid); $base_info->set_can_share($can_share); $base_info->set_can_give_friend($can_give_friend); $base_info->set_url_name_type($url_name_type); $base_info->set_source($source); //自定义cell if (is_array($custom_cells)) { $base_info->set_custom_url_name($custom_cells["custom_url_name"]); $base_info->set_custom_url($custom_cells["custom_url"]); $base_info->set_custom_url_sub_title($custom_cells["custom_url_sub_title"]); $base_info->set_promotion_url_name($custom_cells["promotion_url_name"]); $base_info->set_promotion_url($custom_cells["promotion_url"]); $base_info->set_promotion_url_sub_title($custom_cells["promotion_url_sub_title"]); } //根据卡券类型设置卡券数据 switch ($card_type) { case $this->CARD_TYPE[0]: //通用卡 if (!isset($extra_data["default_detail"])) { exit("default_detail must be set!"); } $card->get_card()->set_default_detail($extra_data["default_detail"]); //必填 break; case $this->CARD_TYPE[1]: //团购卡 if (!isset($extra_data["deal_detail"])) { exit("deal_detail must be set!"); } $card->get_card()->set_deal_detail($extra_data["deal_detail"]); //必填 break; case $this->CARD_TYPE[2]: //折扣卡 if (!isset($extra_data["discount"])) { exit("discount must be set!"); } $card->get_card()->set_discount($extra_data["discount"]); //必填 break; case $this->CARD_TYPE[3]: //礼品卡 if (!isset($extra_data["gift"])) { exit("gift must be set!"); } $card->get_card()->set_gift($extra_data["gift"]); //必填 break; case $this->CARD_TYPE[4]: //代金券 if (isset($extra_data["least_cost"])) { $card->get_card()->set_least_cost($extra_data["least_cost"]); } if (!isset($extra_data["reduce_cost"])) { exit("reduce_cost must be set!"); } $card->get_card()->set_reduce_cost($extra_data["reduce_cost"]); //必填 break; case $this->CARD_TYPE[5]: //会员卡 if (!isset($extra_data["supply_bonus"]) || !isset($extra_data["supply_balance"]) || !isset($extra_data["prerogative"])) { exit("supply_bonus and supply_balance and prerogative must be set!"); } $card->get_card()->set_supply_bonus($extra_data["supply_bonus"]); //必填 $card->get_card()->set_supply_balance($extra_data["supply_balance"]); //必填 $card->get_card()->set_prerogative($extra_data["prerogative"]); //必填 //bind_old_card_url or activate_url must be set one! if (!isset($extra_data["bonus_rules"]) && !isset($extra_data["bonus_rules"])) { exit("bind_old_card_url or activate_url must be set one!"); } else { if (isset($extra_data["bind_old_card_url"])) { $card->get_card()->set_bind_old_card_url($extra_data["bind_old_card_url"]); } if (isset($extra_data["activate_url"])) { $card->get_card()->set_activate_url($extra_data["activate_url"]); } } if (isset($extra_data["bonus_cleared"])) { $card->get_card()->set_bonus_cleared($extra_data["bonus_cleared"]); } if (isset($extra_data["bonus_rules"])) { $card->get_card()->set_bonus_rules($extra_data["bonus_rules"]); } if (isset($extra_data["balance_rules"])) { $card->get_card()->set_balance_rules($extra_data["balance_rules"]); } break; case $this->CARD_TYPE[6]: //门票 if (isset($extra_data["ticket_class"])) { $card->get_card()->set_ticket_class($extra_data["ticket_class"]); } if (isset($extra_data["guide_url"])) { $card->get_card()->set_guide_url($extra_data["guide_url"]); } break; case $this->CARD_TYPE[7]: //电影票 if (isset($extra_data["detail"])) { $card->get_card()->set_detail($extra_data["detail"]); } break; break; case $this->CARD_TYPE[8]: //飞机票 if (!isset($extra_data["from"]) || !isset($extra_data["to"]) || !isset($extra_data["flight"]) || !isset($extra_data["departure_time"]) || !isset($extra_data["landing_time"])) { exit("from and to and flight and departure_time and landing_time must be set!"); } $card->get_card()->set_from($extra_data["from"]); //必填 $card->get_card()->set_to($extra_data["to"]); //必填 $card->get_card()->set_flight($extra_data["flight"]); //必填 $card->get_card()->set_departure_time($extra_data["departure_time"]); //必填 $card->get_card()->set_landing_time($extra_data["landing_time"]); //必填 break; case $this->CARD_TYPE[9]: //红包,无额外数据 break; default: exit("CardType Error"); } //cardjson $jsondata = json_decode($card->toJson(), true); return $this->postapi("card/create", $jsondata); }