User.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <?php
  2. namespace app\api\controller\v1\taxiUser;
  3. use app\api\controller\ApiController;
  4. use app\common\model\Users;
  5. use app\http\IResponse;
  6. use EasyWeChat\Factory;
  7. use Lettered\Support\Upload;
  8. use think\App;
  9. use app\api\service\JWTAuth as IAuth;
  10. use think\Db;
  11. use think\Exception;
  12. class User extends ApiController
  13. {
  14. protected $model;
  15. public function __construct(App $app = null, IAuth $auth)
  16. {
  17. parent::__construct($app, $auth);
  18. $this->model = new \app\common\model\Users();
  19. $this->taxiUserModel = new \app\api\model\taxi\User();
  20. }
  21. /**
  22. * 司机用户信息
  23. * @return mixed
  24. * @throws \Lettered\Support\Exceptions\FailedException
  25. */
  26. public function info(){
  27. $params = $this->request->param();
  28. $taxiUser = $this->auth->guard('taxi_user')->user();
  29. if(!$taxiUser){
  30. return IResponse::failure('用户不存在,或已被冻结');
  31. }
  32. if(!$taxiUser['user_id']){
  33. return IResponse::failure('司机未绑定用户账号');
  34. }
  35. $user = $this->model->where(['id'=> $taxiUser['user_id']])
  36. ->field('id,parent_id,open_id,nickname,avatar_url,partnership,status')
  37. ->find();
  38. $type = isset($params['type'])? $params['type'] : 1;
  39. if($type == 2){
  40. $counts = [
  41. 'day_income'=> '0.00',
  42. 'total_income'=> '0.00',
  43. 'withdraw_income'=> $user['partnership'],
  44. 'day_order'=> '0',
  45. 'total_order'=> '0',
  46. 'wait_order'=> '0',
  47. ];
  48. $counts['day_income'] = model('common/TaxiOrder')
  49. ->where(['taxi_uid'=> $taxiUser['id']])
  50. ->whereIn('status',[4,5])
  51. ->where('created_at','>=', strtotime(date('Y-m-d')))
  52. ->sum('settle_price');
  53. $counts['total_income'] = model('common/TaxiOrder')
  54. ->where(['taxi_uid'=> $taxiUser['id']])
  55. ->whereIn('status',[4,5])
  56. ->sum('settle_price');
  57. $counts['day_order'] = model('common/TaxiOrder')
  58. ->where(['taxi_uid'=> $taxiUser['id']])
  59. ->whereIn('status',[3,4,5])
  60. ->where('created_at','>=', strtotime(date('Y-m-d')))
  61. ->count('id');
  62. $counts['total_order'] = model('common/TaxiOrder')
  63. ->where(['taxi_uid'=> $taxiUser['id']])
  64. ->whereIn('status',[3,4,5])
  65. ->count('id');
  66. $counts['wait_order'] = model('common/TaxiOrder')
  67. ->where(['taxi_uid'=> $taxiUser['id']])
  68. ->whereIn('status',[3])
  69. ->where('created_at','>=', strtotime(date('Y-m-d')))
  70. ->count('id');
  71. $taxiUser['counts'] = $counts;
  72. }
  73. unset($taxiUser['password']);
  74. $taxiUser['user'] = $user;
  75. return IResponse::success($taxiUser,'获取成功');
  76. }
  77. /**
  78. * 提现
  79. * @return \think\response\Json
  80. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  81. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  82. * @throws \GuzzleHttp\Exception\GuzzleException
  83. * @throws \Lettered\Support\Exceptions\FailedException
  84. */
  85. public function withdraw()
  86. {
  87. // 接收参数
  88. $params = $this->request->param();
  89. // 参数校验
  90. $valid = $this->validate($params, [
  91. 'real_name|真实姓名' => 'require',
  92. 'pay_type|收款方式' => 'require',
  93. 'bank_card_no|收款银行卡号' => 'requireIf:pay_type,1',
  94. 'desposit_bank|开户行' => 'requireIf:pay_type,1',
  95. 'sub_branch|开户支行' => 'requireIf:pay_type,1',
  96. 'wechat|收款微信' => 'requireIf:pay_type,2',
  97. 'wechat_qrcode|微信收款码' => 'requireIf:pay_type,2',
  98. 'alipay|收款支付宝' => 'requireIf:pay_type,3',
  99. 'alipay_qrcode|支付宝收款码' => 'requireIf:pay_type,3',
  100. 'amount|提现金额' => 'require',
  101. ]);
  102. // 错误返回
  103. if(true !== $valid){
  104. return $this->ApiJson(-1, $valid);
  105. }
  106. $taxiUser = $this->auth->guard('taxi_user')->user();
  107. if(!$taxiUser){
  108. return IResponse::failure('用户不存在,或已被冻结');
  109. }
  110. if(!$taxiUser['user_id']){
  111. return IResponse::failure( "司机未绑定用户账号");
  112. }
  113. $user = $this->model->where(['id'=> $taxiUser['user_id']])
  114. ->field('id,parent_id,open_id,nickname,avatar_url,partnership,status')
  115. ->find();
  116. // 司机资产限制
  117. if ($user['partnership'] <= sys_config('user_withdraw_limit','user')){
  118. return IResponse::failure("当前可提现金额不满足!司机资产:【". $user['partnership'] . "】");
  119. }
  120. // 最低限制
  121. if ($params['amount'] <= ($limit = sys_config('user_withdraw_limit','user'))){
  122. //return IResponse::failure("申请提现金额不满足最低提现!最低:【" . $limit . "】");
  123. }
  124. // 最高限制
  125. if ($user['partnership'] <= $params['amount']){
  126. return IResponse::failure("当前可提现金额不满足!资产:【". $user['partnership'] . "】");
  127. }
  128. // 写入用户ID
  129. $params['user_id'] = $user['id'];
  130. $params['taxi_uid'] = $taxiUser['id'];
  131. // 交易单号
  132. $params['order_no'] = get_order_no();
  133. // 写入数据
  134. Db::startTrans();
  135. try {
  136. $params['status'] = 10;
  137. $ret = model('common/TaxiUsersWithdraw')::create($params,true);
  138. $Users = new Users();
  139. $Users->changePartnership($user['id'], $ret['amount'], '资产提现', 20);
  140. Db::commit();
  141. return IResponse::success('提现申请成功,请等候审核');
  142. }
  143. catch(Exception $e) {
  144. Db::rollback();
  145. return IResponse::failure( '提现失败,请稍后重试');
  146. }
  147. }
  148. /**
  149. * 文件上传
  150. * @return \think\response\Json
  151. */
  152. public function uploadUserFile()
  153. {
  154. // 接收数据
  155. $params = $this->request->param();
  156. // 参数校验
  157. $valid = $this->validate($params, [
  158. 'action|上传操作' => 'require'
  159. ]);
  160. // 错误返回
  161. if(true !== $valid){
  162. return $this->ApiJson(-1, $valid);
  163. };
  164. // 上传
  165. $upload = new Upload(config('upload.'));
  166. $ret = $upload->setPath( '/' . $params['action'])->upload($this->request->file('file'));
  167. return $this->ApiJson(0,'', ['path'=> $ret,'url'=>get_annex_url($ret)]);
  168. }
  169. }