User.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. try {
  73. if(!$row->user){
  74. IResponse::failure('该司机未绑定用户');
  75. }
  76. $row->user->partnership = $params['amount'];
  77. $result = $row->user->save();
  78. IResponse::failure('该司机未绑定用户');
  79. $MotorRecord->setMoneyLog($row['user'], 'partnership', $params['amount'], 30, '发放合伙资产');
  80. $MotorRecord->saveMoneyLog();
  81. $this->model->commit();
  82. }
  83. catch(Exception $e) {
  84. $this->model->rollback();
  85. IResponse::failure($e->getMessage());
  86. }
  87. if ($result) {
  88. IResponse::success([],'成功');
  89. }else{
  90. IResponse::failure('失败');
  91. }
  92. }
  93. }