User.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. namespace app\api\controller\v1\taxiUser;
  3. use app\api\controller\ApiController;
  4. use app\api\model\taxi\MotorRecord;
  5. use app\common\model\Users;
  6. use app\http\IResponse;
  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 IResponse::failure($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'] = 20;
  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 mixed
  151. * @throws \Lettered\Support\Exceptions\FailedException
  152. */
  153. public function withdrawLog()
  154. {
  155. // 1. 传入用户位置
  156. $param = $this->request->param();
  157. $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
  158. $taxiUser = $this->auth->guard('taxi_user')->user();
  159. if(!$taxiUser){
  160. return IResponse::failure('用户不存在,或已被冻结');
  161. }
  162. // 经纬度升序
  163. $lists = model('common/TaxiUsersWithdraw')
  164. ->where(['taxi_uid' => $taxiUser['id']])
  165. ->order(['created_at' => 'desc'])
  166. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  167. ->select();
  168. return IResponse::success($lists,'获取成功');
  169. }
  170. /**
  171. * 提现记录
  172. * @return mixed
  173. * @throws \Lettered\Support\Exceptions\FailedException
  174. */
  175. public function accountLog()
  176. {
  177. // 1. 传入用户位置
  178. $param = $this->request->param();
  179. $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
  180. $taxiUser = $this->auth->guard('taxi_user')->user();
  181. if(!$taxiUser){
  182. return IResponse::failure('用户不存在,或已被冻结');
  183. }
  184. // 经纬度升序
  185. $lists = MotorRecord::where(['user_id' => $taxiUser['user_id']])
  186. ->order(['created_at' => 'desc'])
  187. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  188. ->select();
  189. return IResponse::success($lists,'获取成功');
  190. }
  191. /**
  192. *
  193. * 设置接单状态
  194. * @return mixed
  195. * @throws \Lettered\Support\Exceptions\FailedException
  196. */
  197. public function setOrderStatus()
  198. {
  199. // 1. 传入用户位置
  200. $param = $this->request->param();
  201. $status = isset($param['status'])? $param['status'] : 2;
  202. $taxiUser = $this->auth->guard('taxi_user')->user();
  203. if(!$taxiUser){
  204. return IResponse::failure('用户不存在,或已被冻结');
  205. }
  206. $taxiUser->order_status = $status;
  207. if($taxiUser->save()){
  208. return IResponse::success([],'设置成功');
  209. }else{
  210. return IResponse::failure('设置失败');
  211. }
  212. }
  213. /**
  214. * 文件上传
  215. * @return \think\response\Json
  216. */
  217. public function uploadUserFile()
  218. {
  219. // 接收数据
  220. $params = $this->request->param();
  221. // 参数校验
  222. $valid = $this->validate($params, [
  223. 'action|上传操作' => 'require'
  224. ]);
  225. // 错误返回
  226. if(true !== $valid){
  227. return IResponse::failure($valid);
  228. };
  229. // 上传
  230. $upload = new Upload(config('upload.'));
  231. $ret = $upload->setPath( '/' . $params['action'])->upload($this->request->file('file'));
  232. return IResponse::success(['path'=> $ret,'url'=>get_annex_url($ret)],'上传成功');
  233. }
  234. }