UserExtract.php 9.0 KB

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