| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164 |
- <?php
- /**
- * @package crmeb_merchant
- *
- * @author Qinii
- * @day 2020-07-18
- *
- * Copyright (c) http://crmeb.net
- */
- namespace app\common\repositories\system\merchant;
- use AdaPaySdk\CorpMember;
- use app\common\repositories\BaseRepository;
- use app\common\repositories\merchant\apply\MerchantHaikeApplyRepository;
- use app\controller\admin\system\merchant\MerchantIntention;
- use app\traits\HaikeApiRequest;
- use app\traits\HuiPay;
- use app\traits\ShouxinyiApiRequest;
- use FormBuilder\Factory\Elm;
- use app\common\dao\system\merchant\MerchantIntentionDao;
- use FormBuilder\Form;
- use think\Exception;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\Log;
- use think\facade\Route;
- use think\route\Url;
- class MerchantIntentionRepository extends BaseRepository
- {
- use HaikeApiRequest;
- use HuiPay;
- public function __construct(MerchantIntentionDao $dao)
- {
- $this->dao = $dao;
- }
- public function getList(array $where,$page,$limit)
- {
- $query = $this->dao->search($where);
- $count = $query->count();
- $list = $query->page($page,$limit)
- ->order('mer_intention_id', 'desc')
- ->select();
- $haikeApplyRepository = app()->make(MerchantHaikeApplyRepository::class);
- foreach ($list as &$item) {
- $item->haike_status = 0;
- if (!$item->merch_no) {
- $item->haike_status = '暂无申请';
- $item->haike_status_msg = '';
- } else {
- try {
- $apply = $haikeApplyRepository->getWhere(['apply_id' => $item->mer_intention_id, 'apply_type' => 1]);
- if ($apply) {
- $item->haike_status = $apply->status;
- $item->haike_status_msg = '-'.$apply->check_result;
- }
- $apply2 = $haikeApplyRepository->getWhere(['apply_id' => $item->mer_intention_id, 'apply_type' => 2]);
- if ($apply2) {
- $str = substr($apply2->check_result, strpos($apply2->check_result, '{'));
- $array = json_decode($str, true);
- $item->haike_apply_wx_status = $apply2->status;
- $item->haike_apply_wx_status_msg = '-' . $array['result_msg'] ?? '';
- }
- $apply3 = $haikeApplyRepository->getWhere(['apply_id' => $item->mer_intention_id, 'apply_type' => 3]);
- if ($apply3) {
- $str = substr($apply2->check_result, strpos($apply2->check_result, '{'));
- $array = json_decode($str, true);
- $item->haike_apply_ali_status = $apply3->status;
- $item->haike_apply_ali_status_msg = '-' . $array['result_msg'] ?? '';
- }
- } catch (\Throwable $e) {
- $item->haike_status = $item->agent_apply_no;
- $item->haike_status_msg = '';
- $item->haike_apply_wx_status = 0;
- $item->haike_apply_wx_status_msg = '';
- $item->haike_apply_ali_status = 0;
- $item->haike_apply_ali_status_msg = '';
- }
- }
- $item = $this->wxAuthStatus($item, $haikeApplyRepository);
- $item->haike_wx_auth_status = 0;
- $sxy_status = $this->sxyStatus($item->mer_intention_id);
- $item->sxy_status = $sxy_status['msg'];
- $item->sys_status_code = $sxy_status['code'];
- }
- unset($item);
- // $list = $query->page($page,$limit)->select();
- // $count1 = $query->where("status",1)->count();
- // $count2 = $query->where("status",0)->count();
- // $count3 = $query->where("status",2)->count();
- $count1 =$count3 =$count2=0;
- $lists = $query->select();
- foreach ($lists as $item) {
- if($item["status"]==1){
- $count1+=1;
- }elseif ($item["status"]==0){
- $count2+=1;
- }else{
- $count3+=1;
- }
- }
- $cardLists=[
- ['className'=> 'el-icon-s-goods', 'count'=>$count1, 'field'=>'个', 'name'=> '已通过' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$count2, 'field'=>'个', 'name'=> '审核中' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$count3, 'field'=>'个', 'name'=> '未通过' ],
- ];
- return compact('count','list','cardLists');
- }
- public function sxyStatus($id){
- $res = Db::name("declare_log") -> where("m_id",$id) -> order('id','desc') -> find();
- //declare==1:审核提交成功
- //status==SUCCESS:审核成功
- $result['code'] = 2;//1:不展示审核按钮。2:展示审核按钮
- if($res['declare'] == 1){
- $result['msg'] = '审核中';
- $result['code'] = 1;
- }
- switch ($res['status']){
- case 'SUCCESS':
- $result['msg'] = '已开通';
- $result['code'] = 1;
- break;
- case 'ESIGN_SUCCESS':
- $result['msg'] = '电子签签约成功';
- $result['code'] = 1;
- break;
- case 'ESIGN_FAIL':
- $result['msg'] = '电子签签约失败';
- $result['code'] = 2;
- break;
- }
- if($res['declare'] != 1 || $res['status'] == 'NO_PASS' || $res['status'] == 'REFUSE'){
- $result['msg'] = $res['message'];
- }
- $result['status']=$res['status'];
- return $result;
- }
- public function markForm($id)
- {
- $intention = $this->dao->get($id);
- $intention->mer_intention_id = (string)$intention->mer_intention_id;
- $where=[
- Elm::input('mer_intention_id', '申请 ID', '')->disabled(true),
- Elm::input('merch_no', '海科商户号')->disabled(true),
- Elm::input('phone', '手机号'),
- Elm::input('mer_name', '商户名称'),
- Elm::input('mer_short_name', '商户简称'),
- Elm::input('addr', '详细地址'),
- Elm::frameImage('doorhead', '门头照', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=doorhead&type=1')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal']),
- Elm::frameImage('business_license', '营业执照', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=business_license&type=1')->modal(['modal' => false])->width('896px')->height('480px')->props(['footer' => false])->info('小微非必填'),
- Elm::frameImage('card_positive_person', '身份证正面(法人)', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=card_positive_person&type=1')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal']),
- Elm::frameImage('card_back_person', '身份证反面(法人)', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=card_back_person&type=1')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal']),
- Elm::input('identification_valid_date_start', '身份证有效期起始时间')->info('例:2000-01-01'),
- Elm::input('identification_valid_date_end', '身份证有效期结束时间')->info('例:2030-01-01'),
- Elm::input('name', '法人姓名'),
- Elm::input('idcard_no', '法人身份证号'),
- Elm::input('email', '邮箱'),
- Elm::input('acc_type', '结算方式(10A:对公,10B:对私)'),
- Elm::input('bank_account', '开户账号'),
- Elm::input('bank_deposit', '开户行'),
- Elm::input('bank_branch', '开户支行'),
- Elm::frameImage('open_account', '开户许可证', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=open_account&type=1')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal'])->info('小微上传结算卡照片'),
- Elm::frameImage('logo', '店铺LOGO', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=logo&type=1')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal']),
- Elm::input('business_addr', '营业执照地址')->info('小微请填写实际经营地址'),
- Elm::input('house_number', '门牌号'),
- Elm::input('type', '1企业2个体3个人'),
- Elm::input('spread_account', '推荐人手机号'),
- Elm::input('credit_code', '社会信用代码'),
- Elm::frameImage('business_premises2', '营业场所室内照图片1', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=business_premises2&type=1')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal']),
- Elm::frameImage('business_premises3', '营业场所室内照图片2', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=business_premises3&type=1')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal']),
- Elm::frameImage('business_premises4', '协议盖章', '/' . config('admin.admin_prefix') . '/setting/uploadPicture?field=business_premises4&type=1')->props(['footer' => false])->modal(['modal' => false, 'custom-class' => 'suibian-modal'])->info('小微必传'),
- Elm::input('haike_wx_type', '海科微信营业范围'),
- Elm::input('haike_wx_appid', '海科微信APPID')->info('配置微信公众号'),
- Elm::input('haike_wxsub_merch_no', '海科子商户号', '')->info('用于二次认证'),
- Elm::input('haike_ali_type', '海科支付宝营业范围'),
- Elm::input('agent_apply_no', '海科申请单号')->disabled(true),
- Elm::textarea('mark', '备注'),
- ];
- return Elm::createForm(Route::buildUrl('systemMerchantIntentionMark', compact('id'))->build(), $where)->setTitle('编辑')->formData($intention->toArray());
- }
- public function statusForm($id)
- {
- $form = Elm::createForm(Route::buildUrl('systemMerchantIntentionStatus', ['id' => $id])->build());
- $form->setRule([
- Elm::select('status', '审核状态', 1)->options([
- ['value' => 1, 'label' => '同意'],
- ['value' => 2, 'label' => '拒绝'],
- ]),
- Elm::textarea('check_result', '审核结果'),
- ]);
- return $form->setTitle('修改审核状态');
- }
- public function createMer($id){
- $data = Db::name("merchant_intention")
- ->where("mer_intention_id",$id)
- ->find();
- $user = Db::name("user")->where("uid",$data['uid'])->field('account,pwd,identity')->find();
- if(in_array($user['identity'],[1,2,3])){
- return ['code'=> 500,'msg'=>'该用户已是代理请拒绝'];
- }
- $count= Db::name("merchant_admin")
- ->where(['account' => $user['account'], 'is_del'=>0])
- ->count();
- if ($count > 0) {
- return ['code'=> 500,'msg' => '该用户已创建过商户账号,请先删除原有账户'];
- }
- $admin= Db::name("merchant_admin")
- ->where(['uid' => $data['uid'], 'is_del'=>0])
- ->find();
- if($admin){
- return ['code'=> 500,'msg'=>'该用户已是商户'];
- }
- if($user['account'] == $admin['account']){
- return ['code'=> 500,'msg'=>'该手机号已是商户账号'];
- }
- $expire_time=strtotime(date('Y-m-d'))+86400*365+86400-1;
- $spread = Db::name("user")
- ->where(["account"=>$data['spread_account']])
- ->field("uid,account,spread_count")
- ->find();
- $insdata=[
- 'uid'=>$data['uid'],
- 'merch_no' => $data['merch_no'],
- 'type'=>$data['type']??3,
- "mer_name"=>$data["mer_name"]??"",
- "mer_phone"=>$data["phone"]??"",
- "mer_address"=>$data["addr"]??"",
- "house_number"=>$data["house_number"]??"",
- "category_id"=>$data['cate_id']?$data['cate_id']:0,
- "doorhead"=>$data["doorhead"]??"",
- "mer_banner"=>$data["doorhead"]??"",
- "status"=>1,
- "lat"=>$data["lat"],
- "lng"=>$data["lng"],
- "business_license"=>$data["business_license"]??"",
- "service_phone"=>$data["phone"]??"",
- 'open_account'=>$data['open_account']??"",
- 'bank_account'=>$data['bank_account']??"",
- 'bank_location'=>$data['bank_location']??"",
- 'bank_deposit'=>$data['bank_deposit']??"",
- 'bank_branch'=>$data['bank_branch']??"",
- 'name'=>$data['name']??"",
- 'email'=>$data['email']??"",
- 'card_positive_person'=>$data['card_positive_person']??"",
- 'card_back_person'=>$data['card_back_person']??"",
- 'logo'=>$data['logo']??"",
- 'mer_avatar' => $data['logo']??"",
- 'mer_info'=>$data['desc']??"",
- 'district_addr'=>$data['district_addr']??"",
- 'province_id'=>$data['province_id']??"",
- 'city_id'=>$data['city_id']??"",
- 'area_id'=>$data['area_id']??"",
- 'street_id'=>$data['street_id']??"",
- "create_time"=>date("Y-m-d H:i:s"),
- "update_time"=>date("Y-m-d H:i:s"),
- "expire_time"=>$expire_time
- ];
- try{
- $merchant_id = Db::transaction(function () use ($spread, $data, $user, $insdata){
- if ($spread) {
- $insdata['recommender'] = $spread['uid'];
- //推荐人推荐数量加1
- Db::name("user")->where(['uid' => $spread['uid']])->update(['spread_count' => ($spread['spread_count'] + 1)]);
- //修改用户推荐人信息
- Db::name("user")->where(['uid' => $data['uid']])->update(['spread_uid' => $spread['uid']]);
- //保存用户的推荐记录
- $log = [
- 'uid' => $spread['uid'],
- 'link_id' => $data['uid'],
- 'identity' => 4,
- 'create_time' => date("Y-m-d H:i:s"),
- ];
- Db::name("user_identity_log")->insert($log);
- }
- $merchant_id = Db::name("merchant")->insertGetId($insdata);
- /*添加账户*/
- $merchant_admin_array = [
- 'uid' => $data['uid'],
- "mer_id" => $merchant_id,
- "account" => $user["account"],
- "pwd" => $user["pwd"],
- "real_name" => $data["mer_name"],
- "phone" => $data["phone"],
- "create_time" => date("Y-m-d H:i:s"),
- 'level' => 0
- ];
- Db::name("merchant_admin")->insert($merchant_admin_array);
- //用户更改成商家
- Db::name("user")->where(['uid' => $data['uid']])->update(['identity' => 5]);
- //更改商户收款码
- Db::name("MerchantQrcode") -> where("uid",$data['uid']) -> update(['mer_id'=>$merchant_id]);
- return $merchant_id;
- });
- if (!$merchant_id)
- return ['code' => 500, 'msg' => '创建商户失败'];
- return ['code' => 200, 'data' => $merchant_id];
- } catch (\Throwable $e) {
- return ['code' => 500, 'msg' => $e->getMessage()];
- }
- }
- /*详情*/
- public function getDetail($where)
- {
- $data = Db::name("merchant_intention")
- ->where($where)
- ->find();
- if ($data) {
- $data['cate_name'] = Db::name("merchant_category")
- ->where(['merchant_category_id' => $data['cate_id']])
- ->value('category_name');
- $data['province_name'] = Db::name("user_province")
- ->where(['province_id' => $data['province_id']])
- ->value('province_name');
- $data['city_name'] = Db::name("user_city")
- ->where(['city_id' => $data['city_id']])
- ->value('city_name');
- $data['area_name'] = Db::name("user_area")
- ->where(['area_id' => $data['area_id']])
- ->value('area_name');
- $data['street_name'] = Db::name("user_street")
- ->where(['street_id' => $data['street_id']])
- ->value('street_name');
- }
- return $data;
- }
- /**
- * 信息回显
- * @return array|bool
- * @author php迷途小书童
- * @created 2021/2/22 16:16
- */
- public function intentionInfo($where){
- try {
- $intention = $this->dao->getWhere($where);
- $haikeApplyRepository = app()->make(MerchantHaikeApplyRepository::class);
- $haikeMerchantApply = $haikeApplyRepository->getWhere(['apply_id' => $intention->mer_intention_id,'trade_type' => 'WX,ALI']);
- $haikeWxApply = $haikeApplyRepository->getWhere(['apply_id' => $intention->mer_intention_id,'apply_type' => 2]);
- $haikeAliApply = $haikeApplyRepository->getWhere(['apply_id' => $intention->mer_intention_id,'apply_type' => 3]);
- $merchantInfo = [];
- if (!$haikeMerchantApply) {
- $merchantInfo['code'] = 0;
- $merchantInfo['msg'] = '暂无申请信息';
- } else {
- //如果海科审核拒绝
- if (in_array($haikeMerchantApply->status, [1,5,6])) {
- $intention->status = 2;
- $intention->check_result = $haikeMerchantApply->check_result;
- $intention->save();
- } else if ($haikeWxApply->status == 2) {
- $str = substr($haikeWxApply->check_result, strpos($haikeWxApply->check_result, '{'));
- $array = json_decode($str, true);
- $intention->status = 2;
- $intention->check_result = $array['result_msg'] ?? '';
- $intention->save();
- } else if ($haikeAliApply->status == 2) {
- $str = substr($haikeAliApply->check_result, strpos($haikeAliApply->check_result, '{'));
- $array = json_decode($str, true);
- $intention->status = 2;
- $intention->check_result = $array['result_msg'] ?? '';
- $intention->save();
- } else {
- if ($intention->status != 1) {
- $intention->status = 0;
- $intention->check_result = '';
- $intention->save();
- }
- $merchantInfo['code'] = 0;
- $merchantInfo['msg'] = '暂无申请信息';
- }
- }
- $intention = $this->wxAuthStatus($intention, $haikeApplyRepository, $width = '200px');
- if (in_array($intention->haike_wx_auth_result_code, ['未授权'])) {
- $intention->haike_wx_auth_result_code = '';
- $intention->haike_wx_auth_result_msg = '';
- }
- if (in_array($intention->haike_wx_auth_result_code, ['已授权'])) {
- $intention->haike_wx_auth_result_code = '';
- $intention->haike_wx_auth_result_msg = '';
- $return = $this->createMer($intention->mer_intention_id);
- if ($return['code'] == 200) {
- $this->dao->update($intention->mer_intention_id, ['status' => 1,'check_result' => '已授权', 'mer_id' => $return['data']]);
- } else {
- Log::info('创建商户失败:'.$return['msg']);
- }
- }
- if ($intention->haike_wx_auth_result_state == 'APPLYMENT_STATE_REJECTED') {
- $intention->status = 2;
- $intention->check_result = $intention->haike_wx_auth_result_msg;
- $intention->save();
- $intention->haike_wx_auth_result_msg = '';
- }
- $sxy_msg=Db::name('declare_log')->where('m_id',$intention->mer_intention_id??0)->order('id','desc')->find();
- if($sxy_msg['status']=='SUCCESS' || $sxy_msg['status']=='ESIGN_SUCCESS'){
- $sxy_msg='线上已授权';
- }else{
- $sxy_msg=$sxy_msg['message'];
- }
- $intention->check_result=$intention->check_result.' || '. $sxy_msg;
- return [
- 'intention' => $intention,
- 'haikeMerchantInfo' => $merchantInfo,
- 'haikeWxAuthInfo' => [
- 'haike_wx_auth_result_code' => $intention->haike_wx_auth_result_code,
- 'haike_wx_auth_result_msg' => $intention->haike_wx_auth_result_msg,
- ],
- ];
- } catch (\Throwable $e) {
- Log::info('获取回显信息失败'.$e->getMessage());
- return false;
- }
- }
- /*获取省份*/
- public function getProvince(){
- $data = Db::name("user_province")
- ->where(['status'=>1])
- ->field("province_id,province_code,province_name")
- ->select();
- return $data;
- }
- /*获取城市*/
- public function getCity($province_code){
- $data = Db::name("user_city")
- ->where(['status'=>1,'province_code'=>$province_code])
- ->field("city_id,city_code,city_name")
- ->select();
- return $data;
- }
- /*获取区域*/
- public function getArea($city_code){
- $data = Db::name("user_area")
- ->where(['status'=>1,'city_code'=>$city_code])
- ->field("area_id,area_code,area_name")
- ->select();
- return $data;
- }
- /*获取街道*/
- public function getStreet($area_code){
- $data = Db::name("user_street")
- ->where(['status'=>1,'area_code'=>$area_code])
- ->field("street_id,street_code,street_name")
- ->select();
- return $data;
- }
- /*获取用户身份*/
- public function getIdentity($uid){
- $data = Db::name("user")->where(["uid"=>$uid])->field("identity,account,uid")->find();
- return $data;
- }
- /*实名认证判断*/
- public function real($uid){
- $data = Db::name("user_certification")->where(["uid"=>$uid,'status'=>1])->count();
- return $data;
- }
- public function wxAuthStatus($intention, $haikeApplyRepository, $width = '100px')
- {
- if ($intention->haike_wx_auth_apply_status == 1) {
- $intention->haike_wx_auth_result_code = '已授权';
- $intention->haike_wx_auth_result_msg ='';
- return $intention;
- }
- $authAstatusResult = $this->queryMerchantAuthStatus(['merch_no' => $intention->merch_no, 'wx_merch_no' => $intention->haike_wxsub_merch_no]);
- $intention->haike_wx_auth_result_code = '未授权';
- $intention->haike_wx_auth_result_msg ='';
- if ($authAstatusResult['return_code'] === 10000) {
- if ($authAstatusResult['authorize_state'] == "AUTHORIZE_STATE_AUTHORIZED") {
- $intention->haike_wx_auth_apply_status = 1;
- $intention->save();
- $intention->haike_wx_auth_result_code = '已授权';
- $intention->haike_wx_auth_result_msg ='';
- return $intention;
- }
- }
- if ($intention->haike_wx_auth_status === 1) {
- $haikeApply = $haikeApplyRepository->getWhere(['apply_id' => $intention->mer_intention_id,'trade_type' => 'WXAUTHAPPLY']);
- if ($haikeApply) {
- try {
- $responseApply = $this->queryMerchantApplyStatus($haikeApply->agent_apply_no);
- $intention->haike_wx_auth_result_state = '';
- if ($responseApply['return_code'] !== 10000) {
- $intention->haike_wx_auth_result_code = $responseApply['return_code'];
- $intention->haike_wx_auth_result_msg = $responseApply['return_msg'];
- } else {
- $intention->haike_wx_auth_result_state = $responseApply['applyment_state'];
- $intention->haike_wx_auth_result_code = $responseApply['applyment_state'];
- if (in_array($responseApply['applyment_state'],['APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT','APPLYMENT_STATE_WAITTING_FOR_CONFIRM_LEGALPERSON','APPLYMENT_STATE_PASSED','APPLYMENT_STATE_FREEZED'])) {
- $intention->haike_wx_auth_result_msg = "<img src='data:image/png;base64,{$responseApply['qrcode_data']}' style='width: {$width}' alt=''>";
- } else {
- if (in_array($responseApply['applyment_state'],['APPLYMENT_STATE_REJECTED'])) {
- $intention->haike_wx_auth_result_msg = $responseApply['reject_reason'];
- } else {
- $intention->haike_wx_auth_result_msg = '';
- }
- }
- $intention->haike_wx_auth_result_code = $this->getAuthCodeMsg($responseApply['applyment_state'], $intention->haike_wxsub_merch_no);
- }
- } catch (\Throwable $e) {
- $intention->haike_wx_auth_result_state = '';
- $intention->haike_wx_auth_result_code = $e->getMessage();
- $intention->haike_wx_auth_result_msg = '';
- }
- }
- }
- return $intention;
- }
- public function getAuthCodeMsg($applyment_state, $haike_wxsub_merch_no)
- {
- switch ($applyment_state) {
- case 'APPLYMENT_STATE_WAITTING_FOR_AUDIT':
- $msg = '【审核中】:请耐心等待1~2个工作日,微信支付将会完成审核。';
- break;
- case 'APPLYMENT_STATE_EDITTING':
- $msg = '【编辑中】:可能提交申请发生了错误导致,可用同一个业务申请编号重新提交。';
- break;
- case 'APPLYMENT_STATE_WAITTING_FOR_CONFIRM_CONTACT':
- $msg = '【待确认联系信息】:请扫描微信支付返回的小程序码确认联系信息。';
- break;
- case 'APPLYMENT_STATE_WAITTING_FOR_CONFIRM_LEGALPERSON':
- $msg = '【待账户验证】:请扫描微信支付返回的小程序码在小程序端完成账户验证。';
- break;
- case 'APPLYMENT_STATE_PASSED':
- $msg = '【审核通过】:请扫描微信支付返回的小程序码在小程序端完成授权流程。';
- break;
- case 'APPLYMENT_STATE_REJECTED':
- $msg = '【审核驳回】:请按照驳回原因修改申请资料,并更换业务申请编码,重新提交申请。';
- break;
- case 'APPLYMENT_STATE_FREEZED':
- $msg = '【已冻结】:可能是该主体已完成过入驻,请查看驳回原因,并通知驳回原因中指定的联系人扫描微信支付返回的小程序码在小程序端完成授权流程。';
- break;
- case 'APPLYMENT_STATE_CANCELED':
- $msg = '【已作废】:表示申请单已被撤销,无需再对其进行操作。';
- break;
- default:
- $msg = '未知。';
- break;
- }
- return $msg . '微信子商户号:' .$haike_wxsub_merch_no;
- }
- public function createSXY($id){
- $intention = $this->getDetail(['mer_intention_id'=>$id]);
- //签约名称
- $arr['signedName'] = $intention['name'];
- if($intention['type'] != 3){
- $arr['signedName'] = $intention['mer_name'];
- }
- if($intention['acc_type'] != "10A"){//对私全部以自然人身份入网
- $arr['signedName'] = $intention['name'];
- }
- // if($intention['acc_type'] == "10A" || $intention['type'] == 1){//10A对公10B对私 对公或者企业填公司名称
- // $arr['signedName'] = $intention['mer_name'];
- // }
- // if($intention['acc_type'] == '10A' && $intention['type'] == 2){//个体可以对公
- // $arr['signedName'] = $intention['mer_name'];
- // }
- // if($intention['acc_type'] == '10B' && $intention['type'] == 2){//个体可以对私
- // $arr['signedName'] = $intention['name'];
- // }
- //end
- if($intention['type'] == 1){//企业
- $arr['registerRole'] = 'ENTERPRISE_LEGAL_PERSON';
- }elseif ($intention['type'] == 2){//个体
- $arr['registerRole'] = 'INDIVIDUAL_BUSINESS';
- }elseif ($intention['type'] == 3){//个人
- $arr['registerRole'] = 'NATURAL_PERSON';
- }
- if($intention['acc_type'] != "10A"){//对私全部以自然人身份入网
- $arr['registerRole'] = 'NATURAL_PERSON';
- }
- $arr['cerType'] = 'ID_CARD';
- // //个人传其他 个体跟企业传营业执照
- // if($intention['type'] == 3){
- // $arr['cerType'] = 'OTHERS';
- // }
- // if($intention['type'] == 1 || $intention['type'] == 2){
- // $arr['cerType'] = 'BUSINESS_LICENSE';
- // }
- $arr['signedShorthand'] = $arr['signedName'];
- $arr['businessAddressProvince'] = $this -> getAddress($intention['province_id'],'province');
- $arr['businessAddressCity'] = $this -> getAddress($intention['city_id'],'city');
- $arr['businessAddressArea'] = $this -> getAddress($intention['area_id'],'area');
- $arr['businessAddress'] = $intention['addr'];
- $arr['contactName'] = $intention['name'];
- $arr['contactEmail'] = $intention['email'];
- $arr['contactPhone'] = $intention['phone'];
- $arr['businessClassification'] = 'ELECTRONIC_BUSINESS_16';//电商_其他
- //银行
- $arr['bankCode'] = $this -> getSXYBankCode($intention['bank_deposit']);
- $arr['bankBranchName'] =$intention['bank_branch'];
- //开户名称
- $arr['accountName'] = $intention['name'];//开户名称
- if($intention['acc_type'] == "10B"){
- $arr['accountName'] = $intention['name'];
- }
- if($intention['acc_type'] == "10A"){//10A对公10B对私 对公或者企业填公司名称
- $arr['accountName'] = $intention['mer_name'];
- }
- if($intention['acc_type'] == '10A'){//个体可以对公
- $arr['accountName'] = $intention['mer_name'];
- }
- // if($intention['acc_type'] == '10B' && $intention['type'] == 2){//个体可以对私
- // $arr['accountName'] = $intention['name'];
- // }
- //end
- str_replace(' ', '', $intention['bank_account']);
- $arr['bankCardNo'] = str_replace(' ', '', $intention['bank_account']);;
- $arr['cityCode'] = Db::name("user_city")
- ->where(['city_id' => $intention['city_id']])
- ->value('city_code');
- $arr['provinceCode'] = Db::name("user_province")
- ->where(['province_id' => $intention['province_id']])
- ->value('province_code');
- if($intention['acc_type'] == '10A'){//10A对公10B对私
- $arr['accountType'] = 'PUBLIC';
- }else{
- $arr['accountType'] = 'PRIVATE';
- }
- $arr['legalPersonName'] = $intention['name'];
- $arr['legalPersonIdNo'] = $intention['idcard_no'];
- $arr['legalPersonPhoneNo'] = $intention['phone'];
- //registerRole类型为NATURAL_PERSON必填
- $arr['profession'] = $arr['registerRole'] == 'NATURAL_PERSON' ? 6 : '';
- //end
- $arr['legalPersonIdType'] = 'IDCARD';
- $arr['legalPersonIdNoSup'] = $intention['idcard_no'];
- $arr['idEffectiveDateStart'] = $intention['identification_valid_date_start'];
- $arr['idEffectiveDateEnd'] = $intention['identification_valid_date_end'] == 'forever' ? '2099-12-31' : $intention['identification_valid_date_end'];
- //registerRole类型不为NATURAL_PERSON必填
- $arr['cerNoType'] = $arr['registerRole'] != 'NATURAL_PERSON' ? 'SOCIAL_CREDIT_NO' : '';
- $arr['cerNo'] = $arr['registerRole'] != 'NATURAL_PERSON' ? $intention['credit_code'] : '';
- $arr['sellingArea'] = 'B';
- $arr['staffSize'] = 'B';
- $arr['businessLicensePath'] = $arr['registerRole'] != 'NATURAL_PERSON' ? $this -> sxyPath($intention['business_license']) : '';
- //end
- $arr['legalIdCardProsPath'] = $this -> sxyPath($intention['card_positive_person']);
- $arr['legalIdCardConsPath'] = $this -> sxyPath($intention['card_back_person']);
- //openAccountPath 商户类型不为自然人及个体工商户时必传
- //legalPersonBankCardPath 商户类型为自然人时必传,为个体工商户时此项和openAccountPath二选一进行传递
- //
- $arr['openAccountPath'] = '';
- $arr['legalPersonBankCardPath'] = '';
- //非个人非个体
- if ($intention['type'] != 3 && $intention['type'] != 2) {
- $arr['openAccountPath'] = $this -> sxyPath($intention['open_account']) ?: '';
- }
- //个人
- if ($intention['type'] == 3) {
- $arr['legalPersonBankCardPath'] = $this -> sxyPath($intention['open_account']) ?: '';
- }
- //个体对公
- if ($intention['type'] == 2 && $intention['acc_type'] != '10B') {
- $arr['openAccountPath'] = $this -> sxyPath($intention['open_account']) ?: '';
- }
- //对私
- if ($intention['acc_type'] != '10A') {
- $arr['legalPersonBankCardPath'] = $this -> sxyPath($intention['open_account']) ?: '';
- }
- //对公
- if ($intention['type'] == 1 && $intention['acc_type'] != '10B') {
- $arr['legalPersonBankCardPath'] = $this -> sxyPath($intention['open_account']) ?: '';
- }
- $arr['m_id'] = $intention['mer_intention_id'];
- $res = ShouxinyiApiRequest::merchantApply($arr);
- Db::name("log")->insert(array('data'=>json_encode($res)));//日志记录
- return true;
- }
- public function sxyPath($file1){
- if ($file1 == '')
- return false;
- $path = "/serviceprovider/chuxubao/".date('Ymd')."/";
- //本地路径
- $file1 = str_replace('http://app.bjtdba.com','',$file1);
- $file1 = str_replace('https://app.bjtdba.com','',$file1);
- //远程路径含文件名
- $f = explode("/",$file1);
- $file = $path.$f[count($f)-1];
- $sxy = ShouxinyiApiRequest::uploadSFtp($path,$file,"./public".$file1);
- return $file;
- }
- public function getAddress($id,$type){
- if($type == 'province'){
- $res = Db::name("user_province")
- ->where(['province_id' => $id])
- ->field('province_code,short_name')
- ->find();
- $code = $res['province_code'];
- $check = Db::name("sxy_business_address") -> where('code',$code) -> find();
- if(!$check){
- $code = Db::name("sxy_business_address") -> where("province like '%".$res['short_name']."%'") -> value('code');
- }
- return $code;
- }
- if($type == 'city'){
- $res = Db::name("user_city")
- ->where(['city_id' => $id])
- ->field('city_code,short_name')
- ->find();
- $code = $res['city_code'];
- $check = Db::name("sxy_business_address") -> where('code',$code) -> find();
- if(!$check){
- $code = Db::name("sxy_business_address") -> where("city like '%".$res['short_name']."%'") -> value('code');
- }
- return $code;
- }
- if($type == 'area'){
- $res = Db::name("user_area")
- ->where(['area_id' => $id])
- ->field('area_code,short_name')
- ->find();
- $code = $res['area_code'];
- $check = Db::name("sxy_business_address") -> where('code',$code) -> find();
- if(!$check){
- $code = Db::name("sxy_business_address") -> where("area like '%".$res['short_name']."%'") -> value('code');
- }
- return $code;
- }
- return '';
- }
- public function getHfAddress($id,$type){
- if($type == 'province'){
- $res = Db::name("user_province")
- ->where(['province_id' => $id])
- ->field('province_code,short_name')
- ->find();
- $code = $res['province_code'];
- $check = Db::name("hf_business_address") -> where('code',$code) -> find();
- if(!$check){
- $code = Db::name("hf_business_address") -> where("province like '%".$res['short_name']."%'") -> value('code');
- }
- return $code;
- }
- if($type == 'city'){
- $res = Db::name("user_city")
- ->where(['city_id' => $id])
- ->field('city_code,short_name')
- ->find();
- $code = $res['city_code'];
- $check = Db::name("hf_business_address") -> where('code',$code) -> find();
- if(!$check){
- $code = Db::name("hf_business_address") -> where("city like '%".$res['short_name']."%'") -> value('code');
- }
- return $code;
- }
- if($type == 'area'){
- $res = Db::name("user_area")
- ->where(['area_id' => $id])
- ->field('area_code,short_name')
- ->find();
- $code = $res['area_code'];
- $check = Db::name("hf_business_address") -> where('code',$code) -> find();
- if(!$check){
- $code = Db::name("hf_business_address") -> where("area like '%".$res['short_name']."%'") -> value('code');
- }
- return $code;
- }
- return '';
- }
- public function getSXYBankCode($bank_deposit){
- $count=strpos($bank_deposit,"中国");
- $bank_deposit=substr_replace($bank_deposit,"",$count,6);
- $code = Db::name("sxy_settlement_bank")
- ->where("bank_name like '%".$bank_deposit."%'")
- ->value('code');
- if($code)
- return $code;
- $bank_deposit = mb_substr($bank_deposit,0,2);
- $code = Db::name("sxy_settlement_bank")
- ->where("bank_name like '%".$bank_deposit."%'")
- ->value('code');
- if($code)
- return $code;
- $bank_deposit = mb_substr($bank_deposit,2,2);
- $code = Db::name("sxy_settlement_bank")
- ->where("bank_name like '%".$bank_deposit."%'")
- ->value('code');
- if($code)
- return $code;
- $bank_deposit = mb_substr($bank_deposit,4,2);
- $code = Db::name("sxy_settlement_bank")
- ->where("bank_name like '%".$bank_deposit."%'")
- ->value('code');
- if($code)
- return $code;
- return '';
- }
- public function huifu_create($id,$type,$key='',$app_id='',$mer_id='')
- {
- try {
- $checkMerchat=Db::name('merchant')->where('mer_id',$mer_id)->find();
- if(!$checkMerchat) return '错误';
- $app_id='app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
- $key='api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
- //拿到商户的信息
- $merchat=Db::name('merchant_intention')->where('mer_intention_id',$id)->find();
- //商户类型为个人走此
- if($merchat['type']==3){
- //用户在汇付的ID
- $member_id='member_personal_'.time().rand(1111,9999);
- $params=[
- 'app_id'=>$app_id,
- 'member_id'=>$member_id,//商户下的用户id,只能为英文、数字或者下划线的一种或多种组合,保证在app_id下唯一
- 'nickname' => $checkMerchat['mer_name']
- ];
- //创建用户对象
- $res=$this->crate_merber_personal_traits($params,$type,$key);
- if(isset($res['data'])){
- $result = json_decode($res['data'],true);
- Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['status'=>3,'check_result'=>$result['error_msg']]);
- return $result['error_msg'];
- }
- if(!empty($res['error_type'])){
- Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['status'=>3,'check_result'=>$res['error_msg']]);
- return $res['error_msg'];
- }
- //个人创建 没有生成结算账户需要手动创建结算账户
- $jiesuandata=[
- 'app_id'=>$app_id,//应用ID
- 'member_id'=>$member_id,//商户下的用户id,只能为英文、数字或者下划线的一种或多种组合,保证在app_id下唯一
- 'channel'=>'bank_account',//结算类型 目前仅支持银行卡 固定值 bank_account
- 'account_info'=>[
- 'card_id'=>str_replace(" ",'',$merchat['bank_account']),//银行卡号
- 'card_name'=>$merchat['name'],//银行卡对应的户名
- 'cert_id'=>$merchat['idcard_no'],//证件号,银行账户类型为对私时,必填
- 'cert_type'=>'00',//证件类型,仅支持:00-身份证,银行账户类型为对私时,必填
- 'tel_no'=>$merchat['phone'],//手机号
- 'bank_name'=>$merchat['bank_deposit'],//开户银行名称
- 'bank_acct_type'=>2//银行账户类型:1-对公;2-对私
- ]
- ];
- //创建该用户的结算账户
- $res=$this->create_settleAccounttraits($jiesuandata,$type,$key);
- if(isset($res['data'])){
- $result = json_decode($res['data'],true);
- //创建失败
- Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['status'=>3,'check_result'=>$result['error_msg'],'hf_status'=>3]);
- return $result['error_msg'];
- }
- if(!empty($res['error_type'])){
- Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['status'=>3,'check_result'=>$res['error_msg'],'hf_status'=>3]);
- return $res['error_msg'];
- }
- //将生成的id 存入数据库
- $insert = [
- [
- 'mer_id' => $checkMerchat['mer_id'],
- 'type' => 1,
- 'member_id' => $checkMerchat['hf_member_id'],
- 'settle_account_id' => $res['id']
- ],
- [
- 'mer_id' => $checkMerchat['mer_id'],
- 'type' => 2,
- 'member_id' => $checkMerchat['hf_member_id_wx'],
- 'settle_account_id' => $res['id']
- ],
- [
- 'mer_id' => $checkMerchat['mer_id'],
- 'type' => 3,
- 'member_id' => $member_id,
- 'settle_account_id' => $res['id']
- ],
- ];
- Db::name('merchant_member')->where('mer_id', $merchat['mer_id'])->insertAll($insert);
- Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['status'=>1,'check_result'=>'线下支付已授权','hf_status'=>2]);
- }else{
- //压缩包
- $imgs=[
- $merchat['business_license'],
- $merchat['card_positive_person'],
- $merchat['card_back_person'],
- $merchat['open_account'],
- ];
- $res=$this->addzip($imgs,'attach_file');
- if (!$res){
- Db::name('merchant_intention')->where('mer_intention_id',$merchat['mer_intention_id'])->update(['status'=>2,'check_result'=>'图片不存在']);
- return "图片不存在";
- }
- $file_real_path = realpath($res);
- $fileInfo = pathinfo($file_real_path);
- //压缩包end
- //银行卡编码
- $bank_code=Db::name('hf_bank_code')->whereLike('name','%'.$merchat['bank_deposit'].'%')->value('code');
- if(!$bank_code){
- Db::name('merchant_intention')->where('mer_intention_id',$merchat['mer_intention_id'])->update(['status'=>2,'check_result'=>'银行卡开户行填写不正确']);
- return "银行卡开户行填写不正确";
- }
- //结算卡类型
- if($merchat['acc_type']=='10A'){
- $bank_acct_type=1;
- $card_name=$merchat['mer_name'];
- }else{
- $bank_acct_type=2;
- $card_name=$merchat['name'];
- }
- //有效期为永久 默认值为 20991231
- if($merchat['identification_valid_date_end']=='forever'){
- $legal_cert_id_expires='20991231';
- }else{
- $legal_cert_id_expires=date('Ymd',strtotime($merchat['identification_valid_date_end']));
- }
- //有效期为长期 默认值为 20991231
- if($merchat['merc_end_time']=='长期'){
- $merc_end_time='20991231';
- }else{
- $merc_end_time=date('Ymd',strtotime($merchat['merc_end_time']));
- if($merc_end_time<date('Ymd',time())){
- $merc_end_time='20991231';
- }
- }
- //请求订单编号1
- $order_no=time().rand(10000,99999);
- //商户下的用户id,只能为英文、数字或者下划线的一种或多种组合,保证在app_id下唯一
- $member_id='member_enterprise_'.time().rand(1111,9999);
- $params=[
- 'app_id'=>$app_id,//控制台 主页面应用的app_id
- 'order_no'=>$order_no,//请求订单号,只能为英文、数字或者下划线的一种或多种组合,保证在app_id下唯一
- 'member_id'=>$member_id,//商户下的用户id,只能为英文、数字或者下划线的一种或多种组合,保证在app_id下唯一
- 'name'=>$merchat['mer_name'],//企业名称
- 'prov_code'=>$this->getHfAddress($merchat['province_id'],'province'),//省份编码 (省市编码)
- 'area_code'=>$this->getHfAddress($merchat['city_id'],'city'),//地区编码 (省市编码)
- 'social_credit_code'=>$merchat['credit_code'],//统一社会信用码
- 'social_credit_code_expires'=>$merc_end_time,//统一社会信用证有效期
- 'business_scope'=>'零售',//经营范围
- 'legal_person'=>$merchat['name'],//法人姓名
- 'legal_cert_id'=>$merchat['idcard_no'],//法人身份证号码
- 'legal_cert_id_expires'=>$legal_cert_id_expires,//法人身份证有效期(格式:YYYYMMDD,例如:20190909)
- 'legal_mp'=>$merchat['phone'],//法人手机号
- 'address'=>$merchat['business_addr'],//企业地址
- 'bank_code'=>$bank_code,//银行代码,如果需要自动开结算账户,本字段必填(详见附录 银行代码)
- 'bank_acct_type'=>$bank_acct_type,//银行账户类型:1-对公;2-对私,如果需要自动开结算账户,本字段必填
- 'card_no'=>$merchat['bank_account'],//银行卡号,如果需要自动开结算账户,本字段必填
- 'card_name'=>$card_name,//银行卡对应的户名,如果需要自动开结算账户,本字段必填;若银行账户类型是对公,必须与企业名称一致
- 'notify_url'=>env('APP_URL').'/sys/HuiPay/notify_url/'.'crate_merber_enterprise',//异步通知地址,url为http/https路径,服务器POST回调,URL 上请勿附带参数
- ];
- //上传附件,传入的中文文件名称为 UTF-8 字符集 URLEncode 编码后的字符串。内容须包含三证合一证件照、法人身份证正面照、法人身份证反面照、开户银行许可证照。 压缩 zip包后上传,最大限制为 9 M。
- $params['attach_file']=new \CURLFile($file_real_path,'', $fileInfo['basename']);
- //增加记录为异步通知做准备
- Db::name('hf_user_order')->insert(['mer_intention_id'=>$id,'order_no'=>$order_no]);
- //创建企业用户并增加结算卡账户
- $res=$this->crate_merber_enterprise_traits($params,$type,$key);
- if (isset($res['data'])){
- $result = json_decode($res['data'],true);
- if(!empty($result['error_type'])){
- Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['check_result'=>$result['error_msg']]);
- return $result['error_msg'];
- }
- }
- if(!empty($res['error_type'])){
- Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['check_result'=>$res['error_msg']]);
- return $res['error_msg'];
- }
- //更改汇付状态
- Db::name('merchant_intention')->where('mer_intention_id',$id)->update(['hf_status'=>1,'check_result'=>'审核中']);
- }
- Db::name('user')->where('uid',$merchat['uid'])->update([
- 'user_group'=>4
- ]);
- return "success";
- }catch (\Exception $exception){
- Db::name('log')->insert(['data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】']);
- return ['data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'];
- }
- }
- /**
- * 将优化后的二维码添加到压缩包
- */
- public function addzip($show_src,$name='attach_file')
- {
- try {
- $tmpDir = './public/zip/'; //
- if (!file_exists($tmpDir)) {
- //创建文件夹
- mkdir($tmpDir, 0777, true);
- }
- // $phone=Db::name('user_agent')
- // ->where('u_a.user_id',$uid)
- // ->alias('u_a')
- // ->leftJoin('user u','u_a.user_id=u.uid')
- // ->field('u.phone')
- // ->find();
- $zipName = date('YmdHis') . mt_rand(1000, 9999) . '.zip'; // 压缩包文件名
- if($name > 0){
- $rend=md5(mt_rand(100000000, 999999999));
- $zipName = $name . '_' . $rend . '.zip'; // 压缩包文件名
- }
- $zipNameUrl = $tmpDir . $zipName; // 文件路径
- //生成文件
- $zip = new \ZipArchive();
- if ($zip->open($zipNameUrl, \ZipArchive::OVERWRITE) !== true) {
- //OVERWRITE 参数会覆写压缩包的文件 文件必须已经存在
- if ($zip->open($zipNameUrl, \ZipArchive::CREATE) !== true) {
- // 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
- return '下载失败,文件夹不存在';
- }
- }
- foreach ($show_src as $file) {
- //判断图片是否存在
- $isFile = $this->checkFileExists($file);
- if (!$isFile) {
- continue;
- }
- //抓取图片内容
- $fileContent = file_get_contents($file);
- //添加图片
- $zip->addFromString(basename($file), $fileContent);
- }
- // 关闭
- $zip->close();
- $qrcodeData=[
- 'url'=>'./public/zip/'.$zipName,
- 'ctime'=>time()
- ];
- return $qrcodeData['url'];
- }catch(\Exception $e){
- log::info($e->getMessage());
- return false;
- }
- }
- /**
- * 判断文件是否存在,支持本地及远程文件
- * @param String $file 文件路径
- * @return Boolean
- */
- private function checkFileExists($file)
- {
- // 远程文件
- if (strtolower(substr($file, 0, 5)) == 'https') {
- // 远程文件
- $header = get_headers($file, true);
- return isset($header[0]) && (strpos($header[0], '200') || strpos($header[0], '304'));
- } elseif (strtolower(substr($file, 0, 4)) == 'http') {
- // 远程文件
- $header = get_headers($file, true);
- return isset($header[0]) && (strpos($header[0], '200') || strpos($header[0], '304'));
- } else {
- // 本地文件
- return file_exists($file);
- }
- }
- //进件 汇付
- public function UpgradeToMerchants($merchant_params,$name)
- {
- $merchant_params['fee_rate_list']='[{"rate_channel": "wx_pub_online","fee_rate": "0.008"}, {"rate_channel": "wx_pub_offline","fee_rate": "0.0038"}, {"rate_channel": "wx_lite_online","fee_rate": "0.007"}, {"rate_channel": "wx_lite_offline","fee_rate": "0.0038"}, {"rate_channel": "wx_scan","fee_rate": "0.0038"}, {"rate_channel": "alipay_qr_online","fee_rate": "0.007"}, {"rate_channel": "alipay_qr_offline","fee_rate": "0.0038"}, {"rate_channel": "alipay_scan","fee_rate": "0.0038"}, {"rate_channel": "alipay_lite_online","fee_rate": "0.007"}, {"rate_channel": "alipay_lite_offline","fee_rate": "0.0038"}, {"rate_channel": "alipay_call","fee_rate": "0.007"}, {"rate_channel": "union_qr_under","fee_rate": "0.0038"}, {"rate_channel": "union_qr_beyond","fee_rate": "0.007"}, {"rate_channel": "union","fee_rate": "0.007"}, {"rate_channel": "alipay_pub","fee_rate": "0.0038"}]';
- Db::name('log')->insert(['data'=>json_encode($merchant_params)]);
- return $this->incoming_parts($merchant_params,$name);
- }
- //进件 汇付
- public function incoming_select($merchant_params,$name)
- {
- return $this->incoming_parts_select($merchant_params,$name);
- }
- public function ruzhu($ruzhu_data,$name)
- {
- return $this->Merchant_settlement($ruzhu_data,$name);
- }
- public function ruzhu_query($ruzhu_query_data,$name)
- {
- return $this->Merchant_settlement_select($ruzhu_query_data,$name);
- }
- public function merProfilePictures($data,$name)
- {
- $up_dir = '/uploads/users/huifu_upload/';
- $new_file = (int)(microtime(true) * 1000);
- $res=$this->uploadImg($data['file'],$up_dir,$new_file);
- Db::name('log')->insert(['data'=>json_encode($res)]);
- $file_real_path = realpath($res['path']);
- $fileInfo = pathinfo($file_real_path);
- $data['file']=new \CURLFile($file_real_path,'', $fileInfo['basename']) ;
- $data=$this->merProfilePicture($data,$name);
- if(empty($data['error_type'])){
- $data=['file_type'=>$data['file_type'],'pic_id'=>$data['pic_id']];
- }else{
- $data=['errro_msg'=>$data['error_msg']];
- }
- return $data;
- }
- public function uploadImg(string $image, string $up_dir,$new_file)
- {
- $base64_img = trim($image);
- if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_img, $result)) {
- $type = $result[2];
- if (in_array($type, array('pjpeg', 'jpeg', 'jpg','JPG', 'gif', 'bmp', 'png'))) {
- if (!is_dir('./public' .$up_dir)) {
- mkdir('./public' .$up_dir,0777,true);
- }
- // $new_file = (int)(microtime(true) * 1000);
- $imgName = $up_dir . "{$new_file}." . $type;
- $new_file = './public'.$imgName;
- if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_img)))) {
- // 完整的图片地址
- return ["path"=>$new_file,"suffix"=>$type];
- } else {
- return false;
- }
- }
- }
- return false;
- }
- public function commit_res($data,$name)
- {
- return $this->merProfileForAudit($data,$name);
- }
- public function commit_res_query($data)
- {
- return $this->merProfileAuditStatus($data);
- }
- }
|