Fan.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace catchAdmin\wind\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\wind\model\Fan as fanModel;
  7. use think\facade\Db;
  8. class Fan extends CatchController
  9. {
  10. protected $fanModel;
  11. public function __construct(FanModel $fanModel)
  12. {
  13. $this->fanModel = $fanModel;
  14. }
  15. /**
  16. * 列表
  17. * @time 2022年04月28日 19:53
  18. * @param Request $request
  19. */
  20. public function index(Request $request) : \think\Response
  21. {
  22. return CatchResponse::paginate($this->fanModel->getList());
  23. }
  24. /**
  25. * 保存信息
  26. * @time 2022年04月28日 19:53
  27. * @param Request $request
  28. */
  29. public function save(Request $request) : \think\Response
  30. {
  31. $data = $request->post();
  32. $save_data=array(
  33. 'wind_id'=>$data['wind_id'],
  34. 'fan_model'=>$data['fan_model'],
  35. 'info'=>$data['info'],
  36. 'creator_id' => $data['creator_id'],
  37. 'created_at' => time(),
  38. );
  39. $add_fans=array();
  40. if($data['mul_number']){
  41. $numArr=explode(',',$data['mul_number']);
  42. foreach($numArr as $value) {
  43. $save_data['number']=$value;
  44. array_push($add_fans, $save_data);
  45. }
  46. }
  47. $rule_data=$data['rule_data'];
  48. if($rule_data['number_length'] && $rule_data['start_number']){
  49. $start=$rule_data['start_number'];
  50. $length=$rule_data['start_number']+$rule_data['number_length'];
  51. for($i=$start; $i<$length;$i++){
  52. if($rule_data['zero_fill']){
  53. $number=str_pad($i,$rule_data['zero_length'],'0',STR_PAD_LEFT );
  54. }else{
  55. $number=$i;
  56. }
  57. $save_data['number']=$rule_data['number_first'].$number.$rule_data['number_last'];
  58. array_push($add_fans, $save_data);
  59. }
  60. }
  61. $count1 = $this->fanModel->limit(100)->insertAll($add_fans);
  62. return CatchResponse::success('添加成功,共' . $count1 . '条');
  63. // return CatchResponse::success($this->fanModel->storeBy($data));
  64. }
  65. /**
  66. * 读取
  67. * @time 2022年04月28日 19:53
  68. * @param $id
  69. */
  70. public function read($id) : \think\Response
  71. {
  72. return CatchResponse::success($this->fanModel->findBy($id));
  73. }
  74. /**
  75. * 更新
  76. * @time 2022年04月28日 19:53
  77. * @param Request $request
  78. * @param $id
  79. */
  80. public function update(Request $request, $id) : \think\Response
  81. { $data = $request->post();
  82. return CatchResponse::success($this->fanModel->updateBy($id, $data));
  83. }
  84. /**
  85. * 删除
  86. * @time 2022年04月28日 19:53
  87. * @param $id
  88. */
  89. public function delete($id) : \think\Response
  90. {
  91. return CatchResponse::success($this->fanModel->deleteBy($id,true));
  92. }
  93. }