MotorAgentWithdraw.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\admin\controller\users;
  3. use app\api\model\taxi\MotorRecord;
  4. use app\common\controller\AdminController;
  5. use app\http\IResponse;
  6. use think\App;
  7. use think\Exception;
  8. use think\Request;
  9. class MotorAgentWithdraw extends AdminController
  10. {
  11. protected $model;
  12. public function __construct(App $app = null)
  13. {
  14. parent::__construct($app);
  15. $this->model = new \app\admin\model\users\MotorAgentWithdraw();
  16. }
  17. /**
  18. * 显示资源列表
  19. *
  20. * @return \think\Response
  21. * @throws \think\exception\DbException
  22. */
  23. public function index()
  24. {
  25. $params = input();
  26. $params['card_id'] = input('card_id/s', '');
  27. $params['nickname'] = input('nickname/s', '');
  28. $where = [];
  29. if ($params['nickname']) {
  30. $where['nickname'] = ['like', '%' . $params['nickname'] . '%'];
  31. }
  32. $list = $this->model
  33. // ->with(['user'])
  34. ->where($where)
  35. ->order(['id' => 'desc'])
  36. ->paginate(input('limit', 10),false);
  37. return IResponse::paginate($list);
  38. }
  39. /**
  40. * 显示创建资源表单页.
  41. *
  42. * @return \think\Response
  43. */
  44. public function create()
  45. {
  46. //
  47. }
  48. /**
  49. * 保存新建的资源
  50. *
  51. * @param \think\Request $request
  52. * @return \think\Response
  53. */
  54. public function save(Request $request)
  55. {
  56. //
  57. }
  58. /**
  59. * 显示指定的资源
  60. *
  61. * @param int $id
  62. * @return \think\Response
  63. */
  64. public function read($id)
  65. {
  66. //
  67. }
  68. /**
  69. * 显示编辑资源表单页.
  70. *
  71. * @param int $id
  72. * @return \think\Response
  73. */
  74. public function edit($id)
  75. {
  76. //
  77. }
  78. /**
  79. * 保存更新的资源
  80. *
  81. * @param \think\Request $request
  82. * @param int $id
  83. * @return \think\Response
  84. */
  85. public function update(Request $request, $id)
  86. {
  87. //
  88. }
  89. public function check($ids)
  90. {
  91. $row = $this->model->with(['user'])->find($ids);
  92. if (!$row || $row['status'] > 20) {
  93. return IResponse::failure('不可操作');
  94. }
  95. if ($row['user']['motor_agent_money'] < $row['withdraw_amount']) {
  96. return IResponse::failure('代理合伙资产余额不足');
  97. }
  98. $result = false;
  99. $this->model->startTrans();
  100. try {
  101. $row->status = 30;
  102. $row->save();
  103. $row->user->balance += $row['withdraw_amount'];
  104. $row->user->motor_agent_money -= $row['withdraw_amount'];
  105. $result = $row->user->save();
  106. $MotorRecord = new MotorRecord();
  107. $MotorRecord->setMoneyLog($row['user'], 'motor_agent_money', $row['withdraw_amount'], 20, '摩的代理-提现', 2);
  108. $MotorRecord->saveMoneyLog();
  109. $this->model->commit();
  110. }
  111. catch(Exception $e) {
  112. $this->model->rollback();
  113. }
  114. if ($result) {
  115. return IResponse::success('成功');
  116. }
  117. return IResponse::failure('失败');
  118. }
  119. /**
  120. * 删除指定资源
  121. *
  122. * @param int $id
  123. * @return \think\Response
  124. */
  125. public function delete($id)
  126. {
  127. //
  128. }
  129. }