User.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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\TaxiUsersLevel;
  6. use app\common\model\Users;
  7. use app\http\IResponse;
  8. use Lettered\Support\Upload;
  9. use think\App;
  10. use app\api\service\JWTAuth as IAuth;
  11. use think\Db;
  12. use think\Exception;
  13. class User extends ApiController
  14. {
  15. protected $model;
  16. public function __construct(App $app = null, IAuth $auth)
  17. {
  18. parent::__construct($app, $auth);
  19. $this->model = new \app\common\model\Users();
  20. $this->taxiUserModel = new \app\api\model\taxi\User();
  21. }
  22. /**
  23. * 司机用户信息
  24. * @return mixed
  25. * @throws \Lettered\Support\Exceptions\FailedException
  26. */
  27. public function info(){
  28. $params = $this->request->param();
  29. $taxiUser = $this->auth->guard('taxi_user')->user();
  30. if(!$taxiUser){
  31. return IResponse::failure('用户不存在,或已被冻结');
  32. }
  33. if(!$taxiUser['user_id']){
  34. return IResponse::failure('司机未绑定用户账号');
  35. }
  36. $user = $this->model->where(['id'=> $taxiUser['user_id']])
  37. ->field('id,parent_id,open_id,nickname,avatar_url,partnership,status')
  38. ->find();
  39. $type = isset($params['type'])? $params['type'] : 1;
  40. if($type == 2){
  41. $counts = [
  42. 'day_income'=> '0.00',
  43. 'total_income'=> '0.00',
  44. 'withdraw_income'=> $user['partnership'],
  45. 'day_order'=> '0',
  46. 'total_order'=> '0',
  47. 'wait_order'=> '0',
  48. ];
  49. $counts['day_income'] = model('common/TaxiOrder')
  50. ->where(['taxi_uid'=> $taxiUser['id']])
  51. ->whereIn('status',[4,5])
  52. ->where('created_at','>=', strtotime(date('Y-m-d')))
  53. ->sum('settle_price');
  54. $counts['total_income'] = model('common/TaxiOrder')
  55. ->where(['taxi_uid'=> $taxiUser['id']])
  56. ->whereIn('status',[4,5])
  57. ->sum('settle_price');
  58. $counts['day_order'] = model('common/TaxiOrder')
  59. ->where(['taxi_uid'=> $taxiUser['id']])
  60. ->whereIn('status',[3,4,5])
  61. ->where('created_at','>=', strtotime(date('Y-m-d')))
  62. ->count('id');
  63. $counts['total_order'] = model('common/TaxiOrder')
  64. ->where(['taxi_uid'=> $taxiUser['id']])
  65. ->whereIn('status',[3,4,5])
  66. ->count('id');
  67. $counts['wait_order'] = model('common/TaxiOrder')
  68. ->where(['taxi_uid'=> $taxiUser['id']])
  69. ->whereIn('status',[3])
  70. ->where('created_at','>=', strtotime(date('Y-m-d')))
  71. ->count('id');
  72. $taxiUser['counts'] = $counts;
  73. }
  74. unset($taxiUser['password']);
  75. $taxiUser['user'] = $user;
  76. return IResponse::success($taxiUser,'获取成功');
  77. }
  78. /**
  79. * 提现
  80. * @return \think\response\Json
  81. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  82. * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
  83. * @throws \GuzzleHttp\Exception\GuzzleException
  84. * @throws \Lettered\Support\Exceptions\FailedException
  85. */
  86. public function withdraw()
  87. {
  88. // 接收参数
  89. $params = $this->request->param();
  90. // 参数校验
  91. $valid = $this->validate($params, [
  92. 'real_name|真实姓名' => 'require',
  93. 'pay_type|收款方式' => 'require',
  94. 'bank_card_no|收款银行卡号' => 'requireIf:pay_type,1',
  95. 'desposit_bank|开户行' => 'requireIf:pay_type,1',
  96. 'sub_branch|开户支行' => 'requireIf:pay_type,1',
  97. 'wechat|收款微信' => 'requireIf:pay_type,2',
  98. 'wechat_qrcode|微信收款码' => 'requireIf:pay_type,2',
  99. 'alipay|收款支付宝' => 'requireIf:pay_type,3',
  100. 'alipay_qrcode|支付宝收款码' => 'requireIf:pay_type,3',
  101. 'amount|提现金额' => 'require',
  102. ]);
  103. // 错误返回
  104. if(true !== $valid){
  105. return IResponse::failure($valid);
  106. }
  107. $taxiUser = $this->auth->guard('taxi_user')->user();
  108. if(!$taxiUser){
  109. return IResponse::failure('用户不存在,或已被冻结');
  110. }
  111. if(!$taxiUser['user_id']){
  112. return IResponse::failure( "司机未绑定用户账号");
  113. }
  114. $user = $this->model->where(['id'=> $taxiUser['user_id']])
  115. ->field('id,parent_id,open_id,nickname,avatar_url,partnership,status')
  116. ->find();
  117. // 司机资产限制
  118. if ($user['partnership'] <= sys_config('user_withdraw_limit','user')){
  119. return IResponse::failure("当前可提现金额不满足!司机资产:【". $user['partnership'] . "】");
  120. }
  121. // 最低限制
  122. if ($params['amount'] <= ($limit = sys_config('user_withdraw_limit','user'))){
  123. //return IResponse::failure("申请提现金额不满足最低提现!最低:【" . $limit . "】");
  124. }
  125. // 最高限制
  126. if ($user['partnership'] <= $params['amount']){
  127. return IResponse::failure("当前可提现金额不满足!资产:【". $user['partnership'] . "】");
  128. }
  129. // 写入用户ID
  130. $params['user_id'] = $user['id'];
  131. $params['taxi_uid'] = $taxiUser['id'];
  132. // 交易单号
  133. $params['order_no'] = get_order_no();
  134. // 写入数据
  135. Db::startTrans();
  136. try {
  137. $params['status'] = 20;
  138. $ret = model('common/TaxiUsersWithdraw')::create($params,true);
  139. $Users = new Users();
  140. $Users->changePartnership($user['id'], $ret['amount'], '资产提现', 20);
  141. Db::commit();
  142. return IResponse::success('提现申请成功,请等候审核');
  143. }
  144. catch(Exception $e) {
  145. Db::rollback();
  146. return IResponse::failure( '提现失败,请稍后重试');
  147. }
  148. }
  149. /**
  150. * 提现记录
  151. * @return mixed
  152. * @throws \Lettered\Support\Exceptions\FailedException
  153. */
  154. public function withdrawLog()
  155. {
  156. // 1. 传入用户位置
  157. $param = $this->request->param();
  158. $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
  159. $taxiUser = $this->auth->guard('taxi_user')->user();
  160. if(!$taxiUser){
  161. return IResponse::failure('用户不存在,或已被冻结');
  162. }
  163. // 经纬度升序
  164. $lists = model('common/TaxiUsersWithdraw')
  165. ->where(['taxi_uid' => $taxiUser['id']])
  166. ->order(['created_at' => 'desc'])
  167. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  168. ->select();
  169. return IResponse::success($lists,'获取成功');
  170. }
  171. /**
  172. * 提现记录
  173. * @return mixed
  174. * @throws \Lettered\Support\Exceptions\FailedException
  175. */
  176. public function accountLog()
  177. {
  178. // 1. 传入用户位置
  179. $param = $this->request->param();
  180. $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
  181. $taxiUser = $this->auth->guard('taxi_user')->user();
  182. if(!$taxiUser){
  183. return IResponse::failure('用户不存在,或已被冻结');
  184. }
  185. // 经纬度升序
  186. $lists = MotorRecord::where(['user_id' => $taxiUser['user_id']])
  187. ->order(['created_at' => 'desc'])
  188. ->limit((($param['page'] - 1) * $limit) . "," . $limit)
  189. ->select();
  190. return IResponse::success($lists,'获取成功');
  191. }
  192. /**
  193. *
  194. * 设置接单状态
  195. * @return mixed
  196. * @throws \Lettered\Support\Exceptions\FailedException
  197. */
  198. public function setOrderStatus()
  199. {
  200. // 1. 传入用户位置
  201. $param = $this->request->param();
  202. $status = isset($param['status'])? $param['status'] : 2;
  203. $taxiUser = $this->auth->guard('taxi_user')->user();
  204. if(!$taxiUser){
  205. return IResponse::failure('用户不存在,或已被冻结');
  206. }
  207. $taxiUser->order_status = $status;
  208. if($taxiUser->save()){
  209. return IResponse::success([],'设置成功');
  210. }else{
  211. return IResponse::failure('设置失败');
  212. }
  213. }
  214. /**
  215. * 文件上传
  216. * @return \think\response\Json
  217. */
  218. public function uploadUserFile()
  219. {
  220. // 接收数据
  221. $params = $this->request->param();
  222. // 参数校验
  223. $valid = $this->validate($params, [
  224. 'action|上传操作' => 'require'
  225. ]);
  226. // 错误返回
  227. if(true !== $valid){
  228. return IResponse::failure($valid);
  229. };
  230. // 上传
  231. $upload = new Upload(config('upload.'));
  232. $ret = $upload->setPath( '/' . $params['action'])->upload($this->request->file('file'));
  233. return IResponse::success(['path'=> $ret,'url'=>get_annex_url($ret)],'上传成功');
  234. }
  235. /**
  236. * 司机等级列表
  237. * @return mixed
  238. */
  239. public function levels()
  240. {
  241. $list = TaxiUsersLevel::where(['status'=> 1])->order('level')->select();
  242. return IResponse::success($list,'上传成功');
  243. }
  244. }