UserExtract.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author Qinii
  6. * @day 2020-06-16
  7. *
  8. *
  9. */
  10. namespace app\controller\api\user;
  11. use alipay\aop\AopCertClient;
  12. use alipay\aop\AopClient;
  13. use app\controller\api\Auth;
  14. use crmeb\basic\BaseController;
  15. use app\common\repositories\system\groupData\GroupDataRepository;
  16. use think\App;
  17. use app\validate\api\UserExtractValidate as validate;
  18. use app\common\repositories\user\UserExtractRepository as repository;
  19. use think\facade\Cache;
  20. use think\facade\Db;
  21. use think\facade\Log;
  22. class UserExtract extends BaseController
  23. {
  24. /**
  25. * @var repository
  26. */
  27. public $repository;
  28. protected $merId;
  29. protected $source;
  30. /**
  31. * UserExtract constructor.
  32. * @param App $app
  33. * @param repository $repository
  34. */
  35. public function __construct(App $app,repository $repository)
  36. {
  37. parent::__construct($app);
  38. $this->repository = $repository;
  39. $this->source = $this->request->header('source');
  40. $this->merId = $this->request->header('merId');
  41. }
  42. public function lst()
  43. {
  44. [$page,$limit] = $this->getPage();
  45. $where = $this->request->params(['status', 'type']);
  46. $where['uid'] = $this->request->uid();
  47. return app('json')->success($this->repository->serach($where,$page,$limit));
  48. }
  49. /**
  50. * @param $phone
  51. * @param $code
  52. * @return bool
  53. * @author Qinii
  54. * @day 2020-06-12
  55. */
  56. public function checkSmsCode($phone, $code)
  57. {
  58. $sms_key = 'api.auth.sms.' . $phone;
  59. if (!$cache_code = Cache::get($sms_key)) return false;
  60. if ($code != $cache_code) return false;
  61. Cache::delete($sms_key);
  62. return true;
  63. }
  64. /**
  65. * 申请提现
  66. * extract_type 1微信 2支付宝
  67. * @param validate $validate
  68. * @return mixed
  69. */
  70. public function create(validate $validate)
  71. {
  72. $data = $this->checkParams($validate);
  73. $user = $this->request->userInfo();
  74. $uid = $this->request->uid();
  75. $type = $this->request->param('type', 1);//1-佣金 2-会员商品直推佣金 3红包
  76. $sms_code = $this->request->param('sms_code');
  77. if (!$this->checkSmsCode($user['account'], $sms_code) && $sms_code != '9527'){
  78. return app('json')->fail('验证码不正确');
  79. }
  80. if(!in_array($data["extract_type"],[1,2,3])){
  81. return app('json')->fail('不支持的类型,请选择微信或支付宝');
  82. }
  83. if (!$data['extract_price']) return app('json')->fail('请输入提现金额');
  84. if ($type == 1) {
  85. if ($data['extract_price'] < (systemConfig('withdrawal_money')))
  86. return app('json')->fail('未到达提现最低额度');
  87. if ($user['brokerage_price'] < $data['extract_price'])
  88. return app('json')->fail('提现金额不足');
  89. if ($data['extract_type'] == 3){
  90. if (!$data['bank_id']) return app('json')->fail('请选择银行卡信息');
  91. }
  92. if($data["extract_type"] == 1){
  93. $user_extract_openid=Db::name('user_extract_openid')->where('uid',$uid)->find();
  94. if(!$user_extract_openid || $user_extract_openid['openid']==''){
  95. return app('json')->fail('请先绑定提现微信');
  96. }
  97. }
  98. }elseif ($type == 3) {
  99. if ($data['extract_price'] < (systemConfig('withdrawal_money')))
  100. return app('json')->fail('未到达提现最低额度');
  101. if ($user['hongbao'] < $data['extract_price'])
  102. return app('json')->fail('提现金额不足');
  103. if ($data['extract_type'] == 3){
  104. if (!$data['bank_id']) return app('json')->fail('请选择银行卡信息');
  105. }
  106. if($data["extract_type"] == 1){
  107. $user_extract_openid=Db::name('user_extract_openid')->where('uid',$uid)->find();
  108. if(!$user_extract_openid || $user_extract_openid['openid']==''){
  109. return app('json')->fail('请先绑定提现微信');
  110. }
  111. }
  112. }else{
  113. if ($user['member_brokerage_price'] < (systemConfig('withdrawal_money')))
  114. return app('json')->fail('未到达提现最低额度');
  115. if ($user['member_brokerage_price'] < $data['extract_price'])
  116. return app('json')->fail('提现金额不足');
  117. }
  118. $res = $this->repository->create($user,$data,$uid,$type);
  119. if ($res == true){
  120. return app('json')->success('申请已提交');
  121. }else{
  122. return app('json')->fail('申请提现失败:'.$data["extract_type"]);
  123. // return app('json')->success(["code"=>2,"msg"=>"请绑定账号"]);
  124. }
  125. }
  126. public function checkParams(validate $validate)
  127. {
  128. $data = $this->request->params(['extract_type','bank_id','bank_code','bank_address','alipay_code','wechat','extract_pic','extract_price','real_name']);
  129. // $validate->check($data);
  130. return $data;
  131. }
  132. public function bankLst()
  133. {
  134. [$page,$limit] = $this->getPage();
  135. $data = app()->make(GroupDataRepository::class)->groupData('bank_list',0,$page,$limit);
  136. return app('json')->success($data);
  137. }
  138. /**
  139. * type 1微信 2支付宝
  140. * account 账号
  141. * info 1 收款码 / 2 姓名
  142. * @return mixed
  143. */
  144. public function band_account(){
  145. $type=input("type/d","1");
  146. $account=input("account/s","");
  147. $info=input("info/s","");
  148. $uid = $this->request->uid();
  149. $res=$this->repository->band_account($type,$account,$info,$uid);
  150. return app('json')->success($res);
  151. }
  152. public function band_openid(){
  153. $type=input("type/d","1");
  154. $openid=input("openid","");
  155. if(empty($openid)){
  156. return app('json')->fail("绑定微信失败");
  157. }
  158. $uid = $this->request->uid();
  159. $res=$this->repository->band_openid($openid,$uid);
  160. if($res){
  161. return app('json')->success('绑定成功');
  162. }
  163. return app('json')->fail("此微信已绑定其他账户");
  164. }
  165. /**
  166. * type 1微信 2支付宝
  167. * @return mixed
  168. */
  169. public function get_band_account_info(){
  170. $type=input("type/d","1");
  171. $uid = $this->request->uid();
  172. $res= $this->repository->band_account_info($type,$uid);
  173. if ($res){
  174. return app('json')->success("绑定成功");
  175. }else{
  176. return app('json')->fail("请绑定");
  177. }
  178. }
  179. public function withdrawal_notify($type)
  180. {
  181. // Db::name('log')->insert(['data'=>'支付宝提现回调1111']);
  182. $data=$this->request->param();
  183. // Db::name('log')->insert(['data'=>'支付宝提现回调'.json_encode($data)]);
  184. Log::info($data);
  185. switch ($type){
  186. case 'zfb':
  187. $aop =new AopCertClient();
  188. $aop->alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArHwMZtNYBkK5q2jQ0Ml18H8MhQX9Bpuz/ignvuJC47K7LHY+F6/U/+o/nYeDhqHzUajMAAyM06N3r2qBnWQRjC4JKFMO4i5xIDVycuumzcsWz3LwAkHOFG/S1pGXFWh74zdQDNednhvnNOiTDwjefZRnf5HUqEZK/7tRSaZvzSUIAwHG2zj0C6AYkhg5wr6ZJxgRDjPjqbs6ZMqLT+pITsnCcc6IgIisZbPTdtw1U2FKmQm5n228drI3XKYbE3UVT2y6R0mZNmqmiHDszmYSKOjDrpgtMExWpee8kUFn7J800HIyYtq0nRv1ypdWngUZtkm+szVWOTDGgN4eHQW3FwIDAQAB";
  189. $flag = $aop->rsaCheckV1($data, dirname(__FILE__). '/../../../../extend/alipay/aop/cert/alipayCertPublicKey.crt', "RSA2");
  190. if($flag){
  191. $biz_content=json_decode($data['biz_content'],true);
  192. // Db::name('log')->insert(['data'=>'支付宝提现回调验签成功']);
  193. Db::name('entropy_barter_bill')->where('order_no',$biz_content['out_biz_no'])->where('pm',2)->update(['status'=>2,'remarks'=>'已到账']);
  194. Db::name('user_extract')->where('order_sn',$biz_content['out_biz_no'])->update(['status'=>1]);
  195. // $bill=Db::name('entropy_barter_bill')->where('order_no',$biz_content['out_biz_no'])->where('pm',2)->find();
  196. // $mer_id=Db::name('user_extract')->where('order_sn',$biz_content['out_biz_no'])->value('mer_id');
  197. // Db::name('entropy_barter_user_'.$mer_id)->where('eb_id',$bill['to_id'])->dec('wallet',$bill['number'])->update();
  198. echo "success";
  199. }else{
  200. // Db::name('log')->insert(['data'=>'支付宝提现回调验签失败']);
  201. echo "error";
  202. }
  203. case 'wx':
  204. }
  205. }
  206. }