| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155 |
- <?php
- /**
- * @package merchant
- *
- * @author Qinii
- * @day 2020-06-16
- *
- *
- */
- namespace app\common\repositories\user;
- use alipay\aop\AlipayConfig;
- use alipay\aop\AopCertClient;
- use alipay\aop\request\AlipayFundTransUniTransferRequest;
- use app\common\repositories\BaseRepository;
- use app\common\dao\user\UserExtractDao as dao;
- use app\common\repositories\merchant\MerchantRepository;
- use crmeb\jobs\SendTemplateMessageJob;
- use crmeb\services\SwooleTaskService;
- use think\Exception;
- use think\facade\Db;
- use think\facade\App;
- use think\facade\Queue;
- class UserExtractRepository extends BaseRepository
- {
- /**
- * @var dao
- */
- protected $dao;
- protected $wxapp = array(
- 'app_id'=>'wxbf753066ac8686ba',
- 'applet_app_id'=>'wx9082e5ac2fdb513f',
- 'mchid'=>'1605734712',
- 'certPem'=>'/pkey/cert/apiclient_cert.pem',
- 'keyPem'=>'/pkey/cert/apiclient_key.pem'
- );
- /**
- * UserExtractRepository constructor.
- * @param dao $dao
- */
- public function __construct(dao $dao)
- {
- $this->dao = $dao;
- }
- /**
- * TODO
- * @param $id
- * @return bool
- * @author Qinii
- * @day 2020-06-16
- */
- public function getWhereCount($id)
- {
- $where['extract_id'] = $id;
- $where['status'] = 0;
- return $this->dao->getWhereCount($where) > 0;
- }
- /**
- * TODO
- * @param array $where
- * @param $page
- * @param $limit
- * @return array
- * @author Qinii
- * @day 2020-06-16
- */
- public function serach(array $where,$page,$limit)
- {
- if(isset($where['mer_id'])){
- $where['mer_id']=isset($where['mer_id'])?$where['mer_id']:"";
- }
- $mer_ids=[];
- if(isset($where['mer_name']) && $where['mer_name']!=''){
- $mer_ids=Db::name('merchant')->whereLike('mer_name','%'.$where['mer_name'].'%')->column('mer_id');
- }
- unset($where['mer_name']);
- $uids[]=0;
- $keyword='';
- if($where['keyword']!=''){
- $keyword=$where['keyword'];
- $uids=Db::name('user_certification')
- ->alias('uc')
- ->join('user_extract ue','uc.uid = ue.uid')
- ->join('user u','uc.uid = u.uid')
- ->whereLike('uc.user_name','%'.$where['keyword'].'%')
- ->whereOr('u.account','like','%'.$where['keyword'].'%')
- ->group('uc.uid')
- ->column('uc.uid');
- unset($where['keyword']);
- }
- $query = $this->dao->serach($where)
- ->when($keyword,function($query)use($keyword,$uids){
- $query->where(function($query)use($keyword,$uids){
- $query->where('real_name','like','%'.$keyword.'%')
- ->whereOr('bank_code','like','%'.$keyword.'%')
- ->whereOr('alipay_code','like','%'.$keyword.'%')
- ->whereOr('wechat','like','%'.$keyword.'%')
- ->whereOr('uid','in',$uids);
- });
- })
- ->when(($where['identity'] ?? '') == 'user', function ($query) {
- $query->where('mer_id is null');
- })
- ->when(($where['identity'] ?? '') == 'mer', function ($query) {
- $query->where('mer_id is not null');
- })
- ->when($mer_ids,function ($q) use ($mer_ids){$q->where('mer_id','in',$mer_ids);});
- $query_sql= clone $query;
- $count = $query->count();
- $list = $query->page($page,$limit)->order("extract_id desc")->select();
- if($list){
- foreach($list as $key => &$value){
- $value['real_name'] = $value['real_name'].'['.Db::name('user_certification') -> where('uid',$value['uid']) -> value('user_name').']';
- $value['phone'] =Db::name('user') -> where('uid',$value['uid']) -> value('phone');
- $value['mer_name'] ='平台';
- if($value['mer_id']){
- $value['mer_name'] = Db::name('merchant')->where('mer_id',$value['mer_id'])->value('mer_name');
- }
- }
- }
- if(isset($where['mer_id']) && $where['mer_id']!=''){
- $where2['mer_id']=isset($where['mer_id'])?$where['mer_id']:'';
- $mer_id = $where['mer_id'];
- $bill_number = Db::name("user_bill")->where('mer_id', $mer_id)->where('status', 1)->whereIn('commission_type', [7, 17, 19])->sum('number');
- $uids2=$query_sql->group('uid')->column('uid');
- //总额
- $zonge_1=$bill_number;
- $zonge_2=sprintf("%.2f", $bill_number * 0.06);
- //已提现
- $tixian_1=Db::name("user_extract") ->where($where2)->where('status',1)->whereIn('uid',$uids2)->sum("extract_price");
- $tixian_2=Db::name("user_extract") ->where($where2)->where('status',1)->whereIn('uid',$uids2)->sum("service_money");
- //审核中
- $shenhezhong_1=Db::name("user_extract") ->where($where2)->where('status',0)->whereIn('uid',$uids2)->sum("extract_price");
- $shenhezhong_2=Db::name("user_extract") ->where($where2)->where('status',0)->whereIn('uid',$uids2)->sum("service_money");
- //增加【实际提现】模块,实际提现金额=已提现金额*(1-综合服务费率)
- $countmoyer=[
- //总额
- ['className'=> 'el-icon-s-goods', 'count'=>$zonge_1, 'field'=>'元', 'name'=> '收益总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$zonge_2, 'field'=>'元', 'name'=> '综合服务费总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>set_price_rtrim(decimal2($zonge_1-$zonge_2)), 'field'=>'元', 'name'=> '实际到账总额' ],
- //已提现
- ['className'=> 'el-icon-s-goods', 'count'=>$tixian_1, 'field'=>'元', 'name'=> '已提现总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$tixian_2, 'field'=>'元', 'name'=> '综合服务费' ],
- ['className'=> 'el-icon-s-goods', 'count'=>set_price_rtrim(decimal2($tixian_1-$tixian_2)), 'field'=>'元', 'name'=> '实际到账总额' ],
- //审核中
- ['className'=> 'el-icon-s-goods', 'count'=>$shenhezhong_1, 'field'=>'元', 'name'=> '审核中总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$shenhezhong_2, 'field'=>'元', 'name'=> '综合服务费' ],
- ['className'=> 'el-icon-s-goods', 'count'=>set_price_rtrim(decimal2($shenhezhong_1-$shenhezhong_2)), 'field'=>'元', 'name'=> '实际到账总额' ]
- ];
- }else{
- if (($where['identity'] ?? '') == 'user') {
- $bill_number = Db::name("user_bill")->where('status', 1)->whereNotIn('commission_type', [5, 7, 17, 19])->sum('number');
- }
- if (($where['identity'] ?? '') == 'mer') {
- $bill_number = Db::name("user_bill")->where('status', 1)->whereIn('commission_type', [7, 17, 19])->sum('number');
- }
- $zonge_1=$bill_number;
- $tixian_1=Db::name("user_extract")->when(($where['identity'] ?? '') == 'user', function ($query) {
- $query->where('mer_id is null');
- })
- ->when(($where['identity'] ?? '') == 'mer', function ($query) {
- $query->where('mer_id is not null');
- })->where('status',1)->sum("extract_price");
- $tixian_2=Db::name("user_extract")->when(($where['identity'] ?? '') == 'user', function ($query) {
- $query->where('mer_id is null');
- })
- ->when(($where['identity'] ?? '') == 'mer', function ($query) {
- $query->where('mer_id is not null');
- })->where('status',1)->sum("service_money");
- $shenhezhong_1=Db::name("user_extract")->when(($where['identity'] ?? '') == 'user', function ($query) {
- $query->where('mer_id is null');
- })
- ->when(($where['identity'] ?? '') == 'mer', function ($query) {
- $query->where('mer_id is not null');
- })->where('status',0)->sum("extract_price");
- $count1 = $query->where("status",1)->sum("extract_price");
- $count2 = Db::name("user")->sum("brokerage_price");
- if (($where['identity'] ?? '') == 'mer') {
- $count2 = Db::name("merchant")->sum("brokerage_price");
- }
- $countmoyer=[
- ['className'=> 'el-icon-s-goods', 'count'=>$zonge_1, 'field'=>'元', 'name'=> '奖励总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$tixian_1, 'field'=>'元', 'name'=> '已提现' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$tixian_1 - $tixian_2, 'field'=>'元', 'name'=> '实际提现' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$zonge_1 - $tixian_1 - $shenhezhong_1, 'field'=>'元', 'name'=> '未提现' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$shenhezhong_1, 'field'=>'元', 'name'=> '审核中' ],
- ];
- }
- return compact('count','list',"countmoyer");
- }
- /**
- * TODO
- * @param array $where
- * @param $page
- * @param $limit
- * @return array
- * @author Qinii
- * @day 2020-06-16
- */
- public function new_search(array $where,$page,$limit)
- {
- if(isset($where['mer_id'])){
- $where['mer_id']=isset($where['mer_id'])?$where['mer_id']:"";
- }
- $mer_ids=[];
- if(isset($where['mer_name']) && $where['mer_name']!=''){
- $mer_ids=Db::name('merchant')->whereLike('mer_name','%'.$where['mer_name'].'%')->column('mer_id');
- }
- unset($where['mer_name']);
- $uids[]=0;
- $keyword='';
- if($where['keyword']!=''){
- $keyword=$where['keyword'];
- $uids=Db::name('user_certification')
- ->alias('uc')
- ->join('user_extract ue','uc.uid = ue.uid')
- ->join('user u','uc.uid = u.uid')
- ->whereLike('uc.user_name','%'.$where['keyword'].'%')
- ->whereOr('u.account','like','%'.$where['keyword'].'%')
- ->group('uc.uid')
- ->column('uc.uid');
- unset($where['keyword']);
- }
- $query = $this->dao->serach($where)
- ->when($keyword,function($query)use($keyword,$uids){
- $query->where(function($query)use($keyword,$uids){
- $query->where('real_name','like','%'.$keyword.'%')
- ->whereOr('bank_code','like','%'.$keyword.'%')
- ->whereOr('alipay_code','like','%'.$keyword.'%')
- ->whereOr('wechat','like','%'.$keyword.'%')
- ->whereOr('uid','in',$uids);
- });
- })
- // ->when($where['identity'] == 'user', function ($query) {
- // $query->where('mer_id is null');
- // })
- // ->when($where['identity'] == 'mer', function ($query) {
- // $query->where('mer_id is not null');
- // })
- ->when($mer_ids,function ($q) use ($mer_ids){$q->where('mer_id','in',$mer_ids);});
- $query_sql= clone $query;
- $count = $query->count();
- $list = $query->page($page,$limit)->order("extract_id desc")->select();
- if($list){
- foreach($list as $key => &$value){
- $value['real_name'] = $value['real_name'].'['.Db::name('user_certification') -> where('uid',$value['uid']) -> value('user_name').']';
- $value['phone'] =Db::name('user') -> where('uid',$value['uid']) -> value('phone');
- $value['mer_name'] ='平台';
- if($value['mer_id']){
- $value['mer_name'] = Db::name('merchant')->where('mer_id',$value['mer_id'])->value('mer_name');
- }
- }
- }
- $where2['mer_id']=isset($where['mer_id'])?$where['mer_id']:'';
- $uids2=$query_sql->group('uid')->column('uid');
- //总额
- $zonge_1=Db::name("user_extract")->whereIn('uid',$uids2)->sum("extract_price");
- $zonge_2=Db::name("user_extract")->whereIn('uid',$uids2)->sum("service_money");
- //已提现
- $tixian_1=Db::name("user_extract")->where('status',1)->whereIn('uid',$uids2)->sum("extract_price");
- $tixian_2=Db::name("user_extract")->where('status',1)->whereIn('uid',$uids2)->sum("service_money");
- //审核中
- $shenhezhong_1=Db::name("user_extract")->where('status',0)->whereIn('uid',$uids2)->sum("extract_price");
- $shenhezhong_2=Db::name("user_extract")->where('status',0)->whereIn('uid',$uids2)->sum("service_money");
- //增加【实际提现】模块,实际提现金额=已提现金额*(1-综合服务费率)
- $countmoyer=[
- //总额
- ['className'=> 'el-icon-s-goods', 'count'=>$zonge_1, 'field'=>'元', 'name'=> '收益总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$zonge_2, 'field'=>'元', 'name'=> '综合服务费总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>set_price_rtrim(decimal2($zonge_1-$zonge_2)), 'field'=>'元', 'name'=> '实际到账总额' ],
- //已提现
- ['className'=> 'el-icon-s-goods', 'count'=>$tixian_1, 'field'=>'元', 'name'=> '已提现总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$tixian_2, 'field'=>'元', 'name'=> '综合服务费' ],
- ['className'=> 'el-icon-s-goods', 'count'=>set_price_rtrim(decimal2($tixian_1-$tixian_2)), 'field'=>'元', 'name'=> '实际到账总额' ],
- //审核中
- ['className'=> 'el-icon-s-goods', 'count'=>$shenhezhong_1, 'field'=>'元', 'name'=> '审核中总额' ],
- ['className'=> 'el-icon-s-goods', 'count'=>$shenhezhong_2, 'field'=>'元', 'name'=> '综合服务费' ],
- ['className'=> 'el-icon-s-goods', 'count'=>set_price_rtrim(decimal2($shenhezhong_1-$shenhezhong_2)), 'field'=>'元', 'name'=> '实际到账总额' ]
- ];
- return compact('count','list',"countmoyer");
- }
- public function get_user_extract_item($extract_id)
- {
- return Db::name('user_extract_item')->where('extract_id',$extract_id)->select();
- }
- /**
- * @param $uid
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function userTotalExtract($uid)
- {
- return $this->dao->serach(['status' => 1, 'uid' => $uid])->sum('extract_price');
- }
- /**
- * TODO
- * @param $user
- * @param $data
- * @author Qinii
- * @day 2020-06-16
- */
- public function create($user,$data,$uid,$type=1)
- {
- $userData = Db::name('user') -> where('uid',$uid) -> find();
- if ($data["extract_type"]==1){
- $data["wechat"]=$userData['account'];
- $data["extract_pic"]='';
- $data["real_name"]=$userData['nickname'];
- $data['order_sn'] = 'wx'.time().rand(100000, 999999);
- }else if($data["extract_type"]==2) {
- if ($userData['ali_user_id'] == '0' || $userData['ali_user_id'] == '') {
- return false;
- }
- $data["alipay_code"] = $userData["account"];
- $data["real_name"] = $userData["nickname"];
- $data['order_sn'] = 'al' . time() . rand(100000, 999999);
- }else if($data["extract_type"]==3){
- $account_info=Db::name("user_withdraw_account")->where(["id"=>$data["bank_id"],"account_type"=>$data["extract_type"],"user_id"=>$uid])->find();
- if(!$account_info){
- return false;
- }
- $data["bank_code"]=$account_info["account"];
- $data["real_name"]=$account_info['info'];
- $data["bank_address"]=$account_info['bank_name'];
- $data['order_sn'] = 'tx'.time().rand(100000, 999999);
- $data["bank_info"]= json_encode($account_info, true);
- unset($data['bank_id']);
- }else{
- return false;
- }
- if ($data["extract_type"]==3){
- $data = Db::transaction(function()use($user,$data, $type,$uid){
- if($type==1){
- $brokerage_price = bcsub($user['brokerage_price'],$data['extract_price'],2);
- $user->brokerage_price = $brokerage_price;
- }else if ($type == 2) {
- $brokerage_price = bcsub($user['member_brokerage_price'],$data['extract_price'],2);
- $user->member_brokerage_price = $brokerage_price;
- }else if ($type == 3) {
- $hongbao = bcsub($user['hongbao'],$data['extract_price'],2);
- $user->hongbao = $hongbao;
- }
- $user->save();
- $service_money=bcmul($data['extract_price'],'0.1',2);
- $data['service_money']=$service_money;
- $data['status'] = 0;
- $data['uid'] = $user['uid'];
- $data['type']=$type;
- $data['withdrawal_type'] =3;
- return $this->dao->create($data);
- });
- }else{
- $data = Db::transaction(function()use($user,$data,$uid,$type){
- if($type==1){
- $brokerage_price = bcsub($user['brokerage_price'],$data['extract_price'],2);
- $user->brokerage_price = $brokerage_price;
- }else if ($type == 2) {
- $brokerage_price = bcsub($user['member_brokerage_price'],$data['extract_price'],2);
- $user->member_brokerage_price = $brokerage_price;
- }else if ($type == 3) {
- $hongbao = bcsub($user['hongbao'],$data['extract_price'],2);
- $user->hongbao = $hongbao;
- }
- $user->save();
- $service_money=bcmul($data['extract_price'],'0.1',2);
- $data['service_money']=$service_money;
- $data['status'] = 0;
- $data['uid'] = $user['uid'];
- $data['types'] = $type;
- $data['statbalanceus'] = $brokerage_price;
- $extract=$this->dao->create($data);
- $tea_price=Db::name('user_rich')->where('uid', $uid)->value('tea_price');
- $extract_price_yihu=0;
- $service_money_yihu=0;
- if($tea_price && $tea_price>0){
- if($tea_price>=$data['extract_price']){
- $extract_price_yihu= $data['extract_price'];
- $service_money_yihu= $data['service_money'];
- }else{
- $extract_price_yihu= $tea_price;
- $service_money_yihu= bcmul($tea_price,'0.1',2);
- }
- }
- // if($extract_price_yihu>0){
- $insertAll[]=array(
- 'extract_id'=>$extract->extract_id,
- 'uid'=> $data['uid'],
- 'extract_type'=> $data["extract_type"],
- 'extract_price'=> $extract_price_yihu,
- 'service_money'=> $service_money_yihu,
- 'order_sn'=> $data['order_sn'],
- 'type'=> 1,//0- 幸福宝 1-一壶茶
- );
- // }
- $insertAll[]=array(
- 'extract_id'=>$extract->extract_id,
- 'uid'=> $data['uid'],
- 'extract_type'=> $data["extract_type"],
- 'extract_price'=> ($data['extract_price']-$extract_price_yihu),
- 'service_money'=> ($data['service_money']-$service_money_yihu),
- 'order_sn'=> $data['order_sn'],
- 'type'=> 0,//0- 幸福宝 1-一壶茶
- );
- DB::name('user_extract_item')->insertAll($insertAll);
- return $extract;
- });
- }
- SwooleTaskService::admin('notice', [
- 'type' => 'extract',
- 'title' => '您有一条新的提醒申请',
- 'id' => $data->extract_id
- ]);
- return true;
- }
- public function create_yhc($user, $merchant, $data)
- {
- Db::name("merchant")->where("mer_id", $merchant['mer_id'])->dec('brokerage_price', $data['extract_price'])->update();
- $data["bank_code"]=$merchant["bank_account"];
- $data["bank_address"]=$merchant["bank_deposit"];
- $data['order_sn'] = 'tx'.time().rand(100000, 999999);
- $data["real_name"]=$user['nickname'];
- $data['status'] = 0;
- $data['uid'] = $user['uid'];
- $data['types'] = 1;
- $data['type'] = 1;
- $data['mer_id'] = $merchant['mer_id'];
- $data['withdrawal_type'] =3;
- return $this->dao->create($data);
- }
- public function switchStatus($id,$data)
- {
- Db::transaction(function()use($id,$data){
- $extract = $this->dao->getWhere(['extract_id' => $id]);
- $user = app()->make(UserRepository::class)->get($extract['uid']);
- if($data['status'] == '-1'){
- if (!empty($extract['mer_id'])) {
- //商户提现逻辑处理
- $mer = app()->make(MerchantRepository::class)->get($extract['mer_id']);
- $brokerage_price = bcadd($mer['brokerage_price'] ,$extract['extract_price'],2);
- $mer->brokerage_price = $brokerage_price;
- $mer->save();
- } else {
- //用户提现逻辑处理
- if($extract['types']==1){
- if($extract['type']==3){
- $user->hongbao = bcadd($user->hongbao,$extract['extract_price'],2);
- }else {
- $brokerage_price = bcadd($user['brokerage_price'] ,$extract['extract_price'],2);
- //返回余额
- $user->brokerage_price = $brokerage_price;
- }
- }else{
- if($extract['type']==3){
- $user->hongbao = bcadd($user->hongbao,$extract['extract_price'],2);
- }else{
- $member_brokerage_price = bcadd($user['member_brokerage_price'] ,$extract['extract_price'],2);
- //返回余额
- $user->member_brokerage_price = $member_brokerage_price;
- Db::name('user_rich')->where('uid',$extract['uid'])->inc('red', $extract['extract_price'])->update();
- Db::name('user_rich_log')->insert([
- 'uid' => $extract['uid'],
- 'red' => $extract['extract_price'],
- 'pm' => 1,
- 'time' => time(),
- 'order_id' => 0,
- 'mark' => '提现失败返还红积分'
- ]);
- }
- }
- $user->save();
- }
- // //返回积分
- // $user->score = bcadd($user['score'] ,$extract['extract_price'],2);
- // $user->save();
- // Db::name('user_sign_score')->where("order_type","extract") -> where("order_id",$id) -> update(['status'=>0]);
- }else{
- if($extract['type']==3){
- //加入红包出账记录
- $insertdata = [
- 'uid'=> $user->uid,
- 'number' => $extract['extract_price'],
- 'surplus' => $user->hongbao,
- 'mark' => '红包提现',
- 'type' => 2,
- 'status' => 1,
- 'addtime' => time(),
- ];
- Db::name('user_sign_hongbao')->insertGetId($insertdata);
- }
- //积分扣除
- // Db::name('user_sign_score')->where("order_type","extract") -> where("order_id",$id) -> update(['status'=>1]);
- }
- $this->dao->update($id,$data);
- });
- Queue::push(SendTemplateMessageJob::class,[
- 'tempCode' => 'ORDER_DELIVER_SUCCESS',
- 'id' =>$id
- ]);
- }
- /**
- * @remarks 微信商家转账到零钱
- * @author Tang
- * @created 2023/10/31
- */
- public function WechatTransfers($id)
- {
- $userdata=Db::name('user_extract')
- ->alias('u_e')
- ->leftJoin('user_extract_openid u_e_o','u_e.uid=u_e_o.uid')
- ->where(['extract_id' => $id,'extract_type'=>1])
- ->field('u_e.extract_price,u_e.uid,u_e_o.openid,u_e_o.type as u_e_o_type,u_e.service_money,u_e.withdrawal_type,u_e.order_sn,u_e.mer_id')
- ->find();
- if($userdata and !empty($userdata)){
- if($userdata['withdrawal_type']==2){
- $money= bcsub($userdata['extract_price'],$userdata['service_money'],2);
- }else{
- $money= bcsub($userdata['extract_price'],$userdata['service_money'],2);
- }
- // $money=$userdata['extract_price'];//测试不加手续手续费
- $res=$this->transfer('提现到微信零钱', $userdata['order_sn'], $money, $userdata['openid'],$userdata['u_e_o_type']);
- if(isset($res['code']) && isset($res['message'])) {
- return ['code'=>500,'msg'=>$res['message']];
- }else{
- Db::name('user_extract')->where('extract_id',$id)->update(['wx_status'=>1]);
- return ['code'=>201,'msg'=>'微信正在处理'];
- }
- // else if($res['batch_status']=='ACCEPTED' || $res['batch_status']=='PROCESSING'){
- // Db::name('user_extract')->where('extract_id',$id)->update(['wx_status'=>1]);
- // return ['code'=>201,'msg'=>'微信正在处理'];
- // }else if($res['batch_status']=='FINISHED'){
- // //FINISHED:已完成。批次内的所有转账明细单都已处理完成
- // Db::name('entropy_barter_bill')->where('order_no', $userdata['order_sn'])->where('pm',2)->update(['status'=>2,'remarks'=>'已到账']);
- // Db::name('user_extract')->where('extract_id',$id)->update(['status'=>1]);
- // return ['code'=>200,'msg'=>'审核成功'];
- // }
- // return ['code'=>500,'msg'=>'提现错误'];
- }else{
- return ['code'=>200,'msg'=>'未找到数据'];
- }
- }
- /**
- * 定时任务3分钟查询一次审核中的微信待处理的订单
- * @return array|bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function wechat_extract(){
- $user_extract_data=Db::name('user_extract')->where('wx_status',1)->where('status',0)->select();
- foreach ($user_extract_data as $v){
- $data=$this->batch_id($v['order_sn']);
- Db::name('log')->insert(['data'=>'微信审核------'.json_encode($data)]);
- if(isset($data['transfer_batch']['batch_status']) && $data['transfer_batch']['batch_status']=='FINISHED' && $data['transfer_batch']['success_num']==1){
- Db::name('entropy_barter_bill')->where('order_no', $v['order_sn'])->where('pm',2)->update(['status'=>2,'remarks'=>'已到账']);
- Db::name('user_extract')->where('extract_id',$v['extract_id'])->update(['status'=>1]);
- }else if(isset($data['transfer_batch']['batch_status']) && $data['transfer_batch']['batch_status']=='FINISHED' && $data['transfer_batch']['success_num']<1){
- $fail_msg='微信二次审核已驳回';
- Db::name('user_extract')->where('order_sn',$v['order_sn'])->update(['fail_msg'=>$fail_msg,'status_time'=>date('Y-m-d H:i:s'),'status'=>'-1']);
- if($v['withdrawal_type']==1){
- Db::name('user')->where('uid',$v['uid'])->inc('brokerage_price',$v['extract_price'])->update();
- }else{
- $eb_bill=Db::name('entropy_barter_bill')->where('order_no',$v['order_sn'])->where('pm',2)->find();
- Db::name('entropy_barter_bill')->where('id',$eb_bill['id'])->where('pm',2)->update(['status'=>3,'remarks'=>$fail_msg]);
- Db::name('entropy_barter_user_'.$v['mer_id'])->where('eb_id',$eb_bill['to_id'])->inc('wallet',$v['extract_price'])->update();
- }
- }else if(isset($data['transfer_batch']['batch_status']) && $data['transfer_batch']['batch_status']=='CLOSED'){
- $fail_msg=(isset($data['transfer_batch']['close_reason']) && $data['transfer_batch']['close_reason']!='')?$data['transfer_batch']['close_reason']:'系统超时未审核,已取消';
- Db::name('user_extract')->where('order_sn',$v['order_sn'])->update(['fail_msg'=>$fail_msg,'status_time'=>date('Y-m-d H:i:s'),'status'=>'-1']);
- if($v['withdrawal_type']==1){
- Db::name('user')->where('uid',$v['uid'])->inc('brokerage_price',$v['extract_price'])->update();
- }else{
- $eb_bill=Db::name('entropy_barter_bill')->where('order_no',$v['order_sn'])->where('pm',2)->find();
- Db::name('entropy_barter_bill')->where('id',$eb_bill['id'])->where('pm',2)->update(['status'=>3,'remarks'=>$fail_msg]);
- Db::name('entropy_barter_user_'.$v['mer_id'])->where('eb_id',$eb_bill['to_id'])->inc('wallet',$v['extract_price'])->update();
- }
- }
- }
- return true;
- }
- /**
- * 商家转账到零钱(公众号:程序员在囧途)
- * @param $batch_name
- * @param $out_trade_no
- * @param $money
- * @param $openid
- */
- private function transfer($batch_name, $out_trade_no, $money, $openid,$type=0)
- {
- $url = 'https://api.mch.weixin.qq.com/v3/transfer/batches';
- $pars = [];
- if($type==1){
- $pars['appid'] = $this->wxapp['applet_app_id'];//直连商户的appid 小程序的
- }else{
- $pars['appid'] = $this->wxapp['app_id'];//直连商户的appid APP的
- }
- $pars['out_batch_no'] = $out_trade_no;//商户系统内部的商家批次单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一
- $pars['batch_name'] = $batch_name;//该笔批量转账的名称
- $pars['batch_remark'] = $batch_name;//转账说明,UTF8编码,最多允许32个字符
- $pars['total_amount'] = intval($money * 100);//转账总金额 单位为“分”
- $pars['total_num'] = 1;//转账总笔数
- $pars['transfer_detail_list'][0] = [
- 'out_detail_no' => 'transfer' . $out_trade_no,
- 'transfer_amount' => $pars['total_amount'],
- 'transfer_remark' => $batch_name,
- 'openid' => $openid
- ];//转账明细列表
- $token = $this->getToken($url,$pars);//获取token
- $res = $this->https_request($url, json_encode($pars), $token);//发送请求
- return json_decode($res, true);
- }
- /**
- * 通过商家批次单号查询批次单
- * @param $order_sn
- * @return mixed
- *
- * 【批次状态】 ACCEPTED:已受理。批次已受理成功,若发起批量转账的30分钟后,转账批次单仍处于该状态,可能原因是商户账户余额不足等。商户可查询账户资金流水,若该笔转账批次单的扣款已经发生,则表示批次已经进入转账中,请再次查单确认
- * PROCESSING:转账中。已开始处理批次内的转账明细单
- * FINISHED:已完成。批次内的所有转账明细单都已处理完成
- * CLOSED:已关闭。可查询具体的批次关闭原因确认
- */
- private function batch_id($order_sn)
- {
- $url = 'https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/'.$order_sn.'?need_query_detail=false';
- $token = $this->getToken($url,null,'GET');//获取token
- $res = $this->https_request($url, null, $token);//发送请求
- return json_decode($res, true);
- }
- private function https_request($url, $data = null, $token)
- {
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, (string)$url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
- if (!empty($data)) {
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- }
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- //添加请求头
- $headers = [
- 'Authorization:WECHATPAY2-SHA256-RSA2048 ' . $token,
- 'Accept: application/json',
- 'Content-Type: application/json; charset=utf-8',
- 'User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
- ];
- if (!empty($headers)) {
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
- }
- $output = curl_exec($curl);
- curl_close($curl);
- return $output;
- }
- private function getToken($url,$pars,$http_method='POST')
- {
- // $http_method = $http_method;//请求方法(GET,POST,PUT)
- $timestamp = time();//请求时间戳
- $url_parts = parse_url($url);//获取请求的绝对URL
- $nonce = $timestamp . rand('10000', '99999');//请求随机串
- if($pars){
- $body = json_encode((object)$pars);//请求报文主体
- }else{
- $body = '';
- }
- $stream_opts = [
- "ssl" => [
- "verify_peer" => false,
- "verify_peer_name" => false,
- ]
- ];
- // try {
- $filePath = App::getRootPath();
- $certPem= [
- 'certPem' => $filePath . $this->wxapp['certPem'],
- 'keyPem' => $filePath . $this->wxapp['keyPem'],
- ];
- $apiclient_cert_path = $certPem['certPem'];
- $apiclient_key_path = $certPem['keyPem'];
- $apiclient_cert_arr = openssl_x509_parse(file_get_contents($apiclient_cert_path, false, stream_context_create($stream_opts)));
- $serial_no = $apiclient_cert_arr['serialNumberHex'];//证书序列号
- $mch_private_key = file_get_contents($apiclient_key_path, false, stream_context_create($stream_opts));//密钥
- $merchant_id = $this->wxapp['mchid'];
- $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
- $message = $http_method . "\n" .
- $canonical_url . "\n" .
- $timestamp . "\n" .
- $nonce . "\n" .
- $body . "\n";
- openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
- $sign = base64_encode($raw_sign);//签名
- // $schema = 'WECHATPAY2-SHA256-RSA2048';
- $token = sprintf('mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"',
- $merchant_id, $nonce, $timestamp, $serial_no, $sign);//微信返回token
- // } catch (\Exception $e) {
- // throw new \Exception(['msg' => $e->getMessage()]);
- // }
- return $token;
- }
- /**
- * 企业付款到零钱
- * @param $id
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function WechatTransfers_qiye($id)
- {
- // $extract = $this->dao->getWhere(['extract_id' => $id]);
- $userdata=Db::name('user_extract')
- ->alias('u_e')
- ->leftJoin('user_extract_openid u_e_o','u_e.uid=u_e_o.uid')
- ->where(['extract_id' => $id,'extract_type'=>1])
- ->field('u_e.extract_price,u_e.uid,u_e_o.openid,u_e.service_money,u_e.withdrawal_type,u_e.order_sn')
- ->find();
- if($userdata and !empty($userdata)){
- $params["mch_appid"]='wxbf753066ac8686ba';
- $params["mchid"] = '1605734712';
- $params["nonce_str"]= mt_rand(100000000,999999999);
- $params["partner_trade_no"] = $userdata['order_sn'];
- if($userdata['withdrawal_type']==2){
- $params["amount"]= bcmul(bcsub($userdata['extract_price'],$userdata['service_money'],2),100);
- }else{
- $params["amount"]= bcmul(bcsub($userdata['extract_price'],$userdata['service_money'],2),100);
- }
- $params["desc"]= '提现到微信零钱';
- $params["openid"]= $userdata['openid'];
- $params["check_name"]= 'NO_CHECK';
- $sign =$this->getSign($params);
- //生成签名
- $params['sign'] = $sign;
- //构造XML数据
- $xmldata = $this->ToXml($params); //数组转XML
- $url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
- //发送post请求
- $res = $this->curl_post_ssl($url, $xmldata,[]);
- // Db::name('log')->insert(['data'=>json_encode($res)]);
- if(!$res){
- return ['code'=>500,'msg'=>'请求未能发送成功'];
- }
- //付款结果分析
- $content = $this->FromXml($res); //xml转数组
- Db::name('log')->insert(['data'=>'【微信提现返回】'.json_encode($content)]);
- if($content['result_code']=="SUCCESS"){
- $this->WechatTransfers_query($userdata['order_sn']);
- return ['code'=>200,'msg'=>'成功'];
- }else{
- // Db::name('log')->insert(['data'=>'else进来了']);
- Db::name('user_extract')->where('order_sn',$userdata['order_sn'])->update(['fail_msg'=>$content['err_code_des'],'status_time'=>date('Y-m-d H:i:s'),'status'=>'-1']);
- $extract_data=Db::name('user_extract')->where('order_sn',$userdata['order_sn'])->find();
- if($extract_data['withdrawal_type']==1){
- Db::name('user')->where('uid',$extract_data['uid'])->inc('brokerage_price',$extract_data['extract_price'])->update();
- }else{
- $eb_bill=Db::name('entropy_barter_bill')->where('order_no',$extract_data['order_sn'])->where('pm',2)->find();
- Db::name('entropy_barter_bill')->where('id',$eb_bill['id'])->where('pm',2)->update(['status'=>3,'remarks'=>$content['err_code_des']]);
- Db::name('entropy_barter_user_'.$extract_data['mer_id'])->where('eb_id',$eb_bill['to_id'])->inc('wallet',$extract_data['extract_price'])->update();
- }
- return ['code'=>201,'msg'=>$content['err_code_des']];
- }
- }else{
- return ['code'=>200,'msg'=>'未找到数据'];
- }
- }
- //付款到零钱查询
- public function WechatTransfers_query($order_sn)
- {
- // Db::name('log')->insert(['data'=>'微信提现查询走进来了']);
- $params["appid"]='wxbf753066ac8686ba';
- $params["mch_id"] = '1605734712';
- $params["nonce_str"]= mt_rand(100000000,999999999);
- $params["partner_trade_no"]= $order_sn;
- $sign =$this->getSign($params);
- //生成签名
- $params['sign'] = $sign;
- //构造XML数据
- $xmldata = $this->ToXml($params); //数组转XML
- $url='https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo';
- //发送post请求
- $res = $this->curl_post_ssl($url, $xmldata,[]);
- if(!$res){
- return ['code'=>500,'msg'=>'请求未能发送成功'];
- }
- //付款结果分析
- $content = $this->FromXml($res); //xml转数组
- // Db::name('log')->insert(['data'=>'查询'.json_encode($content)]);
- try {
- if($content['status']=='SUCCESS'){
- Db::name('entropy_barter_bill')->where('order_no',$content['partner_trade_no'])->where('pm',2)->update(['status'=>2,'remarks'=>'已到账']);
- Db::name('user_extract')->where('order_sn',$content['partner_trade_no'])->update(['status'=>1]);
- //$bill=Db::name('entropy_barter_bill')->where('order_no',$content['partner_trade_no'])->where('pm',2)->find();
- //$mer_id=Db::name('user_extract')->where('order_sn',$content['partner_trade_no'])->value('mer_id');
- //Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$bill['to_id'])->dec('wallet',$bill['number'])->update();
- }
- }catch (\Exception $e) {
- Db::name('log')->insert(['data'=>'提现到微信查询出错:'.$e->getFile().':'.$e->getLine().'【'.$e->getMessage().'】']);
- }
- }
- /**
- * @remarks 支付宝付款到零钱
- * @author Tang
- * @created 2021/9/9 12:59
- */
- public function AliTransfers($id)
- {
- try {
- $userdata=Db::name('user_extract')
- ->where(['extract_id'=>$id])
- ->find();
- $identity=Db::name('user')->where('uid',$userdata['uid'])->value('ali_user_id');
- if($userdata and !empty($userdata)){
- $app_cert_path=dirname(__FILE__). '/../../../../extend/alipay/aop/cert/appCertPublicKey.crt';
- $alipay_cert_path=dirname(__FILE__). '/../../../../extend/alipay/aop/cert/alipayCertPublicKey.crt';
- $alipay_root_cert_path=dirname(__FILE__). '/../../../../extend/alipay/aop/cert/alipayRootCert.crt';
- $url = "https://openapi.alipay.com/gateway.do";
- $app_id="2021002194632049";
- $privateKey="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDGxceDFVT6VTYClinyAdY4PxE6MadNYLZ3sbLOLV14e39kuu1lkKDBZ/KPRNruPlSPGdiRVe+L8v4rsVk6bthsS/vMk5aH1wQyt58/HvHmZ5QVo3U5UD7cgqqefTcRJjKhjjM1rU/OrOkOqyssaLRukW3jeKRlBccUgtaGsXXrbMxWYpzl1OMDhKRRUVxu3LTfqlMpHghOasQrgyD92q9wlUN7U6hBYzGUocO/N3sz97PZwptwWAW0r3CFdlLCpgnMr+xb/Zh8td1OKGl3wEghiGavgDDlc2+w/xtk1SZ3pJbnGAU+D+oyJ6r76po6vkyGIlLrKp/zQ50az7fObzgNAgMBAAECggEBAK60szERlMkaEAih92gQGTsCo5+keMnX0UjO1LvGv7rfwQ7GBVYZklGrjVRDTrHL8wJ70w+amptFDgVVMXncZzh4aG5c4heu8q+pGLyf9DlwnIWQT736O+YQqun2YGogSqwYkgYBuH2NGKKd66pytPPhutYN+WAZfesXPHrSizRJtZMfuZvvGzm6ZJLZ1LmhvkOuLrX4xrJGRs1nAwZOmOfi4MY5VASblfPj59fUim9hErocNaX4uiMVwmhQl2QuOM/EbTd1UkW+dkV/gyQMOFzpcfN+SEi+hdLN+JiR9TVEcwity6ihOG5+3X33GKzfY4WFxeHHUaqA0SQWSkKofMECgYEA5OF5Imtq8/6JjWJ0jvYCpUnj9742McGJZTWBoTn9Hp0d3bwyE3YbH8pBVJyvzlfPKB9TUjE2FzVZvQtxEu+ZxToccp/LPqlgITWNHCmEtzAgXW7ww2PafgDZJ2QRSyjLUeRIWSAkeilj64XMCEC/bEs/nb5nmUb2gnsNTvvpMLUCgYEA3lMMtaIZH1fMI4XMNaPFzeRiKc0FIcLEem/efnPetPuOCujIWQJ/x9cCDCcfqO59I1FXQuiC/E1dFvme2qs/H7h2bFu8RG0M/ZQWd9twg31Sh+R7gCQakFERag8HXc4AWfBGXCvMu1SmSovU49KecSLxYGOAUdp77j1GxtLiePkCgYAQjc45ExPVOd+w/iH4BQsD8Wgvju5Ugu7xBwGtK4iHIk36r5XfmnczwWkgOYTto6Qz/rAEDdMfspge+CjhebrhbOaJ08zbZ1ywijL+inIy3aQ5ncCEIUC4RE9wbehiSz0JWz1wVMbOnxe+/RpYrnYp2vdq7U6I430IyuWXhNjE0QKBgEtJUmd7oghEIgPxfiq37/b+HOPM4q0BGKnhkjW+JS+idAJru9SwjPbub2oQIZ+CS2wXUnZ86EZqKFjsZQflr7WdMLUXB5UgXKLOcCFcdSiB2t3b2JqXH0u5uCzzM+pnJSVPwXPa/TR+wOVDnu8bVr43OAgNCdouI4OUyo/vv/N5AoGATJaIvpsZ9v1zmhbtJbgPBM9dhD2PIp2ufZ7yvhGGzA02FqAbyAeVsI2d+W+uA6jJ1X87x27pQv//mFoFXStxX3/bhdgTWbUYEWobAhw1jBS1rMQfLuBGGI/LsHGhzau3U+59erC5sYhGgZKSdXDyjOduWQlPWAv6ufkNZ+I3FCU=";
- // 证书模式的测试
- $alipayConfig = new AlipayConfig();
- $alipayConfig->setAppId($app_id);
- $alipayConfig->setCharset("utf-8");
- $alipayConfig->setFormat("json");
- $alipayConfig->setSignType("RSA2");
- $alipayConfig->setServerUrl($url);
- $alipayConfig->setPrivateKey($privateKey);
- // content 和 path 只需要设置一个即可
- $alipayConfig->setAppCertPath($app_cert_path);
- //$alipayConfig->setAppCertContent()
- $alipayConfig->setAlipayPublicCertPath($alipay_cert_path);
- //$alipayConfig->setAlipayPublicCertContent()
- $alipayConfig->setRootCertPath($alipay_root_cert_path);
- //$alipayConfig->setRootCertContent()
- $aop = new AopCertClient($alipayConfig);
- $aop->isCheckAlipayPublicCert = true;
- $order_title='提现';
- if($userdata['withdrawal_type']==1){
- $order_title='幸福宝提现';
- $userdata['extract_price']=bcsub($userdata['extract_price'],$userdata['service_money']);
- }elseif($userdata['withdrawal_type']==2){
- $mer_name=Db::name('merchant')->where('mer_id',$userdata['mer_id'])->value('mer_name');
- $order_title='幸福宝-'.$mer_name.'提现';
- $userdata['extract_price']=bcsub($userdata['extract_price'],$userdata['service_money']);
- }
- // Db::name('log')->insert(['data'=>'AopCertClient']);
- $parameter = "{".
- "\"out_biz_no\":\"".$userdata['order_sn']."\",".
- "\"remark\":\"提现到支付宝\",".
- // "\"business_params\"":.json_encode(['payer_show_name_use_alias'=>'北京天地博爱网络科技有限公司']).
- "\"business_params\":\"{'payer_show_name_use_alias':'北京天地博爱网络科技有限公司'}\",".
- "\"biz_scene\":\"DIRECT_TRANSFER\",".
- "\"payee_info\":{".
- "\"identity\":\"".$identity."\",".
- "\"identity_type\":\"ALIPAY_USER_ID\",".
- // "\"name\":\"".$userdata['real_name']."\"".
- "},".
- "\"trans_amount\":\"".$userdata['extract_price']."\",".
- "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\",".
- "\"order_title\":\"".$order_title."\"".
- "}";
- $request = new AlipayFundTransUniTransferRequest ();
- $request->setBizContent($parameter);
- $response = $aop->execute($request);
- Db::name('log')->insert(['data'=>'【支付宝提现返回结果】'.$response]);
- $response=json_decode($response,true);
- if($response['alipay_fund_trans_uni_transfer_response']['code']=='10000'){
- return ['code'=>200,'msg'=>'成功'];
- }else{
- return ['code'=>201,'msg'=>$response['alipay_fund_trans_uni_transfer_response']['sub_msg']];
- }
- }else{
- return ['code'=>200,'msg'=>'未找到数据'];
- }
- }catch (Exception $exception){
- Db::name("log")->insert(array('data'=>$exception->getFile().':'.$exception->getLine().'【'.$exception->getMessage().'】'));//日志记录
- }
- }
- /*
- * Effect 微信生成签名
- * author tangshiwei
- * time 2021-09-09
- * */
- public function getSign($params) {
- ksort($params); //将参数数组按照参数名ASCII码从小到大排序
- foreach ($params as $key => $item) {
- if (!empty($item)) {
- //剔除参数值为空的参数
- $newArr[] = $key.'='.$item; // 整合新的参数数组
- }
- }
- $stringA = implode("&", $newArr); //使用 & 符号连接参数
- $stringSignTemp = $stringA."&key=70yfchPMifQCESGSFr53vOZmUJZ8Srql";//拼接key
- // key是在商户平台API安全里自己设置的
- $stringSignTemp = md5($stringSignTemp); //将字符串进行MD5加密
- $sign = strtoupper($stringSignTemp); //将所有字符转换为大写
- return $sign;
- }
- /**
- * @remarks curl 请求
- * @author Tang
- * @created 2021/9/9 13:14
- */
- function curl_post_ssl($url, $xmldata, $second = 30, $aHeader = array()){
- $dirs= App::getRootPath();
- $ch = curl_init();//初始化curl
- curl_setopt($ch, CURLOPT_TIMEOUT, $second);//设置执行最长秒数
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
- curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 终止从服务端进行验证
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//
- curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');//证书类型
- curl_setopt($ch, CURLOPT_SSLCERT, $dirs.'pkey/cert/apiclient_cert.pem');//证书位置
- curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');//CURLOPT_SSLKEY中规定的私钥的加密类型
- curl_setopt($ch, CURLOPT_SSLKEY, $dirs.'pkey/cert/apiclient_key.pem');//证书位置
- if (count($aHeader) >= 1) {
- curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);//设置头部
- }
- curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xmldata);//全部数据使用HTTP协议中的"POST"操作来发送
- $data = curl_exec($ch);//执行回话
- if ($data) {
- curl_close($ch);
- return $data;
- } else {
- $error = curl_errno($ch);
- echo "call faild, errorCode:$error\n";
- curl_close($ch);
- return false;
- }
- }
- /**
- * @remarks 数组转xml
- * @author Tang
- * @created 2021/9/9 13:14
- */
- public function ToXml($data=array())
- {
- if(!is_array($data) || count($data) <= 0)
- {
- return '数组异常';
- }
- $xml = "<xml>";
- foreach ($data as $key=>$val)
- {
- if (is_numeric($val)){
- $xml.="<".$key.">".$val."</".$key.">";
- }else{
- $xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
- }
- }
- $xml.="</xml>";
- return $xml;
- }
- /**
- * @remarks xml转数组
- * @author Tang
- * @created 2021/9/9 13:15
- */
- public function FromXml($xml)
- {
- if(!$xml){
- echo "xml数据异常!";
- }
- //将XML转为array
- //禁止引用外部xml实体
- libxml_disable_entity_loader(true);
- $data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
- return $data;
- }
- public function band_account($type,$account,$info,$uid){
- $accountinfo=Db::name("user_withdraw_account")->where(["account_type"=>$type,"user_id"=>$uid])->find();
- $data=[
- "account_type"=>$type,
- "account"=>$account,
- "info"=>$info,
- 'update_time'=>date("Y-m-d H:i:s"),
- ];
- if ($accountinfo){
- Db::name("user_withdraw_account")->where("id",$accountinfo["id"])->update($data);
- }else{
- $data["user_id"]=$uid;
- $data["create_time"]=date("Y-m-d H:i:s");
- Db::name("user_withdraw_account")->insert($data);
- }
- return ["msg"=>'绑定成功'];
- }
- public function band_openid($openid,$uid){
- $user_data["wechat_user_id"]=$openid;
- $user_count=Db::name('user')->where($user_data)->count();
- if($user_count>0){
- return true;
- }
- $data["openid"]=$openid;
- $count=Db::name("user_extract_openid")->where($data)->count();
- if($count>0){
- return false;
- }
- $data["uid"]=$uid;
- $wx_type=input("wx_type/d",0);
- $data["type"]=$wx_type==1?1:0;
- Db::name("user_extract_openid")->insert($data);
- return true;
- // return ["msg"=>'绑定成功'];
- }
- /*获取绑卡账户*/
- public function band_account_info($type,$uid){
- if($type=='1'){
- $res=Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
- if(!$res){
- return false;
- }
- return true;
- }
- $res = Db::name('user') -> where('uid',$uid) -> value('ali_user_id');
- if($res && $res != '0' && $res != ''){
- return true;
- }
- return false;
- // $account=Db::name("user_withdraw_account")->where(["account_type"=>$type,"user_id"=>$uid])->find();//
- //
- // if ($account){
- // if($account['account_type'] ==3){
- // $account['icon'] = '';
- // }
- // return $account;
- // }else{
- // return false;
- // }
- }
- public function listBank($where)
- {
- return Db::name("user_withdraw_account")->where($where)->order('id desc')->select();
- }
- /*添加银行卡*/
- public function createBank($data){
- $data["account_type"] = 3;
- $data["info"] = $data['user_name'];
- $real_name = $this->real_info($data['user_id']);
- if(!$real_name){
- return ['code'=>400,'msg'=>'请先实名认证'];
- }
- if($real_name['user_name'] != $data['user_name']){
- return ['code'=>400,'msg'=>'认证信息与银行卡绑定用户不符'];
- }
- if(Db::name("user_withdraw_account")->where(['user_id'=>$data['user_id'],'account_type'=>3,'status'=>0])->value("id")){
- //操作修改
- $data['update_time'] = date("Y-m-d H:i:s");
- Db::name("user_withdraw_account")->where(['user_id'=>$data['user_id'],'account_type'=>3,'status'=>0])->update($data);
- return Db::name("user_withdraw_account")->where(['user_id'=>$data['user_id'],'account_type'=>3,'status'=>0])->value("id");
- // return ['code'=>400,'msg'=>'只能绑定一张银行卡'];
- }
- $data['create_time'] = date("Y-m-d H:i:s");
- return Db::name("user_withdraw_account")->insertGetId($data);
- }
- /*修改银行卡*/
- public function saveBank($where=[],$data=[]){
- $data['update_time'] = date("Y-m-d H:i:s");
- $res = Db::name("user_withdraw_account")->where($where)->update($data);
- return $res;
- }
- /*银行卡列表*/
- public function list($where=[]){
- $res = Db::name("user_withdraw_account")->where($where)->select();
- return $res;
- }
- /*用户认证信息*/
- public function real_info($uid){
- $data = Db::name("user_certification")->where(["uid"=>$uid,'status'=>1])->find();
- return $data;
- }
- }
|