public function createCoupon()
{
$data['card_type'] = $this->input->post_get('card_type');//代金券、兑换券、优惠券、折扣券
$data['brand_name'] = $this->input->post_get('brand_name');//商户名字
$data['title'] = $this->input->post_get('title');//卡券名
$data['color'] = $this->input->post_get('color');//卡券颜色
$data['notice'] = $this->input->post_get('notice');//操作提示
$data['service_phone'] = $this->input->post_get('service_phone');//客服电话
$data['description'] = $this->input->post_get('description');//使用须知
$data['begin_timestamp'] = $this->input->post_get('begin_timestamp');//开始时间
$data['end_timestamp'] = $this->input->post_get('end_timestamp');//结束时间
$data['fixed_term'] = $this->input->post_get('fixed_term');//表示自领取后多少天内有效
$data['location_id_list'] = $this->input->post_get('location_id_list');//门店id
// $data['use_limit'] = $this->input->post_get('use_limit');//每人可领券的数量限制,不填写默认为50
// $data['get_limit'] = $this->input->post_get('get_limit');//每人可核销的数量限制,不填写默认为50
// $data['can_share'] = $this->input->post_get('can_share');//卡券领取页面是否可分享
// $data['can_give_friend'] = $this->input->post_get('can_give_friend');//卡券是否可转赠
// $data['quantity'] = $this->input->post_get('quantity');//库存多少张
$res = $this->couponDo($data);
var_dump($res);
}
public function couponDo($data)
{$array = array(
"card" => array(
"card_type" => $data['card_type'],
strtolower($data['card_type']) => array( //用传过来的卡券类型当键 必须是小写
"base_info" => array(
"logo_url" => "", //已经上传过的logo url
"code_type" => 'CODE_TYPE_QRCODE',
"brand_name" => $data['brand_name'],"title" => $data['title'],
"color" => $data['color'],
"notice" => $data['notice'],
"description" => $data['description'],
"sku" => array("quantity" => 0), //自定义code码为0
"date_info" => array(
"type" => 'DATE_TYPE_FIX_TIME_RANGE',
"begin_timestamp" => $data['begin_timestamp'],
"end_timestamp" => $data['end_timestamp'],
"fixed_term" => $data['fixed_term'],
"fixed_begin_term" => 0
),
"service_phone" => $data['service_phone'],
"location_id_list" => [$data['location_id_list']],
"use_limit" => 1,
"get_limit" => 1,
"use_custom_code" => true, //自定义code码为true
"bind_openid" => false,
"can_share" => true,
"can_give_friend" => true,
"get_custom_code_mode" => "GET_CUSTOM_CODE_MODE_DEPOSIT" //自定义code码
),
// "least_cost" => 0, //满多少可用 单位 分
// "reduce_cost" => 50000, //减多少
)
)
);
$url = "https://api.weixin.qq.com/card/create?access_token=" . $this->token;
return curl_post($url, json_encode($array, JSON_UNESCAPED_UNICODE));
}