Mobile.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\sub\controller;
  3. use app\common\model\Mobile as M;
  4. use app\common\model\MobileHoldLog;
  5. use think\Db;
  6. /**
  7. * 会员中心
  8. */
  9. class Mobile extends SubCommon
  10. {
  11. protected $noNeedLogin=[];
  12. protected $noNeedRight="*";
  13. public function edit(){
  14. $data=input();
  15. $mobile=M::where('s_id',$this->auth->id)->findOrFail($data['id']);
  16. if($this->request->isGet()){
  17. $this->validate($data,[
  18. 'id'=>'require',
  19. ]);
  20. $this->assign('mobile',$mobile);
  21. return view();
  22. }else{
  23. $this->validate($data,[
  24. 'amount_base'=>['require','number','gt:0'],
  25. ]);
  26. foreach ($this->request->only('amount_base') as $key=>$value){
  27. $mobile[$key]=$value;
  28. }
  29. $mobile->save();
  30. $this->success();
  31. }
  32. }
  33. #修改预占
  34. public function hold(){
  35. $data=input();
  36. $user=$this->auth->getUser();
  37. $this->validate($data,[
  38. 'id'=>['require','integer'],
  39. 'is_hold'=>['require','in:0,1'],
  40. ]);
  41. $mobile=M::where('s_id',$this->auth->id)->findOrFail($data['id']);
  42. Db::startTrans();
  43. $mobile['is_hold']=$data['is_hold'];
  44. $mobile->save();
  45. $mobile->holdLog()->save(MobileHoldLog::withHoldUser($user,$data['is_hold']));
  46. Db::commit();
  47. $this->success();
  48. }
  49. }