481 lines
18 KiB
PHP
481 lines
18 KiB
PHP
<?php
|
|
|
|
namespace addon\aliapp\model;
|
|
|
|
use app\model\BaseModel;
|
|
|
|
class AliMemberTemplate extends BaseModel
|
|
{
|
|
|
|
public $site_id;
|
|
|
|
public function __construct($site_id)
|
|
{
|
|
$this->site_id = $site_id;
|
|
}
|
|
|
|
/***
|
|
* 创建模版
|
|
* @param $data
|
|
* @return array|void
|
|
*/
|
|
public function addTemplate($data)
|
|
{
|
|
$rgb = $this->hex2rgb($data['bg_color']);
|
|
$ali = new CloudPay();
|
|
$aliData = [
|
|
'card_show_name' => $data['level_name'],
|
|
'bg_color' => 'rgb(' . $rgb['r'] . ',' . $rgb['g'] . ',' . $rgb['b'] . ')',
|
|
'logo_id' => $ali->imageUpload($this->site_id, $data['level_logo'], 'level_logo', true)['data']['image_id'],
|
|
'background_id' => $ali->imageUpload($this->site_id, $data['level_picture'], 'level_picture', true)['data']['image_id'],
|
|
];
|
|
$template = $this->alipayMarketingCardTemplateCreate($this->site_id, array_merge($aliData, $data));//创建下小程序模版
|
|
if ($template['code'] < 0) return $template;
|
|
$data['alipay_marketing_card_template_id'] = $template['data']['template_id'];
|
|
$formtemplateSet = $this->alipayMarketingCardFormtemplateSet($this->site_id, $template['data']['template_id']);
|
|
if ($formtemplateSet['code'] < 0) return $formtemplateSet;
|
|
return $template;
|
|
}
|
|
|
|
|
|
public function editTemplate()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
public function delTemplate()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取站点推荐会员卡
|
|
* @param $site_id
|
|
*/
|
|
public function getAliMemberCard($site_id)
|
|
{
|
|
$condition = [
|
|
['site_id', '=', $site_id],
|
|
['status', '=', 1],
|
|
['alipay_marketing_card_template_id', '<>', '']
|
|
];
|
|
$field = 'level_id,level_name,consume_discount,is_free_shipping,point_feedback,send_point,send_balance,send_coupon,charge_rule,alipay_marketing_card_template_id';
|
|
$data = model('member_level')->getInfo($condition, $field);
|
|
// 获取支付宝支付参数(统一支付到平台账户)
|
|
$config_model = new \addon\aliapp\model\Config();
|
|
$config_info = $config_model->getAppConfig($site_id)['data'];
|
|
$data['appid'] = $config_info['appid'];
|
|
return $this->success($data);
|
|
}
|
|
|
|
/***
|
|
* 创建支付宝商家会员卡
|
|
* @param $site_id
|
|
* @param $data
|
|
* @return array
|
|
*/
|
|
public function alipayMarketingCardTemplateCreate($site_id, $data)
|
|
{
|
|
// 获取支付宝支付参数(统一支付到平台账户)
|
|
$config_model = new \addon\aliapp\model\Config();
|
|
$config_info = $config_model->getAppConfig($site_id)['data'];
|
|
$platform_config_info = config('alipay.platform');
|
|
$ali = new CloudPay();
|
|
$a = 'A*zCGWRbRjnSoAAAAAAAAAAAAABKd2AQ';
|
|
$b = 'A*yf7PTZGSorcAAAAAAAAAAAAABKd2AQ';
|
|
$c = 'A*i8CkTIsG9dkAAAAAAAAAAAAABKd2AQ';
|
|
$params = [
|
|
'request_id' => substr($this->uuid(), 0, 20),
|
|
'card_type' => 'OUT_MEMBER_CARD',
|
|
'biz_no_suffix_len' => '20',
|
|
'write_off_type' => 'qrcode',
|
|
'template_style_info' => [
|
|
'card_show_name' => $data['card_show_name'],
|
|
'logo_id' => $data['logo_id'],
|
|
'background_id' => $data['background_id'],
|
|
'bg_color' => $data['bg_color'],
|
|
// 'feature_descriptions' => $data['remark'],
|
|
],
|
|
// 'template_benefit_info'=>[
|
|
// 'title'=>$data['remark'],
|
|
// 'benefit_desc'=>$data['remark'],
|
|
// 'end_date'=>$data['remark'],
|
|
// ],
|
|
'column_info_list' => [
|
|
[
|
|
'code' => 'MY_HOME',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '商城主页',
|
|
'more_info' => [
|
|
'title' => '商城主页',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid']
|
|
]
|
|
],
|
|
[
|
|
'code' => 'MEMBER_INFO',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '会员中心',
|
|
'more_info' => [
|
|
'title' => '个人中心',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'] . '&page=pages/member/index'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'BALANCE',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '余额',
|
|
'more_info' => [
|
|
'title' => '个人中心',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'] . '&page=pages/member/index'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'MY_ORDER',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '我的订单',
|
|
'more_info' => [
|
|
'title' => '我的订单',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'] . '&page=pages_market/order/list'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'CARD_INFO',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '会员卡详情',
|
|
'more_info' => [
|
|
'title' => '会员卡详情',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'] . '&page=pages_tool/member/card'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'MINI_SHOP',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '售后服务',
|
|
'more_info' => [
|
|
'title' => '售后服务',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'].'&page=pages_tool/order/activist'
|
|
]
|
|
],
|
|
],
|
|
'field_rule_list' => [
|
|
[
|
|
'field_name' => 'Balance',
|
|
'rule_name' => 'ASSIGN_FROM_REQUEST',
|
|
'rule_value' => 'Balance'
|
|
]
|
|
],
|
|
'card_action_list' => [
|
|
[
|
|
'code' => 'GO_APPOINTMENT',
|
|
'text' => '会员签到',
|
|
'url_type' => 'miniAppUrl',
|
|
'mini_app_url' => [
|
|
'mini_app_id' => $config_info['appid'],
|
|
'mini_page_param' => 'pages_tool/member/signin',
|
|
'display_on_list' => 'false'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'MY_APPOINTMENT',
|
|
'text' => '优惠券',
|
|
'url_type' => 'miniAppUrl',
|
|
'mini_app_url' => [
|
|
'mini_app_id' => $config_info['appid'],
|
|
'mini_page_param' => 'pages_tool/member/coupon',
|
|
'display_on_list' => 'false'
|
|
]
|
|
]
|
|
],
|
|
'open_card_conf' => [
|
|
'open_card_source_type' => 'MER',
|
|
'source_app_id' => $platform_config_info["appid"] ?? "",
|
|
'open_card_url' => addon_url('aliapp/shop/membercard/receive',['appid'=>$config_info['appid']]),
|
|
'card_rights' => [
|
|
[
|
|
'title' => '入会有礼',
|
|
'logo_id' => $a,
|
|
],
|
|
[
|
|
'title' => '在线预约',
|
|
'logo_id' => $b,
|
|
],
|
|
[
|
|
'title' => '专属福利',
|
|
'logo_id' => $c,
|
|
],
|
|
],
|
|
],
|
|
'spi_app_id' => $platform_config_info["appid"] ?? ""
|
|
];
|
|
|
|
return $this->success(cache('alipay_marketing_card_template_create_response'));
|
|
// 发起请求
|
|
$result = (new MinCode($site_id))->requestApi('alipay.marketing.card.template.create', $params, []);
|
|
$result = $result['alipay_marketing_card_template_create_response'];
|
|
if ($result['code'] == 10000) {
|
|
cache('alipay_marketing_card_template_create_response',$result);
|
|
return $this->success($result);
|
|
} else {
|
|
return $this->error('', $result['sub_msg']);
|
|
}
|
|
}
|
|
|
|
public function alipayMarketingCardTemplateModify($site_id, $template_id, $data)
|
|
{
|
|
// 获取支付宝支付参数(统一支付到平台账户)
|
|
$config_model = new \addon\aliapp\model\Config();
|
|
$config_info = $config_model->getAppConfig($site_id)['data'];
|
|
|
|
$ali = new CloudPay();
|
|
$a = 'A*zCGWRbRjnSoAAAAAAAAAAAAABKd2AQ';
|
|
$b = 'A*yf7PTZGSorcAAAAAAAAAAAAABKd2AQ';
|
|
$c = 'A*i8CkTIsG9dkAAAAAAAAAAAAABKd2AQ';
|
|
$params = [
|
|
'request_id' => substr($this->uuid(), 0, 20),
|
|
'template_id' => $template_id,
|
|
// 'card_type' => 'OUT_MEMBER_CARD',
|
|
'biz_no_suffix_len' => '20',
|
|
'write_off_type' => 'qrcode',
|
|
'template_style_info' => [
|
|
'card_show_name' => $data['card_show_name'],
|
|
'logo_id' => $data['logo_id'],
|
|
'background_id' => $data['background_id'],
|
|
'bg_color' => $data['bg_color'],
|
|
],
|
|
'column_info_list' => [
|
|
[
|
|
'code' => 'BALANCE',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '余额',
|
|
'more_info' => [
|
|
'title' => '个人中心',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'] . '&page=pages/member/index'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'MEMBER_INFO',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '个人中心',
|
|
'more_info' => [
|
|
'title' => '个人中心',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'] . '&page=pages/member/index'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'MY_CARD',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '我的服务卡',
|
|
'more_info' => [
|
|
'title' => '我的服务卡',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'] . '&page=pages_service/service_card/list'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'MY_ORDER',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '我的订单',
|
|
'more_info' => [
|
|
'title' => '我的订单',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid'] . '&page=pages_service/service_order/list'
|
|
]
|
|
],
|
|
// [
|
|
// 'code' => 'CARD_INFO',
|
|
// 'operate_type' => 'openWeb',
|
|
// 'title' => '会员卡详情',
|
|
// 'more_info' => [
|
|
// 'title' => '会员卡详情',
|
|
// 'url' => 'alipays://platformapi/startapp?appId='.$config_info['appid'].'&page=pages/member/index'
|
|
// ]
|
|
// ],
|
|
[
|
|
'code' => 'MINI_SHOP',
|
|
'operate_type' => 'openWeb',
|
|
'title' => '小程序商城',
|
|
'more_info' => [
|
|
'title' => '小程序商城',
|
|
'url' => 'alipays://platformapi/startapp?appId=' . $config_info['appid']
|
|
]
|
|
],
|
|
],
|
|
'field_rule_list' => [
|
|
[
|
|
'field_name' => 'Balance',
|
|
'rule_name' => 'ASSIGN_FROM_REQUEST',
|
|
'rule_value' => 'Balance'
|
|
]
|
|
],
|
|
'card_action_list' => [
|
|
[
|
|
'code' => 'GO_APPOINTMENT',
|
|
'text' => '去预约',
|
|
'url_type' => 'miniAppUrl',
|
|
'mini_app_url' => [
|
|
'mini_app_id' => $config_info['appid'],
|
|
'mini_page_param' => 'pages_promotion/cardservice/service_goods/reserve_apply',
|
|
'display_on_list' => 'false'
|
|
]
|
|
],
|
|
[
|
|
'code' => 'MY_APPOINTMENT',
|
|
'text' => '我的预约',
|
|
'url_type' => 'miniAppUrl',
|
|
'mini_app_url' => [
|
|
'mini_app_id' => $config_info['appid'],
|
|
'mini_page_param' => 'pages_promotion/cardservice/service_goods/my_reserve_list',
|
|
'display_on_list' => 'false'
|
|
]
|
|
]
|
|
],
|
|
'open_card_conf' => [
|
|
'open_card_source_type' => 'MER',
|
|
'source_app_id' => '2021003167617037',
|
|
'open_card_url' => 'https://www.alipay.com',
|
|
'card_rights' => [
|
|
[
|
|
'title' => '入会有礼',
|
|
'logo_id' => $a,
|
|
],
|
|
[
|
|
'title' => '专属福利',
|
|
'logo_id' => $c,
|
|
],
|
|
[
|
|
'title' => '在线预约',
|
|
'logo_id' => $b,
|
|
]
|
|
],
|
|
],
|
|
'spi_app_id' => '2021003167617037'
|
|
];
|
|
// 发起请求
|
|
$result = (new MinCode($site_id))->requestApi('alipay.marketing.card.template.modify', $params, []);
|
|
|
|
$result = $result['alipay_marketing_card_template_modify_response'];
|
|
if ($result['code'] == 10000) {
|
|
return $this->success($result);
|
|
} else {
|
|
return $this->error('', $result['sub_msg']);
|
|
}
|
|
}
|
|
|
|
|
|
/***
|
|
* 设置开卡必填信息
|
|
* @param $site_id
|
|
* @param $template_id
|
|
* @return array
|
|
*/
|
|
public function alipayMarketingCardFormtemplateSet($site_id, $template_id)
|
|
{
|
|
$params = [
|
|
"template_id" => $template_id,
|
|
'fields' => [
|
|
'required' => '{"common_fields": [ "OPEN_FORM_FIELD_NAME", "OPEN_FORM_FIELD_GENDER", "OPEN_FORM_FIELD_MOBILE", "OPEN_FORM_FIELD_BIRTHDAY" ] }'
|
|
]
|
|
];
|
|
// 发起请求
|
|
$result = (new MinCode($site_id))->requestApi('alipay.marketing.card.formtemplate.set', $params, []);
|
|
$result = $result['alipay_marketing_card_formtemplate_set_response'];
|
|
if ($result['code'] == 10000) {
|
|
return $this->success($result);
|
|
} else {
|
|
return $this->error('', $result['sub_msg']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 生成UUID
|
|
*/
|
|
public function uuid()
|
|
{
|
|
$chars = md5(uniqid(mt_rand(), true));
|
|
$uuid = substr($chars, 0, 8) . '-'
|
|
. substr($chars, 8, 4) . '-'
|
|
. substr($chars, 12, 4) . '-'
|
|
. substr($chars, 16, 4) . '-'
|
|
. substr($chars, 20, 12);
|
|
return $uuid;
|
|
}
|
|
|
|
/**
|
|
* 会员卡更新
|
|
* @param $site_id
|
|
* @param $template_id
|
|
* @param $data
|
|
* @return array
|
|
*/
|
|
public function alipayMarketingCardUpdate($site_id, $member_id)
|
|
{
|
|
|
|
$memberInfo = model('member')->getInfo([['member_id', '=', $member_id]]);
|
|
if (empty($memberInfo)) {
|
|
return $this->error('用户信息不存在');
|
|
}
|
|
|
|
if (isset($memberInfo['alipay_biz_card_no']) && $memberInfo['alipay_biz_card_no'] == '') {
|
|
return $this->error('支付宝会员卡信息不存在');
|
|
}
|
|
|
|
if (isset($memberInfo['alipay_card_open_date']) && $memberInfo['alipay_card_open_date'] == '') {
|
|
return $this->error('支付宝会员卡信息不存在');
|
|
}
|
|
|
|
if (isset($memberInfo['alipay_card_valid_date']) && $memberInfo['alipay_card_valid_date'] == '') {
|
|
return $this->error('支付宝会员卡信息不存在');
|
|
}
|
|
|
|
$params = [
|
|
'target_card_no' => $memberInfo['alipay_biz_card_no'],
|
|
'target_card_no_type' => 'BIZ_CARD',
|
|
'occur_time' => date('Y-m-d H:i:s', time()),
|
|
'card_info' => [
|
|
'biz_card_no' => $memberInfo['alipay_biz_card_no'],
|
|
'external_card_no' => $memberInfo['member_id'] + 1000000000,
|
|
'open_date' => $memberInfo['alipay_card_open_date'],
|
|
'valid_date' => $memberInfo['alipay_card_valid_date'],
|
|
'balance' => $memberInfo['balance'] + $memberInfo['balance_money']
|
|
],
|
|
];
|
|
// 发起请求
|
|
$result = (new MinCode($site_id))->requestApi('alipay.marketing.card.update', $params, []);
|
|
|
|
$result = $result['alipay_marketing_card_update_response'];
|
|
if ($result['code'] == 10000) {
|
|
return $this->success($result);
|
|
} else {
|
|
return $this->error('', $result['sub_msg']);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 将16进制颜色转换为RGB
|
|
* author www.zwyuanma.com
|
|
*/
|
|
private function hex2rgb($hexColor)
|
|
{
|
|
$color = str_replace('#', '', $hexColor);
|
|
if (strlen($color) > 3) {
|
|
$rgb = array(
|
|
'r' => hexdec(substr($color, 0, 2)),
|
|
'g' => hexdec(substr($color, 2, 2)),
|
|
'b' => hexdec(substr($color, 4, 2))
|
|
);
|
|
} else {
|
|
$r = substr($color, 0, 1) . substr($color, 0, 1);
|
|
$g = substr($color, 1, 1) . substr($color, 1, 1);
|
|
$b = substr($color, 2, 1) . substr($color, 2, 1);
|
|
$rgb = array(
|
|
'r' => hexdec($r),
|
|
'g' => hexdec($g),
|
|
'b' => hexdec($b)
|
|
);
|
|
}
|
|
return $rgb;
|
|
}
|
|
} |