123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace catchAdmin\wind\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\wind\model\Fan as fanModel;
- use catcher\base\CatchRequest;
- use think\facade\Db;
- class Fan extends CatchController
- {
- protected $fanModel;
- public function __construct(FanModel $fanModel)
- {
- $this->fanModel = $fanModel;
- }
- /**
- * 列表
- * @time 2022年04月28日 19:53
- * @param Request $request
- */
- public function index(Request $request): \think\Response
- {
- return CatchResponse::paginate($this->fanModel->getList());
- }
- /**
- *根据风场的id获取风机的列表
- *
- * @param Request $request
- * @return void
- */
- public function getList(Request $request)
- {
- return CatchResponse::success($this->fanModel->getFanList());
- }
- /**
- * 保存信息
- * @time 2022年04月28日 19:53
- * @param Request $request
- */
- public function save(Request $request): \think\Response
- {
- $data = $request->post();
- $save_data = array(
- 'wind_id' => $data['wind_id'],
- 'fan_model' => $data['fan_model'],
- 'supplier' => $data['supplier'],
- 'out_date' => date('Y-m-d', $data['out_date']),
- 'address' => $data['address'],
- 'info' => $data['info'],
- 'creator_id' => $data['creator_id'],
- 'created_at' => time(),
- );
- if (isset($data['out_date']) && is_int($data['out_date'])) {
- $save_data['out_date'] = date('Y-m-d', $data['out_date']);
- }
- $add_fans = array();
- if ($data['mul_number']) {
- $numArr = explode(',', $data['mul_number']);
- foreach ($numArr as $value) {
- $save_data['number'] = $value;
- array_push($add_fans, $save_data);
- }
- }
- $rule_data = $data['rule_data'];
- if ($rule_data['number_length'] && $rule_data['start_number']) {
- $start = $rule_data['start_number'];
- $length = $rule_data['start_number'] + $rule_data['number_length'];
- for ($i = $start; $i < $length; $i++) {
- if ($rule_data['zero_fill']) {
- $number = str_pad($i, $rule_data['zero_length'], '0', STR_PAD_LEFT);
- } else {
- $number = $i;
- }
- $save_data['number'] = $rule_data['number_first'] . $number . $rule_data['number_last'];
- array_push($add_fans, $save_data);
- }
- }
- $count1 = $this->fanModel->saveAll($add_fans);
- //下发风机模型
- $this->fanModel->IssuedFanModel($data['wind_id']);
- return CatchResponse::success('添加成功,共' . count($count1) . '条');
- // return CatchResponse::success($this->fanModel->storeBy($data));
- }
- /**
- * 读取
- * @time 2022年04月28日 19:53
- * @param $id
- */
- public function read($id): \think\Response
- {
- return CatchResponse::success($this->fanModel->findBy($id));
- }
- /**
- * 更新
- * @time 2022年04月28日 19:53
- * @param Request $request
- * @param $id
- */
- public function update(Request $request, $id): \think\Response
- {
- $data = $request->post();
- if (isset($data['out_date']) && is_int($data['out_date'])) {
- $data['out_date'] = date('Y-m-d', $data['out_date']);
- }
- $data['id'] = $id;
- $this->fanModel->updateBy($id, $data);
- //下发风机模型
- $this->fanModel->IssuedFanModel($data['wind_id']);
- return CatchResponse::success();
- }
- /**
- * 删除
- * @time 2022年04月28日 19:53
- * @param $id
- */
- public function delete($id): \think\Response
- {
- if (is_array($id)) {
- $data = $this->fanModel->findBy($id);
- $this->fanModel->deleteBy($id, true);
- $this->fanModel->IssuedFanModel($data['wind_id']);
- } else {
- $where[] = ['id', 'in', $id];
- $list = $this->fanModel->where($where)->group('wind_id')->column('wind_id');
- $this->fanModel->deleteBy($id, true);
- foreach ($list as $item) {
- $this->fanModel->IssuedFanModel($item['wind_id']);
- }
- }
- return CatchResponse::success();
- }
- }
|