| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <?php
- /**
- * @package merchant
- *
- * @author Qinii
- * @day 2020-06-16
- *
- *
- */
- namespace app\controller\api\user;
- use alipay\aop\AopCertClient;
- use alipay\aop\AopClient;
- use app\controller\api\Auth;
- use crmeb\basic\BaseController;
- use app\common\repositories\system\groupData\GroupDataRepository;
- use think\App;
- use app\validate\api\UserExtractValidate as validate;
- use app\common\repositories\user\UserExtractRepository as repository;
- use think\facade\Cache;
- use think\facade\Db;
- use think\facade\Log;
- class UserExtract extends BaseController
- {
- /**
- * @var repository
- */
- public $repository;
- protected $merId;
- protected $source;
- /**
- * UserExtract constructor.
- * @param App $app
- * @param repository $repository
- */
- public function __construct(App $app,repository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- $this->source = $this->request->header('source');
- $this->merId = $this->request->header('merId');
- }
- public function lst()
- {
- [$page,$limit] = $this->getPage();
- $where = $this->request->params(['status']);
- $where['uid'] = $this->request->uid();
- return app('json')->success($this->repository->serach($where,$page,$limit));
- }
- /**
- * @param $phone
- * @param $code
- * @return bool
- * @author Qinii
- * @day 2020-06-12
- */
- public function checkSmsCode($phone, $code)
- {
- $sms_key = 'api.auth.sms.' . $phone;
- if (!$cache_code = Cache::get($sms_key)) return false;
- if ($code != $cache_code) return false;
- Cache::delete($sms_key);
- return true;
- }
- /**
- * 申请提现
- * extract_type 1微信 2支付宝
- * @param validate $validate
- * @return mixed
- */
- public function create(validate $validate)
- {
- $data = $this->checkParams($validate);
- $user = $this->request->userInfo();
- $uid = $this->request->uid();
- $type = input("type/d", 1);//1-佣金 2-红积分
- $sms_code = $this->request->param('sms_code');
- if (!$this->checkSmsCode($user['account'], $sms_code)){
- return app('json')->fail('验证码不正确');
- }
- if(!in_array($data["extract_type"],[1,2,3])){
- return app('json')->fail('不支持的类型,请选择微信或支付宝');
- }
- if ($type == 1) {
- if ($user['brokerage_price'] < (systemConfig('withdrawal_money')))
- return app('json')->fail('未到达提现最低额度');
- if ($user['brokerage_price'] < $data['extract_price'])
- return app('json')->fail('提现金额不足');
- // if ($data['extract_type'] == 3)
- // return app('json')->fail('银行卡暂未开通');
- if($data["extract_type"] == 1){
- $user_extract_openid=Db::name('user_extract_openid')->where('uid',$uid)->find();
- if(!$user_extract_openid || $user_extract_openid['openid']==''){
- return app('json')->fail('请先绑定提现微信');
- }
- }
- }else{
- if ($user['member_brokerage_price'] < (systemConfig('withdrawal_money')))
- return app('json')->fail('未到达提现最低额度');
- if ($user['member_brokerage_price'] < $data['extract_price'])
- return app('json')->fail('提现金额不足');
- }
- $res=$this->repository->create($user,$data,$uid,$type);
- if ($res){
- return app('json')->success('申请已提交');
- }else{
- return app('json')->success(["code"=>2,"msg"=>"请绑定账号"]);
- }
- }
- public function checkParams(validate $validate)
- {
- $data = $this->request->params(['extract_type','bank_id','bank_code','bank_address','alipay_code','wechat','extract_pic','extract_price','real_name']);
- // $validate->check($data);
- return $data;
- }
- public function bankLst()
- {
- [$page,$limit] = $this->getPage();
- $data = app()->make(GroupDataRepository::class)->groupData('bank_list',0,$page,$limit);
- return app('json')->success($data);
- }
- /**
- * type 1微信 2支付宝
- * account 账号
- * info 1 收款码 / 2 姓名
- * @return mixed
- */
- public function band_account(){
- $type=input("type/d","1");
- $account=input("account/s","");
- $info=input("info/s","");
- $uid = $this->request->uid();
- $res=$this->repository->band_account($type,$account,$info,$uid);
- return app('json')->success($res);
- }
- public function band_openid(){
- $type=input("type/d","1");
- $openid=input("openid","");
- if(empty($openid)){
- return app('json')->fail("绑定微信失败");
- }
- $uid = $this->request->uid();
- $res=$this->repository->band_openid($openid,$uid);
- if($res){
- return app('json')->success('绑定成功');
- }
- return app('json')->fail("此微信已绑定其他账户");
- }
- /**
- * type 1微信 2支付宝
- * @return mixed
- */
- public function get_band_account_info(){
- $type=input("type/d","1");
- $uid = $this->request->uid();
- $res= $this->repository->band_account_info($type,$uid);
- if ($res){
- return app('json')->success("绑定成功");
- }else{
- return app('json')->fail("请绑定");
- }
- }
- public function withdrawal_notify($type)
- {
- // Db::name('log')->insert(['data'=>'支付宝提现回调1111']);
- $data=$this->request->param();
- // Db::name('log')->insert(['data'=>'支付宝提现回调'.json_encode($data)]);
- Log::info($data);
- switch ($type){
- case 'zfb':
- $aop =new AopCertClient();
- $aop->alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB";
- $flag = $aop->rsaCheckV1($data, dirname(__FILE__). '/../../../../extend/alipay/aop/cert/alipayCertPublicKey.crt', "RSA2");
- if($flag){
- $biz_content=json_decode($data['biz_content'],true);
- // Db::name('log')->insert(['data'=>'支付宝提现回调验签成功']);
- Db::name('entropy_barter_bill')->where('order_no',$biz_content['out_biz_no'])->where('pm',2)->update(['status'=>2,'remarks'=>'已到账']);
- Db::name('user_extract')->where('order_sn',$biz_content['out_biz_no'])->update(['status'=>1]);
- // $bill=Db::name('entropy_barter_bill')->where('order_no',$biz_content['out_biz_no'])->where('pm',2)->find();
- // $mer_id=Db::name('user_extract')->where('order_sn',$biz_content['out_biz_no'])->value('mer_id');
- // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$bill['to_id'])->dec('wallet',$bill['number'])->update();
- echo "success";
- }else{
- // Db::name('log')->insert(['data'=>'支付宝提现回调验签失败']);
- echo "error";
- }
- case 'wx':
- }
- }
- }
|