1681 行
66 KiB
PHP
可执行文件
1681 行
66 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Api\Controller;
|
||
|
||
use Think\Controller;
|
||
|
||
//[1.9.5]
|
||
|
||
/**
|
||
* Class RetailPaySetController
|
||
* @package PayApi\Controller
|
||
*/
|
||
class RetailPaySetController extends Controller
|
||
{
|
||
static private $gatewayUrl = "https://gateway.starpos.com.cn/emercapp";
|
||
|
||
/**
|
||
* 获取商户支付设置
|
||
* @param $merchant_id
|
||
* @return array
|
||
* @return array
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
*/
|
||
public function getPaySet($merchant_id, $store_id = 0)
|
||
{
|
||
$store_id = is_numeric($store_id) ? $store_id : 0;
|
||
// 查询合伙人新大陆商户模式
|
||
$entry_status = M('retail_admin')->getField('entry');
|
||
// 定义空数组
|
||
$paySet = array(
|
||
'id' => 0,
|
||
'wx_appid' => '',
|
||
'wx_secret_key' => '',
|
||
'wx_serial_no' => '',
|
||
'wx_mch_id' => '',
|
||
'wxpay' => '',
|
||
'balance' => '',
|
||
'merchantid' => '',
|
||
'addtime' => '',
|
||
'alipay_public_key' => '',
|
||
'alipay_private_key' => '',
|
||
'alipay_sellerid' => '',
|
||
'zfpay' => '',
|
||
'xcx_appid' => '',
|
||
'xcx_mer_id' => '',
|
||
'wx_xcx_serial_no' => '',
|
||
'xcx_secret_key' => '',
|
||
'xcx_wxpay' => '',
|
||
'apiclient_cert' => '',
|
||
'apiclient_key' => '',
|
||
'status' => '',
|
||
'wx_appsecret' => '',
|
||
'wx_sub_mchid' => '',
|
||
'alipay_token' => '',
|
||
'xcx_apiclient_cert' => '',
|
||
'xcx_apiclient_key' => '',
|
||
'wx_pay_state' => 0,
|
||
'al_pay_state' => 0,
|
||
'xcx_pay_state' => 0,
|
||
'xcx_sub_mchid' => '',
|
||
'xcx_sub_appid' => '',
|
||
'wx_sub_appid' => '',
|
||
'happy_pay_num' => '',//乐返支付商户编号
|
||
'happy_pay_appid' => '',//乐返商户小程序appId
|
||
'happy_pay_app_secret' => '',//乐返商户小程序密钥
|
||
'lakala_pay_num' => '',//拉卡拉商户号
|
||
'lakala_pay_appid' => '',//拉卡拉商户小程序appId
|
||
'qian_ke_mid' => '',//钱客云商户ID
|
||
'qian_ke_key' => '',//钱客云商户密钥
|
||
'qian_ke_app_id' => '',//钱客云小程序appid
|
||
'qian_ke_public_appid' => '',//钱客云公众号appid
|
||
);
|
||
// 获取商户支付设置
|
||
$pay = M('retail_payset')->where(array('merchantid' => $merchant_id, 'storeid' => $store_id))->find();
|
||
if (!empty($pay)) {
|
||
$paySet = $pay;
|
||
$paySet['wx_pay_state'] = intval($paySet['wx_pay_state']);
|
||
$paySet['al_pay_state'] = intval($paySet['al_pay_state']);
|
||
$paySet['xcx_pay_state'] = intval($paySet['xcx_pay_state']);
|
||
}
|
||
// 商户新大陆设置
|
||
$entry = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->find();
|
||
if (!empty($entry)) {
|
||
$merchantInfo = M('merchant_infos')->where(array('entry_id' => $entry['id']))->find();
|
||
$entry['key'] = $merchantInfo['key'];
|
||
$entry['trm_no'] = $merchantInfo['trm_no'];
|
||
$entry['mcc_cd'] = M('mcc')->where(array('mcc_cd' => $entry['mcc_cd']))->getField('mcc_nm');
|
||
$pro = M('citys')->where(array('cityid' => $entry['province']))->getField('city_name');
|
||
$city = M('citys')->where(array('cityid' => $entry['city']))->getField('city_name');
|
||
$stoe = M('citys')->where(array('cityid' => $entry['stoe_area_cod']))->getField('city_name');
|
||
$entry['citys'] = $pro . $city . $stoe . $entry['stoe_adds'];
|
||
if (empty($merchantInfo)) {
|
||
$merchantInfo = array();
|
||
}
|
||
} else {
|
||
$merchantInfo = array();
|
||
$entry = array();
|
||
}
|
||
$res = array(
|
||
'entry_status' => $entry_status,
|
||
'paySet' => $paySet,
|
||
'entry' => $entry,
|
||
'merchantInfo' => $merchantInfo,
|
||
);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 保存支付设置
|
||
* @param $merchant_id
|
||
* @return mixed
|
||
*/
|
||
public function doSetPaySet($merchant_id, $store_id = 0)
|
||
{
|
||
$store_id = is_numeric($store_id) ? $store_id : 0;
|
||
if (empty($merchant_id)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '请求有误';
|
||
return $res;
|
||
}
|
||
$type = I('post.type');
|
||
$msg = '';//用于日志功能
|
||
switch ($type) {
|
||
case '1':
|
||
$msg = '普通商户模式:编辑微信支付配置';
|
||
$save = array(
|
||
'wx_pay_state' => I('post.wx_pay_state'),
|
||
'wx_appid' => I('post.wx_appid'),
|
||
'wx_appsecret' => I('post.wx_appsecret'),
|
||
'wx_mch_id' => I('post.wx_mch_id'),
|
||
'wx_secret_key' => I('post.wx_secret_key'),
|
||
'wx_serial_no' => I('post.wx_serial_no'),
|
||
'apiclient_cert' => I('post.apiclient_cert'),
|
||
'apiclient_key' => I('post.apiclient_key'),
|
||
);
|
||
break;
|
||
case '2':
|
||
$msg = '普通商户模式:编辑微信小程序支付设置';
|
||
$save = array(
|
||
'xcx_pay_state' => I('post.xcx_pay_state'),
|
||
'xcx_appid' => I('post.xcx_appid'),
|
||
'xcx_mer_id' => I('post.xcx_mer_id'),
|
||
'wx_xcx_serial_no' => I('post.wx_xcx_serial_no'),
|
||
'xcx_secret_key' => I('post.xcx_secret_key'),
|
||
'xcx_apiclient_cert' => I('post.xcx_apiclient_cert'),
|
||
'xcx_apiclient_key' => I('post.xcx_apiclient_key'),
|
||
'balance' => I('post.balance')
|
||
);
|
||
break;
|
||
case '3':
|
||
$msg = '普通商户模式:编辑支付宝支付设置';
|
||
$save = array(
|
||
'al_pay_state' => I('post.al_pay_state'),
|
||
'alipay_appid' => I('post.alipay_appid'),
|
||
'alipay_sellerid' => I('post.alipay_sellerid'),
|
||
'alipay_private_key' => I('post.alipay_private_key'),
|
||
'alipay_public_key' => I('post.alipay_public_key'),
|
||
);
|
||
break;
|
||
case '4':
|
||
$msg = '服务商模式:编辑微信支付设置';
|
||
$save = array(
|
||
'wx_pay_state' => I('post.wx_pay_state'),
|
||
'wx_sub_appid' => I('post.wx_sub_appid'),
|
||
'wx_sub_mchid' => I('post.wx_sub_mchid'),
|
||
);
|
||
break;
|
||
case '5':
|
||
$msg = '服务商模式:编辑微信小程序支付设置';
|
||
$save = array(
|
||
'xcx_pay_state' => I('post.xcx_pay_state'),
|
||
'xcx_sub_appid' => I('post.xcx_sub_appid'),
|
||
'xcx_sub_mchid' => I('post.xcx_sub_mchid'),
|
||
'balance' => I('post.balance'),
|
||
);
|
||
break;
|
||
case '6':
|
||
$msg = '服务商模式:编辑支付宝支付设置';
|
||
$save = array(
|
||
'al_pay_state' => I('post.al_pay_state'),
|
||
'alipay_sellerid' => I('post.alipay_sellerid'),
|
||
'alipay_token' => I('post.alipay_token')
|
||
);
|
||
break;
|
||
case '7':
|
||
$msg = '新大陆支付模式:编辑微信支付设置';
|
||
$save = array(
|
||
'wx_pay_state' => I('post.wx_pay_state')
|
||
);
|
||
$upWx = array(
|
||
'wx_appid' => I('post.wx_appid'),
|
||
'wx_appkey' => I('post.wx_appkey'),
|
||
'wx_publicappid' => I('post.wx_publicappid'),//公众号支付完成推荐关注公众号appid
|
||
'wx_type' => 1
|
||
);
|
||
break;
|
||
case '8':
|
||
$msg = '新大陆支付模式:编辑微信小程序支付设置';
|
||
$save = array(
|
||
'xcx_pay_state' => I('post.xcx_pay_state'),
|
||
'balance' => I('post.balance')
|
||
);
|
||
$upWx = array(
|
||
'xcc_appid' => I('post.xcc_appid'),
|
||
'xcc_appkey' => I('post.xcc_appkey'),
|
||
'xcc_publicappid' => I('post.xcc_publicappid'),//小程序首页推荐关注公众号appid
|
||
'wx_type' => 2
|
||
);
|
||
break;
|
||
case '9':
|
||
//新大陆支付宝
|
||
$msg = '新大陆支付模式:编辑支付宝支付设置';
|
||
$save = array(
|
||
'al_pay_state' => I('post.al_pay_state')
|
||
);
|
||
break;
|
||
case '10':
|
||
//新大陆已进件填写参数
|
||
$save_xdl = array(
|
||
'merc_nm' => I('post.merc_nm'),
|
||
'merc_id' => I('post.merc_id'),
|
||
'stoe_id' => I('post.stoe_id'),
|
||
'trm_no' => I('post.trm_no'),
|
||
'key' => I('post.key'),
|
||
'status' => 1,
|
||
'mer_status' => 1
|
||
);
|
||
break;
|
||
case '11':
|
||
//云闪付
|
||
$msg = '云闪付支付模式:设置云闪付商户号';
|
||
$post = I('post.');
|
||
$save = array(
|
||
'al_pay_state' => $post['al_pay_state'],
|
||
'wx_pay_state' => $post['wx_pay_state'],
|
||
'xcx_pay_state' => $post['xcx_pay_state'],
|
||
'cloud_mer_id' => $post['cloud_mer_id'],
|
||
'cloud_sub_appid' => $post['cloud_sub_appid'],
|
||
'cloud_xcx_appid' => $post['cloud_xcx_appid'],
|
||
'balance' => $post['balance'],
|
||
);
|
||
break;
|
||
case '12':
|
||
//乐返
|
||
$msg = '乐返支付模式:设置乐返商户号';
|
||
$post = I('post.');
|
||
$save = array(
|
||
'al_pay_state' => $post['al_pay_state'],//支付宝支付模式 0关闭 1普通商户 2服务商 3新大陆 4 云闪付,5:乐返
|
||
'wx_pay_state' => $post['wx_pay_state'],//微信模式 0关闭 1普通商户 2服务商 3新大陆 4 云闪付,5:乐返
|
||
'xcx_pay_state' => $post['xcx_pay_state'],//小程序支付 0关闭 1普通 2服务商 3新大陆 4 云闪付,5:乐返
|
||
'happy_pay_num' => $post['happy_pay_num'],//乐返支付商户编号
|
||
'happy_pay_appid' => $post['happy_pay_appid'],//乐返商户小程序appId
|
||
'happy_pay_app_secret' => $post['happy_pay_app_secret'],//乐返商户小程序密钥
|
||
'balance' => $post['balance'],
|
||
);
|
||
break;
|
||
case '13':
|
||
//拉卡拉
|
||
$msg = '拉卡拉支付模式:设置拉卡拉商户号';
|
||
$post = I('post.');
|
||
$save = array(
|
||
'al_pay_state' => $post['al_pay_state'],//支付宝支付模式 0关闭 1普通商户 2服务商 3新大陆 4 云闪付,5:乐返,6:拉卡拉
|
||
'wx_pay_state' => $post['wx_pay_state'],//微信模式 0关闭 1普通商户 2服务商 3新大陆 4 云闪付,5:乐返,6:拉卡拉
|
||
'xcx_pay_state' => $post['xcx_pay_state'],//小程序支付 0关闭 1普通 2服务商 3新大陆 4 云闪付,5:乐返,6:拉卡拉
|
||
'lakala_pay_num' => $post['lakala_pay_num'],//拉卡拉商户号
|
||
'lakala_pay_appid' => $post['lakala_pay_appid'],//拉卡拉商户小程序appId
|
||
'balance' => $post['balance'],
|
||
);
|
||
break;
|
||
case '14':
|
||
//钱客云
|
||
$msg = '钱客云支付模式:设置钱客云商户号';
|
||
$post = I('post.');
|
||
$save = array(
|
||
'al_pay_state' => $post['al_pay_state'],//支付宝支付模式 0关闭 1普通商户 2服务商 3新大陆 4 云闪付,5:乐返,6:拉卡拉,7:钱客云
|
||
'wx_pay_state' => $post['wx_pay_state'],//微信模式 0关闭 1普通商户 2服务商 3新大陆 4 云闪付,5:乐返,6:拉卡拉,7:钱客云
|
||
'xcx_pay_state' => $post['xcx_pay_state'],//小程序支付 0关闭 1普通 2服务商 3新大陆 4 云闪付,5:乐返,6:拉卡拉,7:钱客云
|
||
'qian_ke_mid' => $post['qian_ke_mid'],//钱客云商户ID
|
||
'qian_ke_key' => $post['qian_ke_key'],//钱客云商户密钥
|
||
'qian_ke_app_id' => $post['qian_ke_app_id'],//钱客云小程序appid
|
||
'qian_ke_public_appid' => $post['qian_ke_public_appid'],//钱客云小程序appid
|
||
'balance' => $post['balance'],
|
||
);
|
||
break;
|
||
default:
|
||
$res['status'] = 0;
|
||
$res['msg'] = '提交类型有误';
|
||
}
|
||
if ($save['xcx_pay_state'] && $save['xcx_pay_state'] != 0) {
|
||
$save['xcx_wxpay'] = 1;
|
||
} else if ($save['xcx_pay_state'] === 0 || $save['xcx_pay_state'] === '0') {
|
||
$save['xcx_wxpay'] = 2;
|
||
}
|
||
$paySet = M('retail_payset')->where(array('merchantid' => $merchant_id, 'storeid' => $store_id))->find();
|
||
if (!empty($paySet)) {
|
||
$update = M('retail_payset')->where(array('merchantid' => $merchant_id, 'storeid' => $store_id))->save($save);
|
||
} else {
|
||
$save['storeid'] = $store_id;
|
||
$save['merchantid'] = $merchant_id;
|
||
$update = M('retail_payset')->add($save);
|
||
}
|
||
if (!empty($upWx)) {
|
||
$info = M('merchant_infos')->where(array('merchant_id' => $merchant_id))->find();
|
||
if (!empty($info)) {
|
||
$updateItem = array();
|
||
if ($upWx['wx_type'] == 1) {
|
||
if ($info['wx_appid'] != $upWx['wx_appid'] || $info['wx_appkey'] != $upWx['wx_appkey'] || $info['wx_publicappid'] != $upWx['wx_publicappid']) {
|
||
$isPost = true;
|
||
$updateItem = array(
|
||
'Appid' => $upWx['wx_appid'],
|
||
'appkey' => $upWx['wx_appkey'],
|
||
'PUBLIC_Appid' => $upWx['wx_publicappid'],
|
||
'WX_TYPE' => '1',
|
||
);
|
||
} else {
|
||
$isPost = false;
|
||
}
|
||
} else {
|
||
if ($info['xcc_appid'] != $upWx['xcc_appid'] || $info['xcc_appkey'] != $upWx['xcc_appkey'] || $info['xcc_publicappid'] != $upWx['xcc_publicappid']) {
|
||
$isPost = true;
|
||
$updateItem = array(
|
||
'Appid' => $upWx['xcc_appid'],
|
||
'appkey' => $upWx['xcc_appkey'],
|
||
'PUBLIC_Appid' => $upWx['xcc_publicappid'],
|
||
'WX_TYPE' => '2',
|
||
);
|
||
} else {
|
||
$isPost = false;
|
||
}
|
||
}
|
||
if ($isPost) {
|
||
$merchant_type = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->getField('merchant_type');
|
||
if ($merchant_type == 1) {
|
||
$updateItem['stoe_id'] = $info['stoe_id'];
|
||
$updateNew = $this->updateAppId($updateItem);
|
||
} else {
|
||
$updateNew['status'] = 1;
|
||
}
|
||
if ($updateNew['status'] == 1) {
|
||
unset($upWx['wx_type']);
|
||
$update1 = M('merchant_infos')->where(array('merchant_id' => $merchant_id))->save($upWx);
|
||
if ($update1) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '配置成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '保存失败';
|
||
}
|
||
} else {
|
||
$res = $updateNew;
|
||
$res['status'] = 2;
|
||
$res['updateNew'] = $updateNew;
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '您未修改数据2';
|
||
}
|
||
} else {
|
||
$res['status'] = 2;
|
||
$res['msg'] = '该商户未申请新大陆支付模式';
|
||
}
|
||
}
|
||
if (!empty($save_xdl)) {
|
||
$mer_status = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->save($save_xdl);
|
||
$mer_info = M('merchant_infos')->where(array('merchant_id' => $merchant_id))->save($save_xdl);
|
||
if ($mer_status || $mer_info) {
|
||
$update = true;
|
||
}
|
||
}
|
||
if ($update || $res['status'] == 1) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '保存成功';
|
||
|
||
//操作日志记录
|
||
$source = 0;//请求来源: 0pc系统 1小助手
|
||
$type = session('jurisdiction_user')['login_type'];//平台:1合伙人端 2代理商端 3商户端 4门店端
|
||
$request_data = json_encode($_POST);//请求参数 json数据
|
||
$desc = $msg;//操作行为描述
|
||
action_log($source, $type, $request_data, $desc);
|
||
//end
|
||
} else if ($res['status'] == 2) {
|
||
$res['status'] = 0;
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '您未修改数据3';
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 已有新大陆商户,直接配置
|
||
* @param $merchant_id
|
||
* @return mixed
|
||
*/
|
||
public function customSettings($merchant_id)
|
||
{
|
||
$post = I('post.');
|
||
$map = array(
|
||
'merchant_id' => $merchant_id
|
||
);
|
||
$entryItem['merchant_id'] = $merchant_id;
|
||
$entryItem['merc_nm'] = $post['merc_nm']; //商户名称
|
||
$entryItem['merc_id'] = $post['merc_id']; //商户号
|
||
$entryItem['stoe_id'] = $post['stoe_id'];//门店id
|
||
$entryItem['entry_status'] = 1;
|
||
$entryItem['mer_status'] = 1;
|
||
$entryItem['status'] = 1;
|
||
$entryItem['merchant_type'] = 2;
|
||
$entry = M('merchant_entry')->where($map)->find();
|
||
if (empty($entry)) {
|
||
$res1 = M('merchant_entry')->add($entryItem);
|
||
} else {
|
||
M('merchant_entry')->where($map)->save($entryItem);
|
||
$res1 = $entry['id'];
|
||
}
|
||
$infoItem['merchant_id'] = $merchant_id;
|
||
$infoItem['entry_id'] = $res1;
|
||
$infoItem['key'] = $post['key'];
|
||
$infoItem['trm_no'] = $post['trm_no'];
|
||
$infoItem['merc_nm'] = $post['merc_nm']; //商户名称
|
||
$infoItem['merc_id'] = $post['merc_id']; //商户号
|
||
$infoItem['stoe_id'] = $post['stoe_id'];//门店id
|
||
$map = array(
|
||
'merchant_id' => $merchant_id,
|
||
'entry_id' => $res1,
|
||
);
|
||
$info = M('merchant_infos')->where($map)->find();
|
||
if (!empty($info)) {
|
||
$res2 = M('merchant_infos')->where($map)->save($infoItem);
|
||
} else {
|
||
$res2 = M('merchant_infos')->add($infoItem);
|
||
}
|
||
if ($res1 && $res2) {
|
||
$result['status'] = 1;
|
||
$result['msg'] = '配置成功';
|
||
} else {
|
||
$result['status'] = 0;
|
||
$result['msg'] = '配置失败';
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 初始新大陆进件信息
|
||
* @param $merchant_id 商户id
|
||
* @return array
|
||
*/
|
||
public function initialNewPaySet($merchant_id)
|
||
{
|
||
// 查询
|
||
$entry = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->find();
|
||
if (empty($entry)) {
|
||
$res = array('status' => 2, 'msg' => '暂无进件信息');
|
||
return $res;
|
||
}
|
||
$res['applyStatus'] = $entry['mer_status'];
|
||
$res['applyMsg'] = $entry['hang_air'];
|
||
// 查询图片信息
|
||
$new_img = M('merchant_img')->where(array('entry_id' => $entry['id']))->find();
|
||
// 商户基本资料
|
||
$infoForm = array(
|
||
'merc_nm' => $entry['merc_nm'] ? $entry['merc_nm'] : '',
|
||
'scan_stoe_cnm' => $entry['scan_stoe_cnm'] ? $entry['scan_stoe_cnm'] : '',
|
||
'stoe_cnt_nm' => $entry['stoe_cnt_nm'] ? $entry['stoe_cnt_nm'] : '',
|
||
'stoe_cnt_tel' => $entry['stoe_cnt_tel'] ? $entry['stoe_cnt_tel'] : '',
|
||
'mailbox' => $entry['mailbox'] ? $entry['mailbox'] : '',
|
||
'mcc_cd' => $entry['mcc_cd'] ? $entry['mcc_cd'] : '',
|
||
'province' => $entry['province'] ? $entry['province'] : '',
|
||
'city' => $entry['city'] ? $entry['city'] : '',
|
||
'stoe_area_cod' => $entry['stoe_area_cod'] ? $entry['stoe_area_cod'] : '',
|
||
'stoe_adds' => $entry['stoe_adds'] ? $entry['stoe_adds'] : '',
|
||
);
|
||
$res['infoForm'] = $infoForm;
|
||
// 进件类型
|
||
$incomeForm = array(
|
||
'incom_type' => $entry['incom_type'] ? $entry['incom_type'] : '1',
|
||
'wx_appid' => $entry['wx_appid'] ? $entry['wx_appid'] : '',
|
||
'wx_appsecrect' => $entry['wx_appsecrect'] ? $entry['wx_appsecrect'] : '',
|
||
'recom_wx_appid' => $entry['recom_wx_appid'] ? $entry['recom_wx_appid'] : '',
|
||
'wx_pay_catalog' => $entry['wx_pay_catalog'] ? $entry['wx_pay_catalog'] : '',
|
||
);
|
||
$res['incomeForm'] = $incomeForm;
|
||
// 银行结算信息
|
||
$bankInfoForm = array(
|
||
'bank_name' => $entry['bank_name'] ? $entry['bank_name'] : '',
|
||
'wc_lbnk_name' => $entry['wc_lbnk_name'] ? $entry['wc_lbnk_name'] : '',
|
||
'wc_lbnk_no' => $entry['wc_lbnk_no'] ? $entry['wc_lbnk_no'] : '',
|
||
'stl_sign' => $entry['stl_sign'] ? $entry['stl_sign'] : '0',
|
||
'stl_oac' => $entry['stl_oac'] ? $entry['stl_oac'] : '',
|
||
'bnk_acnm' => $entry['bnk_acnm'] ? $entry['bnk_acnm'] : '',
|
||
'icrp_id_no' => $entry['icrp_id_no'] ? $entry['icrp_id_no'] : '',
|
||
'crp_start_dt' => $entry['crp_start_dt'] ? $entry['crp_start_dt'] : '',
|
||
'crp_end_dt' => $entry['crp_end_dt'] ? $entry['crp_end_dt'] : '',
|
||
'crp_end_dt_permanent' => false,
|
||
'settlement' => !empty($new_img) && $new_img['settlement'] ? $new_img['settlement'] : '',
|
||
'settlement_side' => !empty($new_img) && $new_img['settlement_side'] ? $new_img['settlement_side'] : '',
|
||
'bank_card' => !empty($new_img) && $new_img['bank_card'] ? $new_img['bank_card'] : '',
|
||
'power' => !empty($new_img) && $new_img['power'] ? $new_img['power'] : '',
|
||
'group' => !empty($new_img) && $new_img['group'] ? $new_img['group'] : '',
|
||
);
|
||
if (!empty($bankInfoForm['bank_name'])) {
|
||
$bankInfoForm['bank_name_str'] = M('bank')->where(array('id' => $bankInfoForm['bank_name']))->getField('bank_name');
|
||
}
|
||
$res['bankInfoForm'] = $bankInfoForm;
|
||
// 营业执照信息
|
||
$businessLicenseForm = array(
|
||
'bus_lic_no' => $entry['bus_lic_no'] ? $entry['bus_lic_no'] : '',
|
||
'bse_lice_nm' => $entry['bse_lice_nm'] ? $entry['bse_lice_nm'] : '',
|
||
'merc_adds' => $entry['merc_adds'] ? $entry['merc_adds'] : '',
|
||
'bus_eff_dt' => $entry['bus_eff_dt'] ? $entry['bus_eff_dt'] : '',
|
||
'bus_exp_dt' => $entry['bus_exp_dt'] ? $entry['bus_exp_dt'] : '',
|
||
'bus_exp_dt_permanent' => false,
|
||
'crp_nm' => $entry['crp_nm'] ? $entry['crp_nm'] : '',
|
||
'crp_id_no' => $entry['crp_id_no'] ? $entry['crp_id_no'] : '',
|
||
'crp_eff_dt' => $entry['crp_eff_dt'] ? $entry['crp_eff_dt'] : '',
|
||
'crp_exp_dt' => $entry['crp_exp_dt'] ? $entry['crp_exp_dt'] : '',
|
||
'crp_exp_dt_permanent' => false,
|
||
'license' => !empty($new_img) && $new_img['license'] ? $new_img['license'] : '',
|
||
'identity_card' => !empty($new_img) && $new_img['identity_card'] ? $new_img['identity_card'] : '',
|
||
'identity_card_side' => !empty($new_img) && $new_img['identity_card_side'] ? $new_img['identity_card_side'] : '',
|
||
'door_head' => !empty($new_img) && $new_img['door_head'] ? $new_img['door_head'] : '',
|
||
'interior' => !empty($new_img) && $new_img['interior'] ? $new_img['interior'] : '',
|
||
'mer_info' => !empty($new_img) && $new_img['mer_info'] ? $new_img['mer_info'] : '',
|
||
'mer_info_2' => !empty($new_img) && $new_img['mer_info_2'] ? $new_img['mer_info_2'] : '',
|
||
'agreement' => !empty($new_img) && $new_img['agreement'] ? $new_img['agreement'] : '',
|
||
'agreement_2' => !empty($new_img) && $new_img['agreement_2'] ? $new_img['agreement_2'] : '',
|
||
'agreement_3' => !empty($new_img) && $new_img['agreement_3'] ? $new_img['agreement_3'] : '',
|
||
'agreement_4' => !empty($new_img) && $new_img['agreement_4'] ? $new_img['agreement_4'] : '',
|
||
);
|
||
$res['businessLicenseForm'] = $businessLicenseForm;
|
||
// 检查并提交
|
||
$all_data = array_merge($infoForm, $incomeForm, $bankInfoForm, $businessLicenseForm);
|
||
$merchant_rate = M('retail_merchant')->where(array('id' => $merchant_id))->getField('merchant_rate');
|
||
if ($merchant_rate) {
|
||
$merchant_rate = floatval($merchant_rate);
|
||
}
|
||
$all_data['merchant_rate'] = $merchant_rate;
|
||
// 处理数据
|
||
// 经营类目
|
||
$all_data['mcc_nm'] = M('mcc')->where(array('mcc_cd' => $all_data['mcc_cd']))->getField('mcc_nm');
|
||
$res['all_data'] = $all_data;
|
||
$res['status'] = 1;
|
||
$res['entry_status'] = $entry['entry_status'];
|
||
$res['step'] = $entry['step'];
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取经营类目
|
||
* @return array
|
||
*/
|
||
public function getMccArr()
|
||
{
|
||
// 获取大致分类
|
||
$mcc_group = M('mcc')->field("sup_mcc_cd,sup_mcc_nm")->group("sup_mcc_cd")->select();
|
||
if (empty($mcc_group)) {
|
||
$res = array('status' => 0, 'msg' => '暂无经营类目');
|
||
return $res;
|
||
}
|
||
// 获取下级分类
|
||
$mcc_arr = array();
|
||
foreach ($mcc_group as $key => &$val) {
|
||
$options = M('mcc')->field("mcc_nm,mcc_cd")->where(array('sup_mcc_cd' => $val['sup_mcc_cd']))->select();
|
||
$arr = array('sup_mcc_nm' => $val['sup_mcc_nm'], 'options' => $options);
|
||
array_push($mcc_arr, $arr);
|
||
}
|
||
$res = array('status' => 1, 'mcc_arr' => $mcc_arr);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取省列表
|
||
*/
|
||
public function getProvince()
|
||
{
|
||
$Citys = D('Citys');
|
||
$map = array(
|
||
'state' => 0,
|
||
'parentid' => 0
|
||
);
|
||
$province = $Citys->getListBase($map, 'cityid asc');
|
||
if (empty($province)) {
|
||
$res = array('status' => 0, 'msg' => '暂无数据');
|
||
} else {
|
||
$res = array('status' => 1, 'province' => $province);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取市列表
|
||
* @param $p_id
|
||
* @return array
|
||
*/
|
||
public function getSubordinate($p_id)
|
||
{
|
||
// 查询
|
||
$Citys = D('Citys');
|
||
$map = array(
|
||
'state' => 0,
|
||
'parentid' => $p_id
|
||
);
|
||
$data = $Citys->getListBase($map, 'cityid asc');
|
||
if (empty($data)) {
|
||
$res = array('status' => 0, 'msg' => '暂无数据');
|
||
} else {
|
||
$res = array('status' => 1, 'data' => $data);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
public function getArea()
|
||
{
|
||
$province = I('post.province');
|
||
$city = I('post.city');
|
||
$province_name = M('citys')->where(array('cityid' => $province))->getField('city_name');
|
||
$city_name = M('citys')->where(array('cityid' => $city))->getField('city_name');
|
||
$continent = M('continent_config')->find();
|
||
|
||
$subData['serviceId'] = 6060206;
|
||
$subData['orgNo'] = $continent['continent_number'];
|
||
$subData['version'] = 'V2.0.0';
|
||
$subData['signValue'] = $this->getSign($subData, $continent['continent_pay_secret_key']);
|
||
$subData['provNm'] = $province_name;
|
||
$subData['cityNm'] = $city_name;
|
||
|
||
$data = json_encode($subData);
|
||
$res = $this->http_request($data);
|
||
$response = $this->GBK_decode($res);
|
||
if ($response['msgCd'] == 000000) {
|
||
$result['status'] = 1;
|
||
$result['msg'] = $response['msgDat'];
|
||
$area = array();
|
||
foreach ($response['REC'] as $value) {
|
||
$area[] = array(
|
||
'city_name' => $value['areaNm'],
|
||
'cityid' => $value['mercArea'],
|
||
);
|
||
}
|
||
$result['data'] = $area;
|
||
} else {
|
||
//失败返回接口
|
||
$result['status'] = 0;
|
||
$result['msg'] = $response['msgDat'] ? $response['msgDat'] : '请求失败';
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 获取银行信息
|
||
*/
|
||
public function getBank()
|
||
{
|
||
$bank_info = M('bank')->select();
|
||
if (empty($bank_info)) {
|
||
$res = array('status' => 0, 'msg' => '暂无数据');
|
||
} else {
|
||
$res = array('status' => 1, 'bank_info' => $bank_info);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 获取新大陆联行信息
|
||
* @param $keyword
|
||
* @return mixed
|
||
*/
|
||
/**
|
||
* @param $keyword
|
||
* @param bool $precise
|
||
* @return mixed
|
||
* @throws \think\db\exception\DataNotFoundException
|
||
* @throws \think\db\exception\DbException
|
||
* @throws \think\db\exception\ModelNotFoundException
|
||
* @throws \think\exception\DbException
|
||
*/
|
||
public function getWcLbnkNo($keyword, $precise = false)
|
||
{
|
||
$page = I('post.page') ? I('post.page') : 1;
|
||
if (!empty($keyword)) {
|
||
$map = array(
|
||
'lbnk_nm' => $precise ? $keyword : array('like', '%' . $keyword . '%'),
|
||
);//
|
||
$data = M('interbanknumber')->where($map)->order('id asc')->page($page, 20)->select();
|
||
} else {
|
||
$data = M('interbanknumber')->order('id asc')->page($page, 20)->select();
|
||
}
|
||
|
||
$res['data'] = $data;
|
||
$res['status'] = 1;
|
||
$res['msg'] = '查询成功';
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 保存设置
|
||
* @param $data array 数据
|
||
* @param $step int 步骤
|
||
* @param $merchant_id int 商户id
|
||
* @return array
|
||
*/
|
||
public function updateNewPaySet($data, $step, $merchant_id)
|
||
{
|
||
// 判断
|
||
if (empty($data) || !$step || !$merchant_id) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '缺少必要参数'
|
||
);
|
||
return $res;
|
||
}
|
||
switch ($step) {
|
||
case 1:
|
||
// 验证
|
||
if (!$data['merc_nm'] || !$data['scan_stoe_cnm'] || !$data['stoe_cnt_nm'] || !$data['stoe_cnt_tel'] || !$data['mailbox'] || !$data['mcc_cd'] || !$data['province'] || !$data['city'] || !$data['stoe_area_cod'] || !$data['stoe_adds']) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '请完善基本信息'
|
||
);
|
||
return $res;
|
||
}
|
||
$res = $this->updateInfoForm($data, $step, $merchant_id);
|
||
break;
|
||
case 2:
|
||
// 验证
|
||
if (!$data['incom_type']) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '请完善进件类型'
|
||
);
|
||
return $res;
|
||
}
|
||
$res = $this->updateIncomeForm($data, $step, $merchant_id);
|
||
break;
|
||
case 3:
|
||
// 验证
|
||
if (!$data['bank_name'] || !$data['wc_lbnk_name'] || !$data['wc_lbnk_no'] || !isset($data['stl_sign']) || !$data['stl_oac'] || !$data['bnk_acnm'] || !$data['icrp_id_no'] || !$data['crp_end_dt'] || !$data['crp_start_dt'] || !$data['settlement'] || !$data['settlement_side'] || !$data['bank_card']) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '请完善银行结算信息'
|
||
);
|
||
return $res;
|
||
}
|
||
$res = $this->updateBankInfoForm($data, $step, $merchant_id);
|
||
break;
|
||
case 4:
|
||
// 验证
|
||
if (!$data['bus_lic_no'] || !$data['bse_lice_nm'] || !$data['merc_adds'] || !$data['crp_nm'] || !$data['crp_id_no']) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '请完善营业执照信息'
|
||
);
|
||
return $res;
|
||
}
|
||
$res = $this->updateBusinessLicenseForm($data, $step, $merchant_id);
|
||
break;
|
||
default:
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '未知步骤,建议刷新重试'
|
||
);
|
||
break;
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 保存设置,商户基本信息
|
||
* @param $data array 数据
|
||
* @param $step int 步骤
|
||
* @param $merchant_id int 商户id
|
||
* @return array
|
||
*/
|
||
protected function updateInfoForm($data, $step, $merchant_id)
|
||
{
|
||
$field = array(
|
||
'merc_nm',
|
||
'scan_stoe_cnm',
|
||
'stoe_cnt_nm',
|
||
'stoe_cnt_tel',
|
||
'mailbox',
|
||
'mcc_cd',
|
||
'province',
|
||
'city',
|
||
'stoe_area_cod',
|
||
'stoe_adds',
|
||
'step'
|
||
);
|
||
// 查询商户新大陆进件信息
|
||
$old_entry = M('merchant_entry')->field($field)->where(array('merchant_id' => $merchant_id))->find();
|
||
|
||
if (empty($old_entry)) {
|
||
// 添加
|
||
$data['step'] = $step + 1;
|
||
$data['merchant_id'] = $merchant_id;
|
||
$result = M('merchant_entry')->add($data);
|
||
} else {
|
||
// 修改
|
||
$up = array();
|
||
if ($old_entry['merc_nm'] != $data['merc_nm']) {
|
||
$up['merc_nm'] = $data['merc_nm'];
|
||
}
|
||
if ($old_entry['scan_stoe_cnm'] != $data['scan_stoe_cnm']) {
|
||
$up['scan_stoe_cnm'] = $data['scan_stoe_cnm'];
|
||
}
|
||
if ($old_entry['stoe_cnt_nm'] != $data['stoe_cnt_nm']) {
|
||
$up['stoe_cnt_nm'] = $data['stoe_cnt_nm'];
|
||
}
|
||
if ($old_entry['stoe_cnt_tel'] != $data['stoe_cnt_tel']) {
|
||
$up['stoe_cnt_tel'] = $data['stoe_cnt_tel'];
|
||
}
|
||
if ($old_entry['mailbox'] != $data['mailbox']) {
|
||
$up['mailbox'] = $data['mailbox'];
|
||
}
|
||
if ($old_entry['mcc_cd'] != $data['mcc_cd']) {
|
||
$up['mcc_cd'] = $data['mcc_cd'];
|
||
}
|
||
if ($old_entry['province'] != $data['province']) {
|
||
$up['province'] = $data['province'];
|
||
}
|
||
if ($old_entry['city'] != $data['city']) {
|
||
$up['city'] = $data['city'];
|
||
}
|
||
if ($old_entry['stoe_area_cod'] != $data['stoe_area_cod']) {
|
||
$up['stoe_area_cod'] = $data['stoe_area_cod'];
|
||
}
|
||
if ($old_entry['stoe_adds'] != $data['stoe_adds']) {
|
||
$up['stoe_adds'] = $data['stoe_adds'];
|
||
}
|
||
if (empty($up) && round($step + 1) == $old_entry['step']) {
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '无需修改'
|
||
);
|
||
return $res;
|
||
}
|
||
$up['step'] = $step + 1;
|
||
$result = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->save($up);
|
||
}
|
||
if ($result) {
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '保存成功'
|
||
);
|
||
} else {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '保存失败'
|
||
);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 保存设置,商户基本信息
|
||
* @param $data array 数据
|
||
* @param $step int 步骤
|
||
* @param $merchant_id int 商户id
|
||
* @return array
|
||
*/
|
||
protected function updateIncomeForm($data, $step, $merchant_id)
|
||
{
|
||
$field = array(
|
||
'incom_type',
|
||
'wx_appid',
|
||
'wx_appsecrect',
|
||
'recom_wx_appid',
|
||
'wx_pay_catalog',
|
||
'step'
|
||
);
|
||
// 查询商户新大陆进件信息
|
||
$old_entry = M('merchant_entry')->field($field)->where(array('merchant_id' => $merchant_id))->find();
|
||
// 判断
|
||
if (empty($old_entry)) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '进件信息查询失败'
|
||
);
|
||
return $res;
|
||
}
|
||
// 修改
|
||
$up = array();
|
||
if ($old_entry['incom_type'] != $data['incom_type']) {
|
||
$up['incom_type'] = $data['incom_type'];
|
||
}
|
||
if ($old_entry['wx_appid'] != $data['wx_appid']) {
|
||
$up['wx_appid'] = $data['wx_appid'];
|
||
}
|
||
if ($old_entry['wx_appsecrect'] != $data['wx_appsecrect']) {
|
||
$up['wx_appsecrect'] = $data['wx_appsecrect'];
|
||
}
|
||
if ($old_entry['recom_wx_appid'] != $data['recom_wx_appid']) {
|
||
$up['recom_wx_appid'] = $data['recom_wx_appid'];
|
||
}
|
||
if ($old_entry['wx_pay_catalog'] != $data['wx_pay_catalog']) {
|
||
$up['wx_pay_catalog'] = $data['wx_pay_catalog'];
|
||
}
|
||
if (empty($up) && round($step + 1) == $old_entry['step']) {
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '无需修改'
|
||
);
|
||
return $res;
|
||
}
|
||
$up['step'] = $step + 1;
|
||
$result = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->save($up);
|
||
if ($result) {
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '保存成功'
|
||
);
|
||
} else {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '保存失败'
|
||
);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 保存设置,银行结算信息
|
||
* @param $data array 数据
|
||
* @param $step int 步骤
|
||
* @param $merchant_id int 商户id
|
||
* @return array
|
||
*/
|
||
protected function updateBankInfoForm($data, $step, $merchant_id)
|
||
{
|
||
$field = array(
|
||
'bank_name',
|
||
'wc_lbnk_name',
|
||
'wc_lbnk_no',
|
||
'stl_sign',
|
||
'stl_oac',
|
||
'bnk_acnm',
|
||
'icrp_id_no',
|
||
'crp_start_dt',
|
||
'crp_end_dt',
|
||
'step'
|
||
);
|
||
// 查询商户新大陆进件信息
|
||
$old_entry = M('merchant_entry')->field($field)->where(array('merchant_id' => $merchant_id))->find();
|
||
// 判断
|
||
if (empty($old_entry)) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '进件信息查询失败'
|
||
);
|
||
return $res;
|
||
}
|
||
// 修改
|
||
$up = array();
|
||
if ($old_entry['bank_name'] != $data['bank_name']) {
|
||
$up['bank_name'] = $data['bank_name'];
|
||
}
|
||
if ($old_entry['wc_lbnk_name'] != $data['wc_lbnk_name']) {
|
||
$up['wc_lbnk_name'] = $data['wc_lbnk_name'];
|
||
}
|
||
if ($old_entry['wc_lbnk_no'] != $data['wc_lbnk_no']) {
|
||
$up['wc_lbnk_no'] = $data['wc_lbnk_no'];
|
||
}
|
||
if ($old_entry['stl_sign'] != $data['stl_sign']) {
|
||
$up['stl_sign'] = $data['stl_sign'];
|
||
}
|
||
if ($old_entry['stl_oac'] != $data['stl_oac']) {
|
||
$up['stl_oac'] = $data['stl_oac'];
|
||
}
|
||
if ($old_entry['bnk_acnm'] != $data['bnk_acnm']) {
|
||
$up['bnk_acnm'] = $data['bnk_acnm'];
|
||
}
|
||
if ($old_entry['icrp_id_no'] != $data['icrp_id_no']) {
|
||
$up['icrp_id_no'] = $data['icrp_id_no'];
|
||
}
|
||
if ($old_entry['crp_start_dt'] != $data['crp_start_dt']) {
|
||
$up['crp_start_dt'] = $data['crp_start_dt'];
|
||
}
|
||
if ($old_entry['crp_end_dt'] != $data['crp_end_dt']) {
|
||
$up['crp_end_dt'] = $data['crp_end_dt'];
|
||
}
|
||
if (empty($up) && round($step + 1) == $old_entry['step']) {
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '无需修改'
|
||
);
|
||
return $res;
|
||
}
|
||
$up['step'] = $step + 1;
|
||
$result = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->save($up);
|
||
if ($result) {
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '保存成功'
|
||
);
|
||
} else {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '保存失败'
|
||
);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 保存设置,营业执照信息
|
||
* @param $data array 数据
|
||
* @param $step int 步骤
|
||
* @param $merchant_id int 商户id
|
||
* @return array
|
||
*/
|
||
protected function updateBusinessLicenseForm($data, $step, $merchant_id)
|
||
{
|
||
$field = array(
|
||
'bus_lic_no',
|
||
'bse_lice_nm',
|
||
'merc_adds',
|
||
'bus_eff_dt',
|
||
'bus_exp_dt',
|
||
'crp_nm',
|
||
'crp_id_no',
|
||
'crp_eff_dt',
|
||
'crp_exp_dt',
|
||
'step'
|
||
);
|
||
// 查询商户新大陆进件信息
|
||
$old_entry = M('merchant_entry')->field($field)->where(array('merchant_id' => $merchant_id))->find();
|
||
// 判断
|
||
if (empty($old_entry)) {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '进件信息查询失败'
|
||
);
|
||
return $res;
|
||
}
|
||
// 修改
|
||
$up = array();
|
||
if ($old_entry['bus_lic_no'] != $data['bus_lic_no']) {
|
||
$up['bus_lic_no'] = $data['bus_lic_no'];
|
||
}
|
||
if ($old_entry['bse_lice_nm'] != $data['bse_lice_nm']) {
|
||
$up['bse_lice_nm'] = $data['bse_lice_nm'];
|
||
}
|
||
if ($old_entry['merc_adds'] != $data['merc_adds']) {
|
||
$up['merc_adds'] = $data['merc_adds'];
|
||
}
|
||
if ($old_entry['bus_eff_dt'] != $data['bus_eff_dt']) {
|
||
$up['bus_eff_dt'] = $data['bus_eff_dt'];
|
||
}
|
||
if ($old_entry['bus_exp_dt'] != $data['bus_exp_dt']) {
|
||
$up['bus_exp_dt'] = $data['bus_exp_dt'];
|
||
}
|
||
if ($old_entry['crp_nm'] != $data['crp_nm']) {
|
||
$up['crp_nm'] = $data['crp_nm'];
|
||
}
|
||
if ($old_entry['crp_id_no'] != $data['crp_id_no']) {
|
||
$up['crp_id_no'] = $data['crp_id_no'];
|
||
}
|
||
if ($old_entry['crp_eff_dt'] != $data['crp_eff_dt']) {
|
||
$up['crp_eff_dt'] = $data['crp_eff_dt'];
|
||
}
|
||
if ($old_entry['crp_exp_dt'] != $data['crp_exp_dt']) {
|
||
$up['crp_exp_dt'] = $data['crp_exp_dt'];
|
||
}
|
||
if (empty($up) && round($step + 1) == $old_entry['step']) {
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '无需修改'
|
||
);
|
||
return $res;
|
||
}
|
||
$up['step'] = $step + 1;
|
||
$result = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->save($up);
|
||
if ($result) {
|
||
$res = array(
|
||
'status' => 1,
|
||
'msg' => '保存成功'
|
||
);
|
||
} else {
|
||
$res = array(
|
||
'status' => 0,
|
||
'msg' => '保存失败'
|
||
);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 1. 新大陆商户进件(或修改资料提交)
|
||
* @param $merchant_id
|
||
* @return bool|mixed
|
||
*/
|
||
public function toIncomingParts($merchant_id)
|
||
{
|
||
$entry = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->find();
|
||
$continent = M('continent_config')->find();
|
||
$merchant_rate = M('retail_merchant')->where(array('id' => $merchant_id))->getField('merchant_rate');
|
||
$merchant_rate = floatval($merchant_rate);
|
||
$subData = array();
|
||
if (!empty($entry['log_no']) && !empty($entry["merc_id"]) && !empty($entry["stoe_id"])) {
|
||
$service_id = '6060604';
|
||
$subData['logNo'] = $entry["log_no"];
|
||
$subData['mercId'] = $entry["merc_id"];
|
||
$subData['stoeId'] = $entry["stoe_id"];
|
||
} else {
|
||
$service_id = '6060601';
|
||
$subData['mccCd'] = $entry["mcc_cd"];
|
||
}
|
||
$subData['serviceId'] = $service_id;//交易码
|
||
$subData['version'] = 'V2.0.0';//版本号
|
||
$subData['incomType'] = $entry['incom_type'];//进件类型
|
||
$subData['stlTyp'] = 1;//结算类型
|
||
$subData['scanStoeCnm'] = $entry['scan_stoe_cnm'];//商户简称
|
||
$subData['stlSign'] = $entry['stl_sign'];//结算标志 1对私 0对公
|
||
$subData['orgNo'] = $continent['continent_number'];
|
||
$subData['stlOac'] = $entry['stl_oac'];
|
||
$subData['bnkAcnm'] = $entry['bnk_acnm'];
|
||
$subData['wcLbnkNo'] = $entry['wc_lbnk_no'];
|
||
$subData['stoeNm'] = $this->getStoeNm($entry['province'], $entry['city'], $entry['merc_nm']);//签购单名称
|
||
$subData['stoeCntNm'] = $entry['stoe_cnt_nm'];
|
||
$subData['stoeCntCardid'] = $entry['icrp_id_no'];
|
||
$subData['stoeCntTel'] = $entry['stoe_cnt_tel'];
|
||
$subData['stoeAreaCod'] = $entry['stoe_area_cod'];
|
||
$subData['stoeAdds'] = $entry['stoe_adds'];//商户详细地址
|
||
$subData['alipayFlg'] = "Y";//扫码产品
|
||
$subData['yhkpayFlg'] = "N";//银行卡产品
|
||
//必填的数据先生成签名
|
||
$subData['signValue'] = $this->getSign($subData, $continent['continent_pay_secret_key']);
|
||
|
||
$subData['mailbox'] = $entry['mailbox'];//联系人邮箱
|
||
$subData['mercNm'] = $entry['merc_nm'];//商户全称(商户经营名称)
|
||
if ($subData['incom_type'] == 2) {
|
||
$subData['wxAppid'] = $entry['wx_appid'];
|
||
$subData['wxAppsecrect'] = $entry['wx_appsecrect'];
|
||
$subData['wxPayCatalog'] = $entry['wx_pay_catalog'];
|
||
$subData['recomWxAppid'] = $entry['recom_wx_appid'];
|
||
}
|
||
$subData['icrpIdNo'] = $entry['icrp_id_no'];//结算人身份证号
|
||
$subData['crpStartDt'] = $entry["crp_start_dt"];//结算人身份证起始日期
|
||
$subData['crpEndDt'] = $entry["crp_end_dt"];//结算人身份证有限期
|
||
$subData['busLicNo'] = $entry['bus_lic_no'];//营业执照号
|
||
$subData['bseLiceNm'] = $entry['bse_lice_nm'];//商户注册名
|
||
$subData['crpNm'] = $entry['crp_nm'];//法人姓名
|
||
$subData['mercAdds'] = $entry['merc_adds'];//营业执照地址
|
||
$subData['busEffDt'] = $entry["bus_eff_dt"];//营业执照起始日期
|
||
$subData['busExpDt'] = $entry["bus_exp_dt"];//营业执照有限期
|
||
$subData['crpIdNo'] = $entry['crp_id_no'];//法人身份证
|
||
$subData['crpEffDt'] = $entry['crp_eff_dt'];//法人身份证起始日期
|
||
$subData['crpExpDt'] = $entry['crp_exp_dt'];//法人身份证有限期
|
||
$subData['trmRec'] = 1;//终端数量
|
||
$subData['feeRatScan'] = $merchant_rate; //微信费率
|
||
$subData['feeRat3Scan'] = $merchant_rate; //支付宝费率
|
||
|
||
// file_put_contents('./xdl123.txt', date('Y-m-d H:i:s') . ': ' . json_encode($subData) . "\r\n", FILE_APPEND);
|
||
//触发提交第一次商户审核事件
|
||
$jsonData = json_encode($subData);
|
||
$re = $this->http_request($jsonData);
|
||
$result = $this->GBK_decode($re);
|
||
if ($result['msgCd'] == "000000") {
|
||
$save = array(
|
||
'log_no' => $result['logNo'],
|
||
'merc_id' => $result['mercId'],
|
||
'entry_status' => 1,
|
||
'mer_status' => 6,
|
||
'merchant_type' => 1,
|
||
);
|
||
if (!empty($result['stoeId'])) {
|
||
$save['stoe_id'] = $result['stoeId'];
|
||
}
|
||
M('merchant_entry')->where(array('merchant_id' => $merchant_id))->save($save);
|
||
$result['status'] = 1;
|
||
$result['msg'] = $result['msgDat'];
|
||
} else {
|
||
//失败返回接口
|
||
$result['status'] = 0;
|
||
$result['msg'] = $result['msgDat'] ? $result['msgDat'] : '提交进件失败';
|
||
}
|
||
// $result['post'] = $subData;
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 生成签购单名称
|
||
* @param $province
|
||
* @param $city
|
||
* @param $storeName
|
||
* @return string
|
||
*/
|
||
protected function getStoeNm($province, $city, $storeName)
|
||
{
|
||
$provinceName = M('citys')->where(array("cityid" => $province))->getField('city_name');
|
||
$cityName = M('citys')->where(array("cityid" => $city))->getField('city_name');
|
||
return $provinceName . $cityName . $storeName;
|
||
}
|
||
|
||
/**
|
||
* 2. 新大陆进件商户提交
|
||
* @param $merchant_id
|
||
* @return bool|mixed
|
||
*/
|
||
public function submitApply($merchant_id)
|
||
{
|
||
$entry = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->find();
|
||
$continent = M('continent_config')->find();
|
||
$uploadImg = $this->uploadsImage($entry, $continent);
|
||
if ($uploadImg['status'] != 1) {
|
||
return $uploadImg;
|
||
}
|
||
$subData = array();
|
||
$subData['serviceId'] = '6060603';//交易码
|
||
$subData['version'] = 'V2.0.0';//版本号
|
||
$subData['mercId'] = $entry["merc_id"];
|
||
$subData['logNo'] = $entry["log_no"];
|
||
$subData['orgNo'] = $continent['continent_number'];
|
||
//必填的数据先生成签名
|
||
$subData['signValue'] = $this->getSign($subData, $continent['continent_pay_secret_key']);
|
||
|
||
//触发提交第一次商户审核事件
|
||
$jsonData = json_encode($subData);
|
||
$re = $this->http_request($jsonData);
|
||
$result = $this->GBK_decode($re);
|
||
if ($result['msgCd'] == "000000") {
|
||
$eMap = array(
|
||
'merchant_id' => $merchant_id
|
||
);
|
||
$save['merc_id'] = $result['mercId'];
|
||
if ($result['checkFlag'] == 1) {
|
||
//审核通过
|
||
$merInfos['merchant_id'] = $merchant_id;
|
||
$merInfos['entry_id'] = $entry['id'];
|
||
$merInfos['stoe_id'] = $result['REC'][0]['stoeId'];
|
||
$merInfos['merc_id'] = $result['mercId'];
|
||
$merInfos['log_no'] = $result['logNo'];
|
||
$merInfos['key'] = $result['key'];
|
||
$merInfos['trm_no'] = $result['REC'][0]['trmNo'];
|
||
$map = array(
|
||
'entry_id' => $entry['id']
|
||
);
|
||
$oldInfo = M('merchant_infos')->where($map)->find();
|
||
if (!empty($oldInfo)) {
|
||
M('merchant_infos')->where($map)->save($merInfos);
|
||
} else {
|
||
M('merchant_infos')->add($merInfos);
|
||
}
|
||
$save['key'] = $result['key'];
|
||
$save['stoe_id'] = $result['REC'][0]['stoeId'];
|
||
$save['mer_status'] = 1;
|
||
$save['status'] = 1;
|
||
$save['hang_air'] = '审核通过';
|
||
$result['status'] = 1;
|
||
} else if ($result['checkFlag'] == 2) {
|
||
//驳回
|
||
$result['status'] = 2;
|
||
$save['mer_status'] = 2;
|
||
$save['hang_air'] = $result['chekMsg'];
|
||
} else {
|
||
//审核中
|
||
$result['status'] = 3;
|
||
$save['mer_status'] = 3;
|
||
$save['hang_air'] = $result['chekMsg'];
|
||
}
|
||
$save['step'] = 7;
|
||
$result['msg'] = $result['chekMsg'] ? $result['chekMsg'] : ($result['msgDat'] ? $result['msgDat'] : '审核失败');
|
||
M('merchant_entry')->where($eMap)->save($save);
|
||
return $result;
|
||
} else {
|
||
//失败返回接口
|
||
$result['status'] = 0;
|
||
$result['msg'] = $result['msgDat'] ? $result['msgDat'] : '提交进件失败';
|
||
return $result;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 上传图片到新大陆
|
||
* @param $entry
|
||
* @param $continent
|
||
* @return mixed
|
||
*/
|
||
protected function uploadsImage($entry, $continent)
|
||
{
|
||
$img = M('merchant_img')->where(array('entry_id' => $entry['id']))->field('id,entry_id,add_time', true)->find();
|
||
$arr = array();
|
||
//_img_type
|
||
foreach ($img as $key => $value) {
|
||
if (!empty($value) && !strpos($key, '_img_type')) {
|
||
$img_name = explode('/', $img[$key]);
|
||
$subData = array(
|
||
'serviceId' => '6060606',
|
||
'version' => 'V2.0.0',
|
||
'mercId' => $entry["merc_id"],
|
||
'orgNo' => $continent['continent_number'],
|
||
'logNo' => $entry["log_no"],
|
||
'stoeId' => $entry["stoe_id"],
|
||
'imgTyp' => $img[$key . '_img_type'],
|
||
'imgNm' => $img_name[count($img_name) - 1],
|
||
);
|
||
$subData['signValue'] = $this->getSign($subData, $continent['continent_pay_secret_key']);
|
||
$subData['imgFile'] = $this->Hexadecimal($value);
|
||
$subJson = json_encode($subData);
|
||
$re = $this->http_request($subJson);
|
||
$result = $this->GBK_decode($re);
|
||
if ($result['msgCd'] == 000000) {
|
||
$arr[] = $result;
|
||
} else {
|
||
//失败返回接口
|
||
$result['msg'] = $result['msgDat'] ? $result['msgDat'] : '图片上传失败';
|
||
$result['status'] = 0;
|
||
return $result;
|
||
}
|
||
}
|
||
}
|
||
$result['msg'] = '图片上传成功';
|
||
$result['status'] = 1;
|
||
$result['list'] = $arr;
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 图片转换成十六进制
|
||
* @param $imgUrl
|
||
* @return bool|string
|
||
*/
|
||
protected function Hexadecimal($imgUrl)
|
||
{
|
||
$imgUrl = '.' . $imgUrl;
|
||
if (file_exists($imgUrl)) {
|
||
$data = file_get_contents($imgUrl);
|
||
$newData = bin2hex($data);
|
||
file_put_contents('4.txt', $newData);
|
||
return $newData;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 查询商户提交审核的状态
|
||
* @param $merchant_id
|
||
* @return mixed
|
||
*/
|
||
public function searchEntryApply($merchant_id)
|
||
{
|
||
$map = array(
|
||
'merchant_id' => $merchant_id
|
||
);
|
||
$entry = M('merchant_entry')->where($map)->find();
|
||
$continent = M('continent_config')->find();
|
||
$MerData['serviceId'] = '6060300';
|
||
$MerData['version'] = 'V2.0.0';
|
||
$MerData['mercId'] = $entry['merc_id'];
|
||
$MerData['orgNo'] = $continent['continent_number'];
|
||
$MerData['signValue'] = $this->getSign($MerData, $continent['continent_pay_secret_key']);
|
||
$MerData = json_encode($MerData);
|
||
$re = $this->http_request($MerData);
|
||
$result = $this->GBK_decode($re);
|
||
if ($result['msgCd'] == 000000) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '查询成功';
|
||
if ($result['checkFlag'] == 1) {
|
||
$infos['merchant_id'] = $merchant_id;
|
||
$infos['entry_id'] = $entry['id'];
|
||
$infos['stoe_id'] = $result['REC'][0]['stoeId'];
|
||
$infos['merc_id'] = $result['mercId'];
|
||
$infos['log_no'] = $result['logNo'];
|
||
$infos['key'] = $result['key'];
|
||
$infos['trm_no'] = $result['REC'][0]['trmNo'];
|
||
$star = array(
|
||
'mer_status' => 1,
|
||
'status' => 1,
|
||
'stoe_id' => $result['REC'][0]['stoeId']
|
||
);
|
||
M('merchant_entry')->where($map)->save($star);
|
||
$iMap = array(
|
||
'merchant_id' => $merchant_id,
|
||
'entry_id' => $entry['id'],
|
||
);
|
||
$info = M('merchant_infos')->where($iMap)->find();
|
||
if (empty($info)) {
|
||
M('merchant_infos')->add($infos);
|
||
} else {
|
||
M('merchant_infos')->where($iMap)->save($infos);
|
||
}
|
||
$res['mer_status'] = 1;
|
||
$res['msg'] .= ': 审核成功';
|
||
} else if ($result['checkFlag'] == 2) {
|
||
$res['mer_status'] = 2;
|
||
$res['mer_text'] = $result['mercRemark'];
|
||
$star['mer_status'] = 2;
|
||
$star['hang_air'] = $result['mercRemark'];
|
||
M('merchant_entry')->where($map)->save($star);
|
||
$res['msg'] .= ': 审核驳回';
|
||
} else {
|
||
$res['mer_status'] = 3;
|
||
$star['mer_status'] = 3;
|
||
$star['hang_air'] = $result['mercRemark'];
|
||
M('merchant_entry')->where($map)->save($star);
|
||
$res['msg'] .= ': 人工审核中';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '查询错误:' . $result['msgDat'];
|
||
$star['mer_status'] = 4;
|
||
$star['hang_air'] = $result['msgDat'];
|
||
M('merchant_entry')->where($map)->save($star);
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 审核通过之后,申请修改商户资料
|
||
* @param $merchant_id
|
||
* @return mixed
|
||
*/
|
||
public function applyChange($merchant_id)
|
||
{
|
||
$eMap = array(
|
||
'merchant_id' => $merchant_id,
|
||
);
|
||
$entry = M('merchant_entry')->where($eMap)->find();
|
||
if (!empty($entry)) {
|
||
$continent = M('continent_config')->find();
|
||
$subData['serviceId'] = '6060605';
|
||
$subData['version'] = 'V2.0.0';
|
||
$subData['mercId'] = $entry['merc_id'];
|
||
$subData['orgNo'] = $continent['continent_number'];
|
||
$subData['signValue'] = $this->getSign($subData, $continent['continent_pay_secret_key']);
|
||
$subData = json_encode($subData);
|
||
$re = $this->http_request($subData);
|
||
$result = $this->GBK_decode($re);
|
||
if ($result['msgCd'] == '000000') {
|
||
$Sav['merc_id'] = $result['mercId'];
|
||
$Sav['stoe_id'] = $result['REC'][0]['stoeId'];
|
||
$Sav['log_no'] = $result['logNo'];
|
||
$Sav['mer_status'] = 5;
|
||
M('merchant_entry')->where($eMap)->save($Sav);
|
||
M('merchant_infos')->where(array('entry_id' => $entry['id']))->save($Sav);
|
||
$res['status'] = 1;
|
||
$res['msg'] = $result['msgDat'];
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = $result['msgDat'] ? $result['msgDat'] : '申请失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商户未进件,请先进件';
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 更新小程序或公众号信息
|
||
* @param $subData
|
||
* @return array
|
||
*/
|
||
protected function updateAppId($subData)
|
||
{
|
||
$continent = M('continent_config')->find();
|
||
$subData['serviceId'] = '6060111';//交易码
|
||
$subData['version'] = 'V1.0.0';//版本号
|
||
$subData['orgNo'] = $continent['continent_number'];
|
||
$subData['signValue'] = $this->getSign($subData, $continent['continent_pay_secret_key']);
|
||
|
||
$jsonData = json_encode($subData);
|
||
$re = $this->http_request($jsonData);
|
||
$result = $this->GBK_decode($re);
|
||
$result['subData'] = $subData;
|
||
if ($result['msg_cd'] == "000000") {
|
||
$result['status'] = 1;
|
||
if ($result['FollowSts'] == 1) {
|
||
$result['msg'] = $result['msg_dat'];
|
||
} else {
|
||
$result['msg'] = $result['msg_dat'] . ',请及时到新大陆报备';
|
||
}
|
||
} else {
|
||
//失败返回接口
|
||
$result['status'] = 0;
|
||
$result['msg'] = $result['msg_dat'] ? $result['msg_dat'] : '更新失败';
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 删除商户信息
|
||
* @param $merchant_id
|
||
* @return mixed
|
||
*/
|
||
public function deleteEntry($merchant_id)
|
||
{
|
||
$eMap = array(
|
||
'merchant_id' => $merchant_id
|
||
);
|
||
$entry = M('merchant_entry')->where($eMap)->find();
|
||
if (!empty($entry)) {
|
||
$delEntry = M('merchant_entry')->where(array('id' => $entry['id']))->delete();
|
||
$delImg = M('merchant_img')->where(array('entry_id' => $entry['id']))->delete();
|
||
$delInfo = M('merchant_infos')->where(array('entry_id' => $entry['id']))->delete();
|
||
if ($delEntry || $delImg || $delInfo) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '删除成功,请刷新当前页面!';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '删除失败';
|
||
}
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '暂无进件资料可删除';
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 接口数字签名方法
|
||
* @param $data
|
||
* @param $key
|
||
* @return mixed
|
||
*/
|
||
private function getSign($data, $key)
|
||
{
|
||
$arr = array_change_key_case($data, CASE_LOWER);
|
||
ksort($arr);
|
||
$str = "";
|
||
foreach ($arr as $val) {
|
||
$str .= $val;
|
||
}
|
||
$str .= $key;
|
||
return MD5($str);
|
||
}
|
||
|
||
/**
|
||
* 接口请求方法
|
||
* @param $data
|
||
* @param string $url
|
||
* @return bool|string
|
||
*/
|
||
private function http_request($data, $url = "")
|
||
{
|
||
if (empty($url)) {
|
||
$url = self::$gatewayUrl;
|
||
}
|
||
$ch = curl_init(); //用curl发送数据给api
|
||
$header = array(
|
||
'content-type:application/json;charset=GBK'
|
||
);
|
||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||
$response = curl_exec($ch);
|
||
if ($response === FALSE) {
|
||
echo "CURL Error:" . curl_error($ch);
|
||
}
|
||
curl_close($ch);
|
||
return $response;
|
||
}
|
||
|
||
/**
|
||
* gbk 项目转换
|
||
* @param $gbk_txt
|
||
* @return mixed
|
||
*/
|
||
private function GBK_decode($gbk_txt)
|
||
{
|
||
$text = mb_convert_encoding($gbk_txt, "utf8", "gbk");
|
||
$request = json_decode($text, true);
|
||
return $request;
|
||
}
|
||
|
||
/**
|
||
* 上传证书
|
||
* @return mixed
|
||
*/
|
||
public static function upload()
|
||
{
|
||
$upload = new \Think\Upload (); // 实例化上传类
|
||
$upload->maxSize = 5242880 / 2; // 设置附件上传大小5M/5
|
||
$upload->exts = array(
|
||
'pem',
|
||
); // 设置附件上传类型
|
||
$upload->rootPath = 'Uploads'; // 设置附件上传根目录
|
||
$upload->savePath = '/Wx/'; // 设置附件上传(子)目录
|
||
$upload->saveName = array(
|
||
'uniqid',
|
||
array('', true)
|
||
);
|
||
// 上传文件
|
||
$info = $upload->upload();
|
||
if (!empty($info['file']['savename'])) {
|
||
$path = "/" . $upload->rootPath . $info['file']['savepath'] . $info['file']['savename'];
|
||
$res['status'] = 1;
|
||
$res['path'] = $_SERVER['DOCUMENT_ROOT'] . $path;
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '上传失败';
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 上传图片
|
||
* @param $merchant_id
|
||
* @return mixed
|
||
*/
|
||
public function uploads($merchant_id)
|
||
{
|
||
$key = array_keys($_FILES)[0];
|
||
// 判断上传
|
||
if (!$key) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '非法上传';
|
||
return $res;
|
||
}
|
||
$upload = new \Think\Upload (); // 实例化上传类
|
||
$upload->maxSize = 512000; // 图片大小不超过500kb
|
||
$upload->exts = array('jpg', 'png', 'jpeg'); // 设置上传类型
|
||
$upload->rootPath = 'Uploads'; // 设置图片上传根目录
|
||
$upload->savePath = '/Merchant/'; // 设置附件上传子目录
|
||
$upload->subName = $merchant_id; // 子目录创建规则
|
||
$upload->replace = true; // 存在同名文件覆盖
|
||
// 上传图片
|
||
$info = $upload->upload();
|
||
if (empty($info)) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '上传失败';
|
||
return $res;
|
||
}
|
||
$path = '/Uploads' . $info[$key]['savepath'] . $info[$key]['savename'];
|
||
// 存入数据库
|
||
// 查询进件信息 id
|
||
$entry_id = M('merchant_entry')->where(array('merchant_id' => $merchant_id))->getField('id');
|
||
if (!$entry_id) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '商户进件出现异常,请刷新重试';
|
||
return $res;
|
||
}
|
||
// 查询进件图片
|
||
$m_img = M('merchant_img')->where(array('entry_id' => $entry_id))->find();
|
||
// 判断
|
||
if (empty($m_img)) {
|
||
// 新建
|
||
$cr = array(
|
||
'entry_id' => $entry_id,
|
||
'add_time' => time(),
|
||
$key => $path
|
||
);
|
||
$result = M('merchant_img')->add($cr);
|
||
} else {
|
||
$up = array();
|
||
// 修改
|
||
if ($m_img[$key] != $path) {
|
||
$up[$key] = $path;
|
||
}
|
||
// 判断修改
|
||
if (empty($up)) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '无需修改';
|
||
return $res;
|
||
}
|
||
$result = M('merchant_img')->where(array('entry_id' => $entry_id))->save($up);
|
||
}
|
||
if (!$result) {
|
||
$res['status'] = 0;
|
||
$res['msg'] = '上传失败,请重新上传';
|
||
} else {
|
||
$res['status'] = 1;
|
||
$res['msg'] = '上传成功';
|
||
$res['key'] = $key;
|
||
$res['path'] = $path;
|
||
// 判断原图片
|
||
if (!empty($m_img) && $m_img[$key]) {
|
||
unlink('./' . $m_img[$key]);
|
||
}
|
||
}
|
||
return $res;
|
||
}
|
||
} |