User.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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\Db;
  9. use think\Exception;
  10. class User extends AdminController
  11. {
  12. protected $model;
  13. public function __construct(App $app = null)
  14. {
  15. parent::__construct($app);
  16. $this->model = new TaxiUser();
  17. }
  18. /**
  19. * @desc 审核司机
  20. * @param $ids
  21. * @throws \think\exception\PDOException
  22. * @author weichuanbao<654745815@qq.com>
  23. * @date 2021/12/7 0007
  24. */
  25. public function check($ids)
  26. {
  27. $row = $this->model::get($ids);
  28. if (!$row) {
  29. IResponse::failure('记录不存在');
  30. }
  31. if(!$row['user_id'] || !model('common/users')->where(['id'=> $row['user_id']])->find()){
  32. IResponse::failure('未绑定用户账号');
  33. }
  34. $result = false;
  35. $this->model->startTrans();
  36. try {
  37. $row->status = 5;
  38. $result = $row->save();
  39. $this->model->commit();
  40. }
  41. catch(Exception $e) {
  42. $this->model->rollback();
  43. }
  44. if ($result) {
  45. IResponse::success([],'成功');
  46. }
  47. IResponse::failure('失败');
  48. }
  49. /**
  50. * 用户批量操作
  51. *
  52. * @author 许祖兴 < zuxing.xu@lettered.cn>
  53. * @date 2020/6/11 14:34
  54. *
  55. * @return mixed
  56. */
  57. public function plectron(){
  58. // 收参数
  59. $params = $this->request->param();
  60. foreach (str2arr($params['ids']) as $id){
  61. $user = model('common/Users')->getBy($id);
  62. if ($this->request->isDelete()){
  63. $user->deleteBy($id);
  64. }
  65. //表里不存ids这个字段,要把ids改回表对应的字段名:id
  66. //user这个模型没有updateBy这个方法,所以回报错,既然循环,也不可能直接单个id对应
  67. // $user->allowField(true)->updateBy($id, $params);
  68. //懒得去补模型的方法了,我直接用原生写法对表操作了。
  69. //2022-3-3 丘 改动
  70. //判断 原状态 和 修改致状态 未交费之前 冻结,启用动作 都忽略;
  71. $olduser=Db::table('ins_users_motor_agent')->where('id',$id)->find();
  72. if(!$olduser){
  73. return IResponse::failure('用户不存在!');
  74. }
  75. if( $params['status']==40){
  76. if($olduser['status']<40){
  77. //没有通过交费 啥也不做
  78. }else{
  79. //做解冻,或冬季操作
  80. $res=Db::table('ins_users_motor_agent')->update(['status' => $params['status'],'id'=>$id]);
  81. }
  82. }
  83. if( $params['status']==50){
  84. if($olduser['status']<40){
  85. //没有通过交费 啥也不做
  86. }else{
  87. //做解冻,或冬季操作
  88. $res=Db::table('ins_users_motor_agent')->update(['status' => $params['status'],'id'=>$id]);
  89. }
  90. }
  91. }
  92. return IResponse::success([],'操作成功');
  93. }
  94. /**
  95. * @desc 发放合伙资产
  96. * @param $ids
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\ModelNotFoundException
  99. * @throws \think\exception\DbException
  100. * @throws \think\exception\PDOException
  101. * @author weichuanbao<654745815@qq.com>
  102. * @date 2022/1/7 0007
  103. */
  104. public function partnership($ids)
  105. {
  106. $row = $this->model->with('user')->find($ids);
  107. if (!$row) {
  108. IResponse::failure('记录不存在');
  109. }
  110. $params = input();
  111. $params['amount'] = input('amount', 0);
  112. if(floatval($params['amount'])<=0){
  113. IResponse::failure('请输入合法资产金额');
  114. }
  115. $MotorRecord = new MotorRecord();
  116. $result = false;
  117. $this->model->startTrans();
  118. try {
  119. if(!$row->user){
  120. IResponse::failure('该司机未绑定用户');
  121. }
  122. $row->user->taxi_property += $params['amount'];
  123. $result = $row->user->save();
  124. IResponse::failure('该司机未绑定用户');
  125. $MotorRecord->setMoneyLog($row['user'], 'taxi_property', $params['amount'], 30, '发放通证资产');
  126. $MotorRecord->saveMoneyLog();
  127. $this->model->commit();
  128. }
  129. catch(Exception $e) {
  130. $this->model->rollback();
  131. IResponse::failure($e->getMessage());
  132. }
  133. if ($result) {
  134. IResponse::success([],'成功');
  135. }else{
  136. IResponse::failure('失败');
  137. }
  138. }
  139. }