User.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\controller\taxi;
  3. use app\api\model\taxi\MotorRecord;
  4. use app\common\controller\AdminController;
  5. use app\common\model\TaxiUser;
  6. use app\http\IResponse;
  7. use think\App;
  8. use think\Exception;
  9. class User extends AdminController
  10. {
  11. protected $model;
  12. public function __construct(App $app = null)
  13. {
  14. parent::__construct($app);
  15. $this->model = new TaxiUser();
  16. }
  17. /**
  18. * @desc 审核司机
  19. * @param $ids
  20. * @throws \think\exception\PDOException
  21. * @author weichuanbao<654745815@qq.com>
  22. * @date 2021/12/7 0007
  23. */
  24. public function check($ids)
  25. {
  26. $row = $this->model::get($ids);
  27. if (!$row) {
  28. IResponse::failure('记录不存在');
  29. }
  30. $result = false;
  31. $this->model->startTrans();
  32. try {
  33. $row->status = 5;
  34. $result = $row->save();
  35. $this->model->commit();
  36. }
  37. catch(Exception $e) {
  38. $this->model->rollback();
  39. }
  40. if ($result) {
  41. IResponse::success([],'成功');
  42. }
  43. IResponse::failure('失败');
  44. }
  45. /**
  46. * @desc 发放合伙资产
  47. * @param $ids
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. * @throws \think\exception\DbException
  51. * @throws \think\exception\PDOException
  52. * @author weichuanbao<654745815@qq.com>
  53. * @date 2022/1/7 0007
  54. */
  55. public function partnership($ids)
  56. {
  57. $row = $this->model->with('user')->find($ids);
  58. if (!$row) {
  59. IResponse::failure('记录不存在');
  60. }
  61. $params = input();
  62. $params['amount'] = input('amount', 0);
  63. if(floatval($params['amount'])<=0){
  64. IResponse::failure('请输入合法资产金额');
  65. }
  66. $MotorRecord = new MotorRecord();
  67. $result = false;
  68. $this->model->startTrans();
  69. var_dump($row->user);
  70. try {
  71. if(!$row->user){
  72. IResponse::failure('该司机未绑定用户');
  73. }
  74. $row->user->partnership = $params['amount'];
  75. $result = $row->user->save();
  76. IResponse::failure('该司机未绑定用户');
  77. $MotorRecord->setMoneyLog($row['user'], 'partnership', $params['amount'], 30, '发放合伙资产');
  78. $MotorRecord->saveMoneyLog();
  79. $this->model->commit();
  80. }
  81. catch(Exception $e) {
  82. $this->model->rollback();
  83. IResponse::failure($e->getMessage());
  84. }
  85. if ($result) {
  86. IResponse::success([],'成功');
  87. }else{
  88. IResponse::failure('失败');
  89. }
  90. }
  91. }