| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- namespace app\api\controller\service;
- use app\common\controller\Api;
- use think\Db;
- use think\Exception;
- use think\Loader;
- /**
- * 首页接口
- */
- class Withdraw extends Api
- {
- protected $noNeedLogin = [''];
- protected $noNeedRight = ['*'];
- public function apply()
- {
- $uid = $this->auth->id;
- $userInfo = \app\api\model\service\UserInfo::getUserMoney($uid);
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $post = input('post.','','trim,strip_tags,htmlspecialchars,xss_clean');
- if(isset($post['types']) && $post['types'] == 'withdraw')
- {
- $post['user_id'] = $uid;
- $post['num'] = sprintf("%.2f",$post['num']);
- $validate = Loader::validate('service.Withdraw');
- if(!$validate->scene('add')->check($post)){
- $this->error($validate->getError());
- }
- Db::startTrans();
- try{
- \app\api\model\service\Withdraw::apply($post);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error('提现申请失败',$e->getMessage());
- }
- $this->success('提现申请已提交');
- }
- $this->success('信息返回成功',$userInfo);
- }
- public function getList()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $post = input('post.','');
- $post['user_id'] = $uid;
- $list = \app\api\model\service\Withdraw::getList($post);
- $this->success('列表信息返回成功',$list);
- }
- public function moneyInfo()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $data['money'] = \app\api\model\service\UserInfo::where(['user_id'=>$uid])->field('id,money,shop_money,shop_user_money')->find();
- $type = input('type/d',0);
- $page = input('page/d',1);
- if($type == 0)
- {
- $list = \app\api\model\service\UserMoneyLog::where(['user_id'=>$uid])->order('id desc')->page($page)->limit(10)->select();
- }elseif($type == 1){
- $list = \app\api\model\service\ShopMoneyLog::where(['user_id'=>$uid])->order('id desc')->page($page)->limit(10)->select();
- }elseif($type == 2){
- $list = \app\api\model\service\ShopUserMoneyLog::where(['user_id'=>$uid])->order('id desc')->page($page)->limit(10)->select();
- }
- $data['list'] = $list;
- $this->success('信息返回成功',$data);
- }
- public function getWithdrawDay()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $type = input('type/d','');
- if($type == 0){
- $config = \app\api\model\service\ProjectConfig::where(['state'=>1])->field('withdrawtype,day')->find();
- }else{
- $shopId = \app\api\model\service\Skill::where(['user_id'=>$uid])->value('shop_id');
- $config = \app\api\model\service\Shop::where(['id'=>$shopId])->field('withdrawtype,day')->find();
- }
- $this->success('信息返回成功',$config);
- }
- public function shopWithdrawList()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $post = input('post.','','trim,strip_tags');
- $post['shop_id'] = $shopId;
- $post['type'] = 1;
- $list = \app\api\model\service\Withdraw::getList($post);
- foreach ($list as $key=>$value)
- {
- $list[$key]['skill'] = \app\api\model\service\Skill::where(['user_id'=>$value['user_id']])->field('id,name,image')->find();
- $list[$key]['shop_money'] = \app\api\model\service\UserInfo::where('user_id',$value['user_id'])->value('shop_money');
- }
- $this->success('信息返回成功',$list);
- }
- public function shopCheckWithdraw()
- {
- if (!$this->request->isPost()) {
- $this->error('请求方式异常');
- }
- $uid = $this->auth->id;
- $shopId = \app\api\model\service\Shop::where(['user_id'=>$uid])->value('id');
- $post = input('post.','','trim,strip_tags');
- $info = \app\api\model\service\Withdraw::where(['id'=>$post['id'],'shop_id'=>$shopId])->find();
- !$info && $this->error('当前订单无法审核');
- Db::startTrans();
- try{
- $withdraw = new \app\api\model\service\Withdraw();
- $withdraw->allowField('note,state,images')->save($post,['id'=>$post['id']]);
- if($post['state'] == -1)
- {
- \app\api\model\service\UserInfo::shopMoney(+$info['num'],$info['user_id'],'审核拒绝余额退回');
- }
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error('提现申请失败',$e->getMessage());
- }
- $this->success('提现订单已处理');
- }
- }
|