isAjax()) { $page = input('page', 1); $page_size = input('page_size', PAGE_LIST_ROWS); $search_text = input('search_text', ''); $states = input('states','all'); $condition[] = ['a.ag_site_id', '=', $this->site_id]; if ($states!='all') { $condition[] = ['a.states', '=', $states]; } if ($search_text) { $condition[] = ['a.merchant_name|a.contacts_name|a.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/list'); } /** * 收款店铺 * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function paystore() { if (request()->isAjax()) { $page = input('page', 1); $page_size = input('page_size', PAGE_LIST_ROWS); $search_text = input('search_text', ''); $condition[] = ['ag_site_id', '=', $this->site_id]; if ($search_text) { $condition[] = ['shop_name|contacts_name', 'like', '%' . $search_text . '%']; } $pat_model = new PayStore(); $res = $pat_model->getPageList($condition, $page, $page_size); return $res; } return $this->fetch('pay/paylist'); } /*** * 商家注册 * @return mixed|void * @throws \GuzzleHttp\Exception\GuzzleException */ public function reg() { $shop_id = input('shop_id', 0); $payShop = new PayShop(); if (request()->isAjax()) { $data = request()->post(); $payInfo = $data; //补充支付宝资料 $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']; $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['business_code']=='import20230107') { //草稿箱储存 $data['applyment_id'] = $data['business_code']; if($data['business_code']=='import20230107'){ $data['isDrafts']=0; $data['states']=1; } } 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); $res = $CloudPay->simpleCreate($payInfo); if ($res['code'] == 10000) { $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['area'] = $area; $data['subject_type'] = ''; $data['shop_id'] = $shop_id; $data['reg_money'] = 0; $res = $payShop->AlipaySave($data, $payInfo, $this->site_id); 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['username'] =$regInfo['username']; $payInfo['business_code'] = $regInfo['business_code']; } else { $payInfo['business_code'] = date('YmdHis') . rand(1000, 9999); $payInfo['outdoor_store_images'] = ''; $payInfo['indoor_store_image'] = ''; } $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|bool|mixed|\multitype|string */ public function image() { $CloudPay = new OpenPay(); $upload_model = new UploadModel($this->site_id, $this->app_module); $thumb_type = input('thumb', ''); $name = input('name', ''); $width = input('width', ''); $height = input('height', ''); $watermark = input('watermark', 0); // 是否需生成水印 $cloud = input('cloud', 1); // 是否需上传到云存储 $param = array( 'thumb_type' => '', 'name' => 'file', 'watermark' => $watermark, 'cloud' => $cloud, 'width' => $width, 'height' => $height ); $file = request()->file($param["name"]); $path = $this->site_id > 0 ? 'common/images/' . date('Ymd') . '/' : 'common/images/' . date('Ymd') . '/'; $result = $upload_model->setPath($path)->image($param); $ext = $file->getOriginalExtension(); $res = $CloudPay->upload($ext, $result['data']['pic_path']);//上传阿里 $result['data']['image_id'] = $res['image_id']; return $result; } /*** * 微信进件 * @return array|mixed|void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function wepayadd() { $app = new Wepay(); $pay_config = $app->payconfig; $shop_id = input('shop_id', 0); $subject_type = input('subject_type', 'reg'); $pay_model = new PayShop(); $payInfo = []; if ($shop_id) { $regInfo = $pay_model->where('shop_id', $shop_id)->find()->toArray(); $subject_type = $regInfo['subject_type']; $payInfo = $regInfo['wechatpay_value']; } $rate_model = new TradeRate(); $rate = $rate_model->getRateList($subject_type); $tate_arr = []; if ($rate) { foreach ($rate as $key => $vel) { $tate_arr[$vel['id']] = $vel; } } if (request()->isAjax()) { $data = request()->post(); //银行卡编码 if ($data['district_id']) { if ($data['district_id'] > 659000000) { $data['bank_account_info']['bank_address_code'] = $data['city_id']; } else { $data['bank_account_info']['bank_address_code'] = $data['district_id']; } } else if ($data['city_id']) { $data['bank_account_info']['bank_address_code'] = $data['city_id']; } else { $data['bank_account_info']['bank_address_code'] = $data['province_id']; } //企业类型 if ($data['subject_info']['subject_type'] == 'SUBJECT_TYPE_INDIVIDUAL') { $data['bank_account_info']['bank_account_type'] = 'BANK_ACCOUNT_TYPE_PERSONAL'; } else { $data['bank_account_info']['bank_account_type'] = 'BANK_ACCOUNT_TYPE_CORPORATE'; } //开通类型 if (isset($data['business_info']['sales_info']['sales_scenes_type'])) { $data['business_info']['sales_info']['sales_scenes_type'] = explode(',', $data['business_info']['sales_info']['sales_scenes_type']); $data['business_info']['sales_info']['mini_program_info']['mini_program_pics'] = json_decode($data['business_info']['sales_info']['mini_program_info']['mini_program_pics'], true); } //特殊资料 if (isset($data['settlement_info']['qualifications'])) { $data['settlement_info']['qualifications'] = json_decode($data['settlement_info']['qualifications']) ?? []; } $rate = $tate_arr[$data['settlement_info']['settlement_id']]['rate'] ?? '0.6';//费率 //优惠费率 if (empty($data['settlement_info']['activities_rate'])) { unset($data['settlement_info']['activities_rate']); } else if ($data['settlement_info']['activities_rate']) { $data['settlement_info']['activities_id'] = '20191030111cff5b5e';//范活动ID $rate = $data['settlement_info']['activities_rate']; } //检测小程序 if (empty($data['business_info']['sales_info']['mini_program_info']['mini_program_sub_appid'])) { $data['business_info']['sales_info']['mini_program_info']['mini_program_appid'] = 'wx1eac96cd7bac0ade'; } $data['subject_info']['identity_info']['owner'] = true; $area = [ 'district_id' => $data['district_id'], 'city_id' => $data['city_id'], 'province_id' => $data['province_id'], ]; if ($data['isDrafts']) { //草稿箱储存 $apply = []; $data['applyment_id'] = $data['business_code']; $data['applyment_state'] = ""; } else { //移除组织机构代码 if (empty($data['subject_info']['organization_info']['organization_copy']) || $data['subject_info']['subject_type'] == "SUBJECT_TYPE_INDIVIDUAL") { unset($data['subject_info']['organization_info']); } unset($data['district_id'], $data['city_id'], $data['province_id']); $apply = $app->applyment($data); if (isset($apply['applyment_id'])) { $data['applyment_id'] = $apply['applyment_id']; $data['applyment_state'] = "PAYAPPLY"; } else { return $apply; } } $data['area'] = $area; $data['subject_type'] = $subject_type; $data['shop_id'] = $shop_id; $payInfo['mch_id'] = ''; $payInfo['app_secrect'] = ''; $payInfo['pay_signkey'] = ''; $payInfo['apiclient_cert'] = ''; $payInfo['apiclient_key'] = ''; $payInfo['refund_status'] = 1; $payInfo['transfer_status'] = 1; $payInfo['is_ips'] = 1; $payInfo['app_type'] = 'wechat,weapp'; $payInfo['pay_status'] = 1; $payInfo['return_log'] = $apply; $payInfo['applyment_value'] = $data; $rate_arr = $tate_arr[$data['settlement_info']['settlement_id']]['activities_rate']; $data['reg_money'] = $rate_arr[$rate] ?? 0; $res = $pay_model->PaySave($data, $payInfo, $this->site_id, 0, $rate); return $res; } if (empty($pay_config['appid'])) { return $this->error('未知错误联系管理员'); } $this->assign("subject_type", $subject_type); if ($subject_type || $shop_id) { $applyment = []; $findpay = []; if (empty($payInfo)) { $applyment['business_code'] = date('YmdHis') . rand(1000, 9999); } else if (isset($payInfo['applyment_value'])) { $applyment = $payInfo["applyment_value"]; } $address_model = new AddressModel(); $weapp = new WeappModel($this->site_id); $weappinfo = $weapp->weapp_config; $list = $address_model->getAreaList([["pid", "=", 0], ["level", "=", 1]]); $this->assign("back", $rate_model->back); $this->assign("applyment_value", $payInfo['applyment_value'] ?? ''); $this->assign("province_list", $list["data"]); $this->assign("payfind", $findpay); $this->assign("isp_appid", $pay_config['appid']); $this->assign("mini_appid", $weappinfo['appid'] ?? ''); $this->assign("info", $applyment); $this->assign("rate", $tate_arr); $this->assign("cert_type", $rate_model->cert_type); $this->assign("rate_json", json_encode($tate_arr, JSON_UNESCAPED_UNICODE)); } return $this->fetch("pay/pay_{$subject_type}"); } /*** *删除申请 */ public function del() { $shop_id = input('shop_id'); if (request()->isAjax()) { $where = [ ['shop_id', '=', $shop_id], ['site_id', '=', $this->site_id], ]; $pay_model = new PayShop(); $res = $pay_model->where($where)->delete(); if ($res) { $info['code'] = 0; $info['message'] = '删除成功'; } else { $info['code'] = -1; $info['message'] = '使用中无法删除'; } return $info; } } /*** * 微信支付申请详情 * @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 = []; $pay_model = new 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']; $res=$this->alipayApplyment($regInfo); $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($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']; } $this->assign('shop_id', $shop_id); $this->assign('regInfo', $regInfo); $this->assign('info', $payInfo); return $this->fetch("pay/{$payType}_detail"); } /*** * 支付宝进件查询 * @param $payInfo */ public function alipayApplyment($payInfo) { $CloudPay = new OpenPay(); $order_id=$payInfo['alipay_value']['order_id']??''; $business_code=$payInfo['business_code']; if($order_id){ $res = $CloudPay->query('',$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['status'] =0; $res['sub_code'] = '未进件'; } return $res; } public function wxApplyment($data){ $shop_id = input('shop_id', 0); $payInfo = []; $findpay = []; $pay_model = new PayShop(); if ($shop_id) { $regInfo = $pay_model->where('shop_id', $shop_id)->find()->toArray(); $payInfo = $regInfo['wechatpay_value']; $payInfo['applyment_value']['applyment_state'] = "PAYAPPLY"; $payInfo['business_code'] = $regInfo['business_code']; } $app = new Wepay(); if (isset($payInfo['applyment_value']) && isset($payInfo['applyment_value']['applyment_id'])) { $findpay = $app->getApplyment($regInfo['business_code'], ''); if (isset($findpay['applyment_id'])) { if (isset($findpay['sub_mchid']) && ($payInfo['mch_id'] != $findpay['sub_mchid'] || $payInfo['applyment_value']['applyment_state'] != $findpay['applyment_state'])) { $payInfo['applyment_id'] = $findpay['applyment_id']; $payInfo['mch_id'] = $findpay['sub_mchid']; $payInfo['applyment_value']['applyment_state'] = $findpay['applyment_state']; $payInfo['applyment_value']['applyment_id'] = $findpay['applyment_id']; $updata = ['wechatpay_value' => $payInfo]; if ($findpay['applyment_state'] == 'APPLYMENT_STATE_FINISHED') { $updata['states'] = 1; if ($regInfo['reg_money'] > 0 && $regInfo['states'] == 0) { $pay_model->payAgent($regInfo['site_id'], $regInfo['reg_money']); } } $pay_model->where('shop_id', $shop_id)->save($updata); } } else { $payInfo['applyment_state'] = 'APPLYMENT_STATE_REJECTED'; $payInfo['audit_detail'] = []; } $payInfo = array_merge($payInfo, $findpay); } $this->assign('shop_id', $shop_id); $this->assign('info', $payInfo); return $this->fetch('pay/detail'); } /*** * 更新状态 * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function states() { $pay_model = new PayShop(); $where = [ ['isDrafts', '=', 0], ['states', '=', 0], ]; $info = $pay_model->where($where)->limit(10)->order('updata_time asc')->select(); if ($info) { foreach ($info as $key => $item) { if($item['pay_type']=='alipay'){ $payInfo = $item->toArray()['alipay_value']; $res=$this->alipayApplyment($payInfo); $payInfo=array_merge($payInfo,$res); $updata['apply_desc']=$payInfo['sub_code']; $updata['merchant_smid']=$payInfo['smid']; $updata['updata_time']=time(); $updata['alipay_value']=$payInfo; if($payInfo['status']==99){ $updata['states']=1; }else if($payInfo['status']==-1){ $updata['states']=2; }else{ $updata['states']=3; } $pay_model->where('shop_id', $item['shop_id'])->save($updata); }else{ $payInfo = $item->toArray()['wechatpay_value']; if (isset($payInfo['applyment_value']) && isset($payInfo['applyment_value']['applyment_id'])) { $applyment = $payInfo["applyment_value"]; $app = new Wepay(); $findpay = $app->getApplyment($applyment['business_code']); if (isset($findpay['applyment_id'])) { if (isset($findpay['sub_mchid']) && ($payInfo['mch_id'] != $findpay['sub_mchid'] || $payInfo['applyment_value']['applyment_state'] != $findpay['applyment_state'])) { $payInfo['applyment_id'] = $findpay['applyment_id']; $payInfo['mch_id'] = $findpay['sub_mchid']; $payInfo['applyment_value']['applyment_state'] = $findpay['applyment_state']; $updata = ['wechatpay_value' => $payInfo]; if ($findpay['applyment_state'] == 'APPLYMENT_STATE_FINISHED') { $updata['states'] = 1; if ($info['reg_money'] > 0 && $info['states'] == 0) { $pay_model->payAgent($info['site_id'], $info['reg_money']); } } else { $updata['states'] = 2; $updata['apply_desc'] = $findpay['applyment_state_msg']; } $pay_model->where('shop_id', $item['shop_id'])->save($updata); continue; } else if ($findpay['applyment_state'] == "APPLYMENT_STATE_AUDITING") { $updata['states'] = 3; $updata['apply_desc'] = $findpay['applyment_state_msg']; $updata['updata_time'] = time(); $pay_model->where('shop_id', $item['shop_id'])->save($updata); } else if ($findpay['applyment_state'] == 'APPLYMENT_STATE_FINISHED') { $updata['states'] = 1; $updata['apply_desc'] = $findpay['applyment_state_msg']; $updata['updata_time'] = time(); $pay_model->where('shop_id', $item['shop_id'])->save($updata); continue; } else { $updata['states'] = 2; $updata['apply_desc'] = $findpay['applyment_state_msg']; $updata['updata_time'] = time(); $pay_model->where('shop_id', $item['shop_id'])->save($updata); continue; } } } $pay_model->where('shop_id', $item['shop_id'])->save(['updata_time' => time()]); } } } return 'ok'; } /*** * @return bool|mixed */ public function alipayauth() { if (request()->isAjax()) { $pay_model = new PayShop(); $data = request()->post(); $data['business_code'] = date('YmdHi') . rand(1000, 9999); $data['site_id'] = $this->site_id; $data['site_id'] = $this->site_id; $res = $pay_model->save($data); return $res; } return $this->fetch('pay/alipay'); } /*** * 绑定支付宝 * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function bingAlipay() { $shop_id = input('shop_id'); $pay_model = new PayShop(); $regInfo = $pay_model->where('shop_id', $shop_id)->find()->toArray(); $alipay = new \addon\alipay\model\MinCode(); $url = addon_url('mp/alipay/authinfo', ['shop_id' => $shop_id]); $auth_url = $alipay->getPreAuthorizationUrl($url); $qr_img = "aipay/authimg/"; $file_name = "authqr_{$shop_id}"; qrcode($auth_url, $qr_img, $file_name); $this->assign('auth_url', $auth_url); $this->assign('qr_auth', '/' . $qr_img . $file_name . '.png'); return $this->fetch("pay/alipayauth"); } /*** * 绑定店铺 * @return array|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function bingshop() { if (request()->isAjax()) { $shop_id = input('shop_id'); $site_id = input('site_id'); $info['code'] = -1; $info['message'] = "参数错误"; if ($shop_id && $site_id) { $pay_model = new PayShop(); $regInfo = $pay_model->where('shop_id', $shop_id)->find()->toArray(); $pay_model->where('shop_id', $shop_id)->save(['site_id'=>$site_id]); model('site')->update(['shop_id'=>$shop_id],[['site_id','=',$site_id]]); $info['code'] = 0; $info['message'] = "绑定成功"; // if (isset($regInfo['wechatpay_value']['mch_id'])) { // $wxpay_model = new \addon\wechatpay\model\Config(); // $app_secrect = input("app_secrect", "");//应用密钥 // $pay_signkey = input("pay_signkey", "");//支付签名串API密钥 // $apiclient_cert = input("apiclient_cert", "");//支付证书cert // $apiclient_key = input("apiclient_key", "");//支付证书key // $data = array( // "appid" => '', // "mch_id" => $regInfo['wechatpay_value']['mch_id'], // "app_secrect" => $app_secrect, // "pay_signkey" => $pay_signkey, // "apiclient_cert" => $apiclient_cert, // "apiclient_key" => $apiclient_key, // "refund_status" => 0, // "pay_status" => 1, // "transfer_status" => 0, // "is_isp" => 1, // "app_type" => '' // ); // if (is_file($apiclient_cert)) { // $data['apiclient_cert_text'] = file_get_contents($apiclient_cert); // } // if (is_file($apiclient_key)) { // $data['apiclient_key_text'] = file_get_contents($apiclient_key); // } // $info_result = $wxpay_model->getPayConfig($site_id, $this->app_module); // $info = $info_result["data"]; // if ($info['value']) { // $data = array_merge($data, $info['value']); // $data['is_isp'] = 1; // } // $wxpay_model->setPayConfig($data, $site_id, $this->app_module); // $info['code'] = 0; // $info['message'] = "绑定微信成功"; // } // if ($regInfo['alipay_value']) { // $where=[ // 'site_id'=>$site_id, // 'app_type'=>'aliapp', // ]; // $AppInfo=Db::name('uni_account')->where($where)->json(['value'],true)->field('appid,original,value')->find(); // if($AppInfo){ // $value=$AppInfo['value']; // $data = array( // "app_id" => $AppInfo['appid'], // "app_auth_token" =>$value['app_auth_token'], // "merchant_smid" => $regInfo['merchant_smid'], // "private_key" => '', // "public_key" => '', // "alipay_public_key" => '', // "refund_status" => 0, // "pay_status" => 1, // "transfer_status" => 0, // "app_type" => '', // "public_key_crt" => '', // "alipay_public_key_crt" => '', // "alipay_with_crt" => '', // "countersign_type" => 0 // ); // $alpay_model = new \addon\alipay\model\Config(); // $info_result = $alpay_model->getPayConfig($site_id, $this->app_module); // $info_result = $info_result["data"]; // if ($info_result['value']) { // $data = array_merge($data, $info_result['value']); // $data['is_isp'] = 1; // } // $alpay_model->setPayConfig($data, $site_id, $this->app_module); // } // $info['code'] = 0; // $info['message'] .= "&绑定支付宝成功"; // } } else { $info['code'] = -1; $info['message'] = "参数错误"; } return $info; } return $this->fetch("pay/bingshop"); } }