377 lines
15 KiB
PHP
377 lines
15 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
|
|
namespace addon\saas\shop\controller;
|
|
|
|
use addon\aliapp\model\CloudPay;
|
|
use addon\aliapp\model\OpenPay;
|
|
use addon\saas\model\PayShop;
|
|
use app\model\system\Address as AddressModel;
|
|
use app\model\upload\Upload as UploadModel;
|
|
use addon\saas\model\AlipayCategory;
|
|
|
|
class Pay extends SaasBase
|
|
{
|
|
public function lists()
|
|
{
|
|
if (request()->isAjax()) {
|
|
$page = input('page', 1);
|
|
$page_size = input('page_size', PAGE_LIST_ROWS);
|
|
$search_text = input('search_text', '');
|
|
$states = input('states', 'all');
|
|
$condition[] = ['ag_site_id', '=', $this->site_id];
|
|
if ($states != 'all') {
|
|
$condition[] = ['states', '=', $states];
|
|
}
|
|
if ($search_text) {
|
|
$condition[] = ['merchant_name|contacts_name|contacts_phone', 'like', '%' . $search_text . '%'];
|
|
}
|
|
$pat_model = new PayShop();
|
|
$res = $pat_model->getPageList($condition, $page, $page_size);
|
|
return $res;
|
|
}
|
|
$this->forthMenu();
|
|
return $this->fetch('pay/lists');
|
|
}
|
|
|
|
|
|
/***
|
|
* 申请详情
|
|
* @return mixed
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function details()
|
|
{
|
|
$shop_id = input('shop_id', 0);
|
|
$payInfo = [];
|
|
$regInfo = [];
|
|
$zimaInfo = [];
|
|
$pay_model = new \addon\saas\model\PayShop();
|
|
if ($shop_id) {
|
|
$regInfo = $pay_model->where('shop_id', $shop_id)->find()->toArray();
|
|
$payType = $regInfo['pay_type'];
|
|
if ($payType == 'alipay') {
|
|
$payInfo = $regInfo['alipay_value'];
|
|
$zima_value = $regInfo['zmalipay_value'];
|
|
$res = $this->alipayApplyment($regInfo);
|
|
if ($zima_value) {
|
|
$zimaInfo = $this->zimaApplymentQuery($zima_value['smid'], $regInfo['site_id']);
|
|
}
|
|
$payInfo = array_merge($payInfo, $res);
|
|
if ($regInfo['states'] >= 0) {
|
|
if ($payInfo['status'] == 99) {
|
|
$updata['states'] = 1;
|
|
$updata['apply_desc'] = $payInfo['sub_code'];
|
|
$updata['merchant_smid'] = $payInfo['smid'];
|
|
} else if ($payInfo['status'] == '031') {
|
|
$updata['states'] = 3;
|
|
$updata['apply_desc'] = $payInfo['sub_code'];
|
|
$updata['merchant_smid'] = $payInfo['smid'];
|
|
} else if ($payInfo['status'] == -1) {
|
|
$updata['states'] = 2;
|
|
if (isset($payInfo['smid'])) {
|
|
$updata['states'] = 1;
|
|
$updata['merchant_smid'] = $payInfo['smid'];
|
|
}
|
|
}
|
|
$updata['updata_time'] = time();
|
|
$updata['alipay_value'] = $payInfo;
|
|
$pay_model->where('shop_id', $shop_id)->save($updata);
|
|
}
|
|
} else {
|
|
$payInfo = $regInfo['wechatpay_value'];
|
|
$res = $this->wxApplyment($payInfo);
|
|
$payInfo = array_merge($payInfo, $res);
|
|
}
|
|
$payInfo['business_code'] = $regInfo['business_code'];
|
|
}
|
|
if (request()->isAjax()) {
|
|
return success();
|
|
}
|
|
$this->assign('zimaInfo', $zimaInfo);
|
|
$this->assign('shop_id', $shop_id);
|
|
$this->assign('regInfo', $regInfo);
|
|
$this->assign('info', $payInfo);
|
|
return $this->fetch("pay/{$payType}_detail");
|
|
}
|
|
|
|
|
|
/***
|
|
* 商家支付通
|
|
* @return mixed|void
|
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
|
*/
|
|
public function reg()
|
|
{
|
|
$shop_id = input('shop_id', 0);
|
|
$payShop = new \addon\saas\model\PayShop();
|
|
if (request()->isAjax()) {
|
|
$data = request()->post();
|
|
$payInfo = $data;
|
|
$business_info = model('pay_shop')->getInfo([['alipay_value', 'like', '%' . $data['binding_alipay_logon_id'] . '%']], 'business_code,merchant_smid,alipay_value');
|
|
$business_code = $business_info['business_code'] ?? '';
|
|
$merchant_smid = $business_info['merchant_smid'] ?? '';
|
|
if ($business_info && $business_info['alipay_value']) {
|
|
$alipay_value = json_decode($business_info['alipay_value'], true);
|
|
}
|
|
if (empty($business_info) || !$shop_id || $business_code == $data['business_code']) {
|
|
//补充支付宝资料
|
|
$payInfo['external_id'] = $data['business_code'];
|
|
$payInfo['alipay_logon_id'] = $data['binding_alipay_logon_id'];
|
|
$payInfo['business_address']['province_code'] = $data['province_id'];
|
|
$payInfo['business_address']['city_code'] = $data['city_id'];
|
|
$payInfo['business_address']['district_code'] = $data['district_id'];
|
|
$payInfo['default_settle_rule'] = [
|
|
'default_settle_type' => 'alipayAccount',
|
|
'default_settle_target' => $data['binding_alipay_logon_id']
|
|
];
|
|
$payInfo['zft_withholding_info']=[
|
|
'withholding_service_feature_name'=>'GENERAL_WITHHOLDING_P',
|
|
'sign_scene'=>'INDUSTRY|PAY_ORDER_MODEL',
|
|
];
|
|
$area = [
|
|
'district_id' => $data['district_id'],
|
|
'city_id' => $data['city_id'],
|
|
'province_id' => $data['province_id'],
|
|
];
|
|
$mgs['code'] = 0;
|
|
$mgs['message'] = '成功';
|
|
if ($data['isDrafts']) { //草稿箱储存
|
|
$data['applyment_id'] = $data['business_code'];
|
|
} else {
|
|
$CloudPay = new OpenPay();
|
|
unset($payInfo['isDrafts'], $payInfo['district_id'], $payInfo['city_id'], $payInfo['province_id'], $payInfo['file']);
|
|
unset($payInfo['code'], $payInfo['bing_site_id'], $payInfo['username'], $payInfo['business_code'], $payInfo['outdoor_store_images'], $payInfo['indoor_store_image']);
|
|
$sites = $payInfo['sites'];
|
|
$payInfo['sites'] = array_values($sites);
|
|
if ($merchant_smid && (isset($alipay_value['order_id']) && $alipay_value['order_id'])) {
|
|
if ($merchant_smid) {
|
|
$payInfo['smid'] = $merchant_smid;
|
|
}
|
|
if ($data['code_type'] == 'individual') {
|
|
$payInfo['name'] = $data['legal_name'];
|
|
}
|
|
$res = $CloudPay->modifycreate($payInfo);
|
|
$payInfo = array_merge($alipay_value, $payInfo);
|
|
} else {
|
|
$res = $CloudPay->simpleCreate($payInfo);
|
|
}
|
|
if ($res['code'] == 10000) {
|
|
$payInfo['states'] = 0;
|
|
$payInfo['order_id'] = $res['order_id'];
|
|
} else {
|
|
$mgs['code'] = -1;
|
|
$mgs['message'] = $res['sub_msg'];
|
|
$data['states'] = 2;
|
|
$data['apply_desc'] = $res['sub_msg'];
|
|
}
|
|
$payInfo = array_merge($data, $payInfo);
|
|
$data['isDrafts'] = 0;
|
|
}
|
|
$data['area'] = $area;
|
|
$data['subject_type'] = '';
|
|
$data['shop_id'] = $shop_id;
|
|
$data['reg_money'] = 0;
|
|
$payShop->AlipaySave($data, $payInfo, $this->site_id, $this->uid, 0.6, [
|
|
'is_zmapply' => $data['is_zmapply'],
|
|
'is_platform'=>1]
|
|
);
|
|
return $mgs;
|
|
} else {
|
|
$mgs['code'] = -1;
|
|
$mgs['message'] = '商户已存在';
|
|
return $mgs;
|
|
}
|
|
}
|
|
if ($shop_id) {
|
|
$regInfo = $payShop->alias('a')
|
|
->where('a.shop_id', $shop_id)
|
|
->field('a.*,s.username')
|
|
->join('site s', 's.site_id = a.site_id', 'left')
|
|
->find()->toArray();
|
|
$payInfo = $regInfo['alipay_value'];
|
|
$payInfo['site_id'] = $regInfo['site_id'];
|
|
$payInfo['is_zmapply'] = $regInfo['is_zmapply'];
|
|
$payInfo['username'] = $regInfo['username'];
|
|
$payInfo['business_code'] = $regInfo['business_code'];
|
|
$this->assign('siteInfo', $payInfo);
|
|
} else {
|
|
$payInfo['business_code'] = date('YmdHis') . rand(1000, 9999);
|
|
$payInfo['outdoor_store_images'] = '';
|
|
$payInfo['indoor_store_image'] = '';
|
|
$payInfo['is_zmapply'] = '';
|
|
}
|
|
$address_model = new AddressModel();
|
|
$AlipayCategory = new AlipayCategory();
|
|
$list = $address_model->getAreaList([["pid", "=", 0], ["level", "=", 1]]);
|
|
$this->assign("province_list", $list["data"]);
|
|
$this->assign("alipay_category", $AlipayCategory->getCategory()['data']);
|
|
$this->assign('info', $payInfo);
|
|
return $this->fetch('pay/alipay');
|
|
}
|
|
|
|
|
|
/***
|
|
* 修改结算账号
|
|
* @return array|mixed
|
|
*/
|
|
public function settlementmodify()
|
|
{
|
|
$shop_id = input('shop_id', 0);
|
|
if (request()->isAjax()) {
|
|
$data = request()->post();
|
|
$payInfo = $data;
|
|
$business_info = model('pay_shop')->getInfo([['alipay_value', 'like', '%' . $data['binding_alipay_logon_id'] . '%']], 'business_code,merchant_smid,alipay_value');
|
|
$business_code = $business_info['business_code'] ?? '';
|
|
$merchant_smid = $business_info['merchant_smid'] ?? '';
|
|
$alipay_value = json_decode($business_info['alipay_value'], true);
|
|
if (empty($info) || !$shop_id || $business_code == $data['business_code']) {
|
|
$CloudPay = new OpenPay();
|
|
$mdata['alipay_logon_id'] = $data['binding_alipay_logon_id'];
|
|
$mdata['smid'] = $merchant_smid;
|
|
$res = $CloudPay->settlementmodify($mdata);
|
|
$payInfo = array_merge($alipay_value, $payInfo);
|
|
if ($res['code'] == 10000) {
|
|
$payInfo['order_id'] = $res['order_id'];
|
|
$payInfo = array_merge($data, $payInfo);
|
|
model('pay_shop')->update(['alipay_value' => json_encode($payInfo)], ['shop_id' => $shop_id]);
|
|
$mgs['code'] = 0;
|
|
$mgs['message'] = '成功';
|
|
} else {
|
|
$mgs['code'] = -1;
|
|
$mgs['message'] = $res['sub_msg'];
|
|
$data['states'] = 2;
|
|
$data['apply_desc'] = $res['sub_msg'];
|
|
}
|
|
|
|
return $mgs;
|
|
} else {
|
|
$mgs['code'] = -1;
|
|
$mgs['message'] = '商户已存在';
|
|
return $mgs;
|
|
}
|
|
}
|
|
}
|
|
|
|
/***
|
|
* 图片上传
|
|
* @return array|bool|mixed|\multitype|string
|
|
*/
|
|
public function image()
|
|
{
|
|
$upload_model = new UploadModel($this->site_id, $this->app_module);
|
|
$width = input('width', '');
|
|
$height = input('height', '');
|
|
$watermark = input('watermark', 0); // 是否需生成水印
|
|
$param = array(
|
|
'thumb_type' => '',
|
|
'name' => 'file',
|
|
'watermark' => $watermark,
|
|
'cloud' => 0,
|
|
'width' => $width,
|
|
'height' => $height
|
|
);
|
|
$path = $this->site_id > 0 ? 'common/images/' . date('Ymd') . '/' : 'common/images/' . date('Ymd') . '/';
|
|
$result = $upload_model->setPath($path)->image($param);
|
|
$CloudPay = new OpenPay();
|
|
$file = request()->file($param["name"]);
|
|
$ext = $file->getOriginalExtension();
|
|
$res = $CloudPay->upload($ext, $result['data']['pic_path']);//上传阿里
|
|
if (isset($res['image_id'])) {
|
|
$result['data']['image_id'] = $res['image_id'];
|
|
$pic_path = $upload_model->setPath($path)->fileCloud($result['data']['pic_path']);
|
|
$result['data']['pic_path'] = $pic_path['data'];
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
/***
|
|
*删除申请
|
|
*/
|
|
public function del()
|
|
{
|
|
$shop_id = input('shop_id');
|
|
if (request()->isAjax()) {
|
|
$where = [
|
|
['shop_id', '=', $shop_id],
|
|
['ag_site_id', '=', $this->site_id],
|
|
];
|
|
$pay_model = new \addon\saas\model\PayShop();
|
|
$res = $pay_model->where($where)->delete();
|
|
if ($res) {
|
|
$info['code'] = 0;
|
|
$info['message'] = '删除成功';
|
|
} else {
|
|
$info['code'] = -1;
|
|
$info['message'] = '使用中无法删除';
|
|
}
|
|
return $info;
|
|
}
|
|
}
|
|
|
|
|
|
public function zimaApplymentQuery($misd, $site_id)
|
|
{
|
|
$CloudPay = new CloudPay();
|
|
return $CloudPay->merchantApplyInfoQuery($misd, $site_id);
|
|
}
|
|
|
|
/***
|
|
* 支付宝进件查询
|
|
* @param $payInfo
|
|
*/
|
|
protected function alipayApplyment($payInfo)
|
|
{
|
|
$CloudPay = new OpenPay();
|
|
$order_id = $payInfo['alipay_value']['order_id'] ?? '';
|
|
$business_code = $payInfo['business_code'];
|
|
if (($order_id || $business_code) && !$payInfo['isDrafts']) {
|
|
$res = $CloudPay->query($business_code, $order_id);
|
|
if ($res['code'] == '10000') {
|
|
$res = $res['orders'][count($res['orders']) - 1];
|
|
if (isset($res['sub_confirm'])) {
|
|
switch ($res['sub_confirm']) {
|
|
case 'CREATE' :
|
|
$res['sub_code'] = '待商户确认';
|
|
break;
|
|
case 'SKIP' :
|
|
$res['sub_code'] = $res['reason'] ?? '进件成功';
|
|
break;
|
|
case 'FAIL' :
|
|
$res['sub_code'] = '进件失败';
|
|
break;
|
|
case 'FINISH' :
|
|
$res['sub_code'] = '签约完成';
|
|
break;
|
|
case 'NOT_CONFIRM' :
|
|
$res['sub_code'] = '商户未确认';
|
|
break;
|
|
default :
|
|
$res['sub_code'] = $res['reason'] ?? '';
|
|
}
|
|
}
|
|
} else {
|
|
$res['states'] = -1;
|
|
$res['status'] = 0;
|
|
}
|
|
} else {
|
|
$res['states'] = -1;
|
|
$res['status'] = 0;
|
|
$res['sub_code'] = '未进件';
|
|
}
|
|
return $res;
|
|
}
|
|
}
|