| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <?php
- namespace app\api\controller\v1\taxiUser;
- use app\api\controller\ApiController;
- use app\api\model\taxi\MotorRecord;
- use app\api\model\taxi\UserPaymentOrder;
- use app\common\model\TaxiUser;
- use app\common\model\TaxiUsersLevel;
- use app\common\model\Users;
- use app\http\IResponse;
- use Lettered\Support\Upload;
- use think\App;
- use app\api\service\JWTAuth as IAuth;
- use think\Db;
- use think\Exception;
- class User extends ApiController
- {
- protected $model;
- public function __construct(App $app = null, IAuth $auth)
- {
- parent::__construct($app, $auth);
- $this->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,taxi_property,status')
- ->find();
- $type = isset($params['type'])? $params['type'] : 1;
- if($type == 2){
- $taxiUser['level_name'] = $taxiUser['level']? TaxiUsersLevel::where(['level'=>$taxiUser['level']])->value('title') : '';
- $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'] = 10;
- $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()
- {
- $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)],'上传成功');
- }
- /**
- * 司机等级列表
- * @return mixed
- */
- public function levels()
- {
- $list = TaxiUsersLevel::where(['status'=> 1])->order('level')->select();
- return IResponse::success($list,'获取成功');
- }
- /**
- * 升级记录
- * @return mixed
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function levelLog()
- {
- $param = $this->request->param();
- $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
- $lists = UserPaymentOrder::where(['user_id' => $this->auth->user()['id'],'type'=>30])
- ->order(['created_at' => 'desc'])
- ->limit((($param['page'] - 1) * $limit) . "," . $limit)
- ->select()->each(function($item,$k){
- $item['created_at_text'] = $item['created_at']? date('Y-m-d H:i:s', $item['created_at']) : '';
- });
- return IResponse::success($lists,'获取成功');
- }
- /**
- * 升级订单
- * @return mixed|\think\response\Json
- * @throws \Lettered\Support\Exceptions\FailedException
- */
- public function doLevel()
- {
- // 接收数据
- $params = $this->request->param();
- // 参数校验
- $valid = $this->validate($params, [
- 'id|请选择升级级别' => 'require'
- ]);
- // 错误返回
- if(true !== $valid){
- return IResponse::failure($valid);
- };
- $levelData = TaxiUsersLevel::where(['id'=> $params['id'],'status'=>1])->find();
- if(empty($levelData)){
- return IResponse::failure('参数错误或级别不存在');
- }
- $taxiUser = TaxiUser::where(['user_id'=> $this->auth->user()['id']])->find();
- if(empty($taxiUser)){
- return IResponse::failure('司机不存在或您还不是司机,请先入驻成为司机');
- }
- if(!in_array($taxiUser['status'], [1,2])){
- return IResponse::failure('您还未通过司机入驻审核,请先通过审核后操作');
- }
- if($taxiUser['level'] >= $levelData['level']){
- return IResponse::failure('升级等级参数错误,不能低于司机当前等级');
- }
- $data = [
- 'user_id'=> $this->auth->user()['id'],
- 'order_no'=> get_order_no(),
- 'source_id'=> $levelData['id'],
- 'price'=> $levelData['price'],
- 'remark'=> '司机付费【'.$levelData['price'].'】升级到'.$levelData['title'],
- 'status'=> 1,
- 'created_at'=> time(),
- 'updated_at'=> time(),
- 'type'=> 30,
- ];
- DB::startTrans();
- $orderid = UserPaymentOrder::insertGetId($data);
- if(!$orderid){
- Db::rollback();
- return IResponse::failure('创建升级订单失败');
- }
- // 创建对应支付记录
- $trade_no = get_order_no();
- $logID = model('common/OrderPaylog')->storeBy([
- 'out_trade_no' => $trade_no,
- 'total_price' => $levelData['price'],
- 'order_idx' => $orderid,
- 'ascription' => 'level' // 归属订单
- ]);
- if(!$logID){
- Db::rollback();
- return IResponse::failure('升级订单提交失败');
- }
- Db::commit();
- // 返回支付单号
- return $this->ApiJson(0,'升级订单提交成功', [
- 'type' => 'wx',
- 'success' => "ok!",
- 'order_id' => $orderid,
- 'trade_no' => $trade_no
- ]);
- }
- }
|