| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace app\agent\controller\finance;
- use app\common\controller\AgentController;
- use app\http\IResponse;
- use Lettered\Support\Auth as IAuth;
- use think\App;
- use think\Exception;
- use think\Request;
- class Withdraw extends AgentController
- {
- protected $model;
- public function __construct(App $app = null, IAuth $auth)
- {
- parent::__construct($app, $auth);
- $this->model = new \app\agent\model\finance\Withdraw();
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $where = [];
- !empty($this->auth->user()['user_id']) && $where[]
- = ['user_id', '=', $this->auth->user()['user_id']];
- (!empty(input('status')) || input('status') == '0') &&
- $where[] = ['status', 'eq', input('status')];
- // 时间处理
- if (!empty(input('created_at'))){
- list($start, $end) = str2arr(input('created_at'),'-');
- $where[] = ['created_at', 'between', [strtotime($start), strtotime($end)]];
- }
- $list = $this->model->where($where)
- ->order(['id' => 'desc'])
- ->paginate(input('limit'),false);
- return IResponse::paginate($list);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- //
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- * @throws \think\exception\PDOException
- */
- public function save(Request $request)
- {
- $params = input();
- $validate = validate('\app\agent\validate\finance\Withdraw');
- if (!$validate->scene('save')->check($params)) {
- return IResponse::failure($validate->getError());
- }
- $admin = $this->auth->user();
- $user = model('\app\common\model\Users')->field('id,motor_agent_money')
- ->find($admin['user_id']);
- if ($user['motor_agent_money'] < $params['withdraw_amount']) {
- return IResponse::failure('余额不足');
- }
- $this->model->startTrans();
- try {
- $params['user_id'] = $admin['user_id'];
- $result = $this->model::create($params, true);
- $this->model->commit();
- }
- catch(Exception $e) {
- $this->model->rollback();
- return IResponse::failure($e->getMessage());
- }
- if ($result) {
- return IResponse::success();
- }
- return IResponse::failure();
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- //
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function edit($id)
- {
- //
- }
- /**
- * 保存更新的资源
- *
- * @param int $ids
- * @return \think\Response
- */
- public function update($ids)
- {
- $row = $this->model::get($ids);
- if (!$row || $row['status'] > 20) {
- return IResponse::failure('不可操作');
- }
- $result = false;
- $this->model->startTrans();
- try {
- $result = $row->allowField(true)->save(input());
- $this->model->commit();
- }
- catch(Exception $e) {
- $this->model->rollback();
- }
- if ($result === false) {
- return IResponse::failure();
- }
- return IResponse::success();
- }
- /**
- * 删除指定资源
- *
- * @param int $ids
- * @return \think\Response
- * @throws \think\exception\PDOException
- */
- public function delete($ids)
- {
- $row = $this->model::get($ids);
- if (!$row) {
- return IResponse::failure('不可操作');
- }
- $result = false;
- $this->model->startTrans();
- try {
- $result = $row->delete();
- $this->model->commit();
- }
- catch(Exception $e) {
- $this->model->rollback();
- }
- if ($result) {
- return IResponse::success();
- }
- return IResponse::failure();
- }
- }
|