[ // 设计罐容 'tankCapacity' => '', // 油罐类型 'tankType' => '', // 储存品种 'varieties' => '菜籽油', // 储存性质 'nature' => '', // 储存数量 'storageNum' => '', // 原料产地 'productArea' => '', // 加工地 'addr' => '', // 加工年度 'machiningYear' => '', // 入罐时间 'enterTime' => '', // 等级 'level' => '', // 色泽 'color' => '', // 气味滋味 'odorAndTaste' => '', // 水分及挥发物 'waterVolatileCompounds' => '', // 不溶性杂质 'insolubleImpurities' => '', // 酸价 'acidValue' => '', // 过氧化值 'peroxideValue' => '', // 加热试验 'heating' => '', // 溶剂残留量 'residualSolventContent' => '', // 罐内直径 'TankDiameter' => '', // 装油高度 'oilLoadingHeight' => '', // 扣除(增加体积) 'volume' => '', // 油脂体脂 'oilVolume' => '', // 管理形式 'managementForm' => '', // 保管员 'custodian' => '' ], // '稻谷' 'two' => [ // 货位编号 'code' => '', // 仓型 'warehouseType' => '', // 核定仓容 'capacity' => '', // 储存品种 'varieties' => '稻谷', // 储存性质 'nature' => '', // 产地 'addr' => '', // 收获年度 'harvestYear' => '', // 入仓时间 'enterTime' => '', // 储存数量 'storageNum' => '', // 等级 'level' => '', // 出糙率 'roughnessRate' => '', // 杂质 'impurity' => '', // 拆合水分 'water' => '', // 散存粮体积 'volume' => '', // 扣除体积 'decVolume' => '', // 整精米粒 'riceGrains' => '', // 管理形式 'managementForm' => '', // 长(米) 'length' => '', // 宽(米) 'width' => '', // 直径(米) 'diam' => '', // 高(米) 'height' => '', // 保管方式 'storageMethod' => '', // 保管员 'custodian' => '' ], // 小麦和玉米 'three' => [ // 货位编号 'code' => '', // 仓型 'warehouseType' => '', // 核定仓容 'capacity' => '', // 储存品种 'varieties' => '小麦', // 储存性质 'nature' => '', // 产地 'addr' => '', // 收获年度 'harvestYear' => '', // 入仓时间 'enterTime' => '', // 储存数量 'storageNum' => '', // 等级 'level' => '', // 容重 'weight' => '', // 杂质 'impurity' => '', // 拆合水分 'water' => '', // 散存粮体积 'volume' => '', // 扣除体积 'decVolume' => '', // 不完善粒 'imperfect' => '', // 管理形式 'managementForm' => '', // 长(米) 'length' => '', // 宽(米) 'width' => '', // 直径(米) 'diam' => '', // 高(米) 'height' => '', // 保管方式 'storageMethod' => '', // 保管员 'custodian' => '' ] ]; return $fields; } public function getContentAttr($value, $data) { return json_decode($value, true); } /** * 获取列表 * @param $params * @param int $rows * @param int $page * @param string $fields * @return array * @throws \think\exception\DbException */ public function getLists($params, $rows = 20, $page = 1, $fields = '*') { // 条件搜索 if (!empty($params['where'])) { $this->where($params['where']); } else { if (!empty($params['keyword'])) { switch ($params['type']) { case 1 : $this->where(['name' => ['LIKE', '%' . $params['keyword'] . '%']]); break; case 2 : $this->where(['storage' => ['LIKE', '%' . $params['keyword'] . '%']]); break; case 3 : $this->where(['num' => ['LIKE', '%' . $params['keyword'] . '%']]); break; case 4 : $this->where(['code' => ['LIKE', '%' . $params['keyword'] . '%']]); break; } } // 时间范围查询 if (!empty($params['start_time'])) { $this->where('create_time', '>=', strtotime($params['start_time'])); } if (!empty($params['end_time'])) { $this->where('create_time', '<=', strtotime($params['end_time'])); } // 省市查询 if (!empty($params['china']) && is_array($params['china'])) { $count = count($params['china']); if ($count >= 1) { $this->where('province_id', '=', $params['china'][0]); } if ($count >= 2) { $this->where('city_id', '=', $params['china'][1]); } } if (!empty($params['granary_type'])) { $this->where(['granary_type' => $params['granary_type']]); } if (!empty($params['varieties']) && $params['varieties'] != '全部') { $this->where(['varieties' => $params['varieties']]); } } // 排序 $order = !empty($params['order']) ? $params['order'] : 'id DESC'; $result = $this ->field($fields) ->order($order) ->paginate($rows, false, [ 'page' => $page ]); $arr = [ 'list' => [], 'total' => 0, 'page' => 1, 'pageSize' => $rows, 'totalSize' => 0 ]; // 格式化数据信息 if (!$result->isEmpty()) { $arr = [ 'list' => $result->items(), 'total' => $result->total(), 'page' => $result->currentPage(), 'pageSize' => $result->listRows(), 'totalSize' => $result->lastPage() ]; } return $arr; } /** * 添加 * @param $data * @return bool|int|string */ public function add($data) { if (empty($data) || !is_array($data)) { $this->error = '参数不正确'; return false; } return $this->transaction(function () use ($data) { $id = $this->insertGetId($data); return $id; }); } /** * 获取某条记录 * @param $where * @return array|bool|false|\PDOStatement|string|Model * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getItem($where, $fields = '*', $with = []) { if (empty($where)) { $this->error = '参数不正确。'; return false; } if (floor($where) > 0) { $where = ['id' => $where]; } if (!empty($with)) { $this->with($with); } return $this->where($where)->field($fields)->find(); } /** * 编辑 * @param $data * @return bool */ public function edit($data) { if (empty($data) || !is_array($data)) { $this->error = '参数不正确'; return false; } return $this->transaction(function () use ($data) { $res = $this->update($data); return $res; }); } /** * 删除 * @param $id * @return bool|mixed */ public function del($id) { if (empty($id)) { $this->error = '参数不正确'; return false; } return $this->transaction(function () use ($id) { TestingModel::where(['gid' => $id])->delete(); TestingParamsModel::where(['gid' => $id])->delete(); return $this->where([ 'id' => $id, ])->delete(); }); } }