User.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. if(!$row['user_id'] || !model('common/users')->where(['id'=> $row['user_id']])->find()){
  31. IResponse::failure('未绑定用户账号');
  32. }
  33. $result = false;
  34. $this->model->startTrans();
  35. try {
  36. $row->status = 5;
  37. $result = $row->save();
  38. $this->model->commit();
  39. }
  40. catch(Exception $e) {
  41. $this->model->rollback();
  42. }
  43. if ($result) {
  44. IResponse::success([],'成功');
  45. }
  46. IResponse::failure('失败');
  47. }
  48. /**
  49. * @desc 发放合伙资产
  50. * @param $ids
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. * @throws \think\exception\DbException
  54. * @throws \think\exception\PDOException
  55. * @author weichuanbao<654745815@qq.com>
  56. * @date 2022/1/7 0007
  57. */
  58. public function partnership($ids)
  59. {
  60. $row = $this->model->with('user')->find($ids);
  61. if (!$row) {
  62. IResponse::failure('记录不存在');
  63. }
  64. $params = input();
  65. $params['amount'] = input('amount', 0);
  66. if(floatval($params['amount'])<=0){
  67. IResponse::failure('请输入合法资产金额');
  68. }
  69. $MotorRecord = new MotorRecord();
  70. $result = false;
  71. $this->model->startTrans();
  72. var_dump($row->user);
  73. try {
  74. if(!$row->user){
  75. IResponse::failure('该司机未绑定用户');
  76. }
  77. $row->user->partnership = $params['amount'];
  78. $result = $row->user->save();
  79. IResponse::failure('该司机未绑定用户');
  80. $MotorRecord->setMoneyLog($row['user'], 'partnership', $params['amount'], 30, '发放合伙资产');
  81. $MotorRecord->saveMoneyLog();
  82. $this->model->commit();
  83. }
  84. catch(Exception $e) {
  85. $this->model->rollback();
  86. IResponse::failure($e->getMessage());
  87. }
  88. if ($result) {
  89. IResponse::success([],'成功');
  90. }else{
  91. IResponse::failure('失败');
  92. }
  93. }
  94. }