| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace app\admin\controller\users;
- use app\api\model\taxi\MotorRecord;
- use app\common\controller\AdminController;
- use app\http\IResponse;
- use think\App;
- use think\Exception;
- use think\Request;
- class MotorAgentWithdraw extends AdminController
- {
- protected $model;
- public function __construct(App $app = null)
- {
- parent::__construct($app);
- $this->model = new \app\admin\model\users\MotorAgentWithdraw();
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $params = input();
- $params['card_id'] = input('card_id/s', '');
- $params['nickname'] = input('nickname/s', '');
- $where = [];
- if ($params['nickname']) {
- $where['nickname'] = ['like', '%' . $params['nickname'] . '%'];
- }
- $list = $this->model
- // ->with(['user'])
- ->where($where)
- ->order(['id' => 'desc'])
- ->paginate(input('limit', 10),false);
- return IResponse::paginate($list);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- //
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function save(Request $request)
- {
- //
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read($id)
- {
- //
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function edit($id)
- {
- //
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
- public function check($ids)
- {
- $row = $this->model->with(['user'])->find($ids);
- if (!$row || $row['status'] > 20) {
- return IResponse::failure('不可操作');
- }
- if ($row['user']['motor_agent_money'] < $row['withdraw_amount']) {
- return IResponse::failure('代理合伙资产余额不足');
- }
- $result = false;
- $this->model->startTrans();
- try {
- $row->status = 30;
- $row->save();
- $row->user->balance += $row['withdraw_amount'];
- $row->user->motor_agent_money -= $row['withdraw_amount'];
- $result = $row->user->save();
- $MotorRecord = new MotorRecord();
- $MotorRecord->setMoneyLog($row['user'], 'motor_agent_money', $row['withdraw_amount'], 20, '摩的代理-提现', 2);
- $MotorRecord->saveMoneyLog();
- $this->model->commit();
- }
- catch(Exception $e) {
- $this->model->rollback();
- }
- if ($result) {
- return IResponse::success('成功');
- }
- return IResponse::failure('失败');
- }
- /**
- * 删除指定资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function delete($id)
- {
- //
- }
- }
|