model = new \app\common\model\Users(); $this->taxiUserModel = new \app\api\model\taxi\User(); } /** * 司机用户信息 * @return mixed * @throws \Lettered\Support\Exceptions\FailedException */ public function info(){ $params = $this->request->param(); $taxiUser = $this->auth->guard('taxi_user')->user(); if(!$taxiUser){ return IResponse::failure('用户不存在,或已被冻结'); } if(!$taxiUser['user_id']){ return IResponse::failure('司机未绑定用户账号'); } $user = $this->model->where(['id'=> $taxiUser['user_id']]) ->field('id,parent_id,open_id,nickname,avatar_url,partnership,status') ->find(); $type = isset($params['type'])? $params['type'] : 1; if($type == 2){ $counts = [ 'day_income'=> '0.00', 'total_income'=> '0.00', 'withdraw_income'=> $user['partnership'], 'day_order'=> '0', 'total_order'=> '0', 'wait_order'=> '0', ]; $counts['day_income'] = model('common/TaxiOrder') ->where(['taxi_uid'=> $taxiUser['id']]) ->whereIn('status',[4,5]) ->where('created_at','>=', strtotime(date('Y-m-d'))) ->sum('settle_price'); $counts['total_income'] = model('common/TaxiOrder') ->where(['taxi_uid'=> $taxiUser['id']]) ->whereIn('status',[4,5]) ->sum('settle_price'); $counts['day_order'] = model('common/TaxiOrder') ->where(['taxi_uid'=> $taxiUser['id']]) ->whereIn('status',[3,4,5]) ->where('created_at','>=', strtotime(date('Y-m-d'))) ->count('id'); $counts['total_order'] = model('common/TaxiOrder') ->where(['taxi_uid'=> $taxiUser['id']]) ->whereIn('status',[3,4,5]) ->count('id'); $counts['wait_order'] = model('common/TaxiOrder') ->where(['taxi_uid'=> $taxiUser['id']]) ->whereIn('status',[3]) ->where('created_at','>=', strtotime(date('Y-m-d'))) ->count('id'); $taxiUser['counts'] = $counts; } unset($taxiUser['password']); $taxiUser['user'] = $user; return IResponse::success($taxiUser,'获取成功'); } /** * 提现 * @return \think\response\Json * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException * @throws \GuzzleHttp\Exception\GuzzleException * @throws \Lettered\Support\Exceptions\FailedException */ public function withdraw() { // 接收参数 $params = $this->request->param(); // 参数校验 $valid = $this->validate($params, [ 'real_name|真实姓名' => 'require', 'pay_type|收款方式' => 'require', 'bank_card_no|收款银行卡号' => 'requireIf:pay_type,1', 'desposit_bank|开户行' => 'requireIf:pay_type,1', 'sub_branch|开户支行' => 'requireIf:pay_type,1', 'wechat|收款微信' => 'requireIf:pay_type,2', 'wechat_qrcode|微信收款码' => 'requireIf:pay_type,2', 'alipay|收款支付宝' => 'requireIf:pay_type,3', 'alipay_qrcode|支付宝收款码' => 'requireIf:pay_type,3', 'amount|提现金额' => 'require', ]); // 错误返回 if(true !== $valid){ return IResponse::failure($valid); } $taxiUser = $this->auth->guard('taxi_user')->user(); if(!$taxiUser){ return IResponse::failure('用户不存在,或已被冻结'); } if(!$taxiUser['user_id']){ return IResponse::failure( "司机未绑定用户账号"); } $user = $this->model->where(['id'=> $taxiUser['user_id']]) ->field('id,parent_id,open_id,nickname,avatar_url,partnership,status') ->find(); // 司机资产限制 if ($user['partnership'] <= sys_config('user_withdraw_limit','user')){ return IResponse::failure("当前可提现金额不满足!司机资产:【". $user['partnership'] . "】"); } // 最低限制 if ($params['amount'] <= ($limit = sys_config('user_withdraw_limit','user'))){ //return IResponse::failure("申请提现金额不满足最低提现!最低:【" . $limit . "】"); } // 最高限制 if ($user['partnership'] <= $params['amount']){ return IResponse::failure("当前可提现金额不满足!资产:【". $user['partnership'] . "】"); } // 写入用户ID $params['user_id'] = $user['id']; $params['taxi_uid'] = $taxiUser['id']; // 交易单号 $params['order_no'] = get_order_no(); // 写入数据 Db::startTrans(); try { $params['status'] = 20; $ret = model('common/TaxiUsersWithdraw')::create($params,true); $Users = new Users(); $Users->changePartnership($user['id'], $ret['amount'], '资产提现', 20); Db::commit(); return IResponse::success('提现申请成功,请等候审核'); } catch(Exception $e) { Db::rollback(); return IResponse::failure( '提现失败,请稍后重试'); } } /** * 提现记录 * @return mixed * @throws \Lettered\Support\Exceptions\FailedException */ public function withdrawLog() { // 1. 传入用户位置 $param = $this->request->param(); $limit = isset($param['pageSize'])? $param['pageSize'] : 20; $taxiUser = $this->auth->guard('taxi_user')->user(); if(!$taxiUser){ return IResponse::failure('用户不存在,或已被冻结'); } // 经纬度升序 $lists = model('common/TaxiUsersWithdraw') ->where(['taxi_uid' => $taxiUser['id']]) ->order(['created_at' => 'desc']) ->limit((($param['page'] - 1) * $limit) . "," . $limit) ->select(); return IResponse::success($lists,'获取成功'); } /** * 提现记录 * @return mixed * @throws \Lettered\Support\Exceptions\FailedException */ public function accountLog() { // 1. 传入用户位置 $param = $this->request->param(); $limit = isset($param['pageSize'])? $param['pageSize'] : 20; $taxiUser = $this->auth->guard('taxi_user')->user(); if(!$taxiUser){ return IResponse::failure('用户不存在,或已被冻结'); } // 经纬度升序 $lists = MotorRecord::where(['user_id' => $taxiUser['user_id']]) ->order(['created_at' => 'desc']) ->limit((($param['page'] - 1) * $limit) . "," . $limit) ->select(); return IResponse::success($lists,'获取成功'); } /** * * 设置接单状态 * @return mixed * @throws \Lettered\Support\Exceptions\FailedException */ public function setOrderStatus() { // 1. 传入用户位置 $param = $this->request->param(); $status = isset($param['status'])? $param['status'] : 2; $taxiUser = $this->auth->guard('taxi_user')->user(); if(!$taxiUser){ return IResponse::failure('用户不存在,或已被冻结'); } $taxiUser->order_status = $status; if($taxiUser->save()){ return IResponse::success([],'设置成功'); }else{ return IResponse::failure('设置失败'); } } /** * 文件上传 * @return \think\response\Json */ public function uploadUserFile() { // 接收数据 $params = $this->request->param(); // 参数校验 $valid = $this->validate($params, [ 'action|上传操作' => 'require' ]); // 错误返回 if(true !== $valid){ return IResponse::failure($valid); }; // 上传 $upload = new Upload(config('upload.')); $ret = $upload->setPath( '/' . $params['action'])->upload($this->request->file('file')); return IResponse::success(['path'=> $ret,'url'=>get_annex_url($ret)],'上传成功'); } }