|
@@ -4,7 +4,7 @@ namespace app\admin\controller\asset;
|
|
|
|
|
|
use app\admin\validate\asset\HouseTypeValidate;
|
|
|
use app\controller\Curd;
|
|
|
-use app\model\Asset;
|
|
|
+use app\model\Content;
|
|
|
use support\exception\BusinessException;
|
|
|
use support\Request;
|
|
|
use support\Response;
|
|
@@ -13,19 +13,21 @@ class HouseTypeController extends Curd
|
|
|
{
|
|
|
public function __construct()
|
|
|
{
|
|
|
- $this->model = new Asset();
|
|
|
- $this->validate = true;
|
|
|
- $this->validateClass = new HouseTypeValidate();
|
|
|
+ $this->model = new Content();
|
|
|
+// $this->validate = true;
|
|
|
+// $this->validateClass = new HouseTypeValidate();
|
|
|
}
|
|
|
|
|
|
public function select(Request $request): Response
|
|
|
{
|
|
|
[$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
|
+ $where['content_category'] = 'HOUSE';
|
|
|
$order = $request->get('order', 'desc');
|
|
|
- $field = $field ?? 'asset_addtimes';
|
|
|
+ $field = $field ?? 'content_addtimes';
|
|
|
$query = $this->doSelect($where, $field, $order);
|
|
|
return $this->doFormat($query, $format, $limit);
|
|
|
}
|
|
|
+
|
|
|
protected function doSelect(array $where, string $field = null, string $order = 'desc')
|
|
|
{
|
|
|
$model = $this->model->with([
|
|
@@ -70,14 +72,19 @@ class HouseTypeController extends Curd
|
|
|
|
|
|
public function afterQuery($items)
|
|
|
{
|
|
|
+ $specs = self::$specs;
|
|
|
foreach ($items as &$item) {
|
|
|
- $assetHouseJson = json_decode($item->asset_house_json, true);
|
|
|
- if (!empty($assetHouseJson['floor_plan'])) {
|
|
|
- $assetHouseJson['floor_plan'] = getenv('STORAGE_DOMAIN') . $assetHouseJson['floor_plan'];
|
|
|
- $item->asset_house_json = $assetHouseJson;
|
|
|
+ $item->content_config_json = json_decode($item->content_config_json, true);
|
|
|
+ $newSpecs = [];
|
|
|
+ foreach ($item->content_config_json['specs'] as $key => $value) {
|
|
|
+ if (in_array($key, $specs) && !empty($value)) {
|
|
|
+ $key = array_search($key, $specs);
|
|
|
+ $newSpecs[$key] = $value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($newSpecs)) {
|
|
|
+ $item->content_config_json['specs'] = $newSpecs;
|
|
|
}
|
|
|
-
|
|
|
- $item->asset_json = json_decode($item->asset_json, true);
|
|
|
}
|
|
|
|
|
|
return $items;
|
|
@@ -94,18 +101,27 @@ class HouseTypeController extends Curd
|
|
|
*/
|
|
|
protected function insertInput(Request $request): array
|
|
|
{
|
|
|
- $data = $this->inputFilter($request->post());
|
|
|
- $data['asset_id'] = 'AE' . date('YmdHis') . random_string(6, 'up');
|
|
|
- if (!empty($request->post('floor_plan'))) {
|
|
|
- $data['asset_house_json'] = json_encode(['floor_plan' => str_replace(getenv('STORAGE_DOMAIN'), '', $request->post('floor_plan'))]);
|
|
|
- } else {
|
|
|
- $data['asset_house_json'] = [];
|
|
|
+ $params = $request->post();
|
|
|
+ $params['content_config_json'] = json_encode($params['content_config_json']);
|
|
|
+ $data = $this->inputFilter($params);
|
|
|
+ $data['content_config_json'] = json_decode($data['content_config_json'], true);
|
|
|
+ if (!empty($data['content_config_json']['cover'])) {
|
|
|
+ $data['content_config_json']['cover'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['content_config_json']['cover']);
|
|
|
}
|
|
|
- if (!empty($request->post('asset_house_address'))) {
|
|
|
- $data['asset_json'] = json_encode(['address' => $request->post('asset_house_address')]);
|
|
|
- } else {
|
|
|
- $data['asset_json'] = '[]';
|
|
|
+ if (!empty($data['content_config_json']['img'])) {
|
|
|
+ $data['content_config_json']['img'] = str_replace(getenv("STORAGE_DOMAIN"), '', $data['content_config_json']['img']);
|
|
|
}
|
|
|
+ $specs = [];
|
|
|
+ foreach ($data['content_config_json']['specs'] as $key => $item) {
|
|
|
+ $specs[self::$specs[$key]] = $item;
|
|
|
+ }
|
|
|
+ $data['content_config_json']['specs'] = $specs;
|
|
|
+
|
|
|
+ $data['content_config_json'] = json_encode($data['content_config_json']);
|
|
|
+
|
|
|
+ $data['img'] = [$data['img']];
|
|
|
+ $data['cover'] = [$data['cover']];
|
|
|
+ dump($data);
|
|
|
|
|
|
return $data;
|
|
|
}
|
|
@@ -135,4 +151,15 @@ class HouseTypeController extends Curd
|
|
|
unset($data[$primary_key]);
|
|
|
return [$id, $data];
|
|
|
}
|
|
|
+
|
|
|
+ public static $specs = [
|
|
|
+ 'bianhao' => "编号",
|
|
|
+ 'cengshu' => '层数',
|
|
|
+ 'chanquan' => '产权',
|
|
|
+ 'chaoxiang' => '朝向',
|
|
|
+ 'jiaofang' => '交房',
|
|
|
+ 'mianji' => '面积',
|
|
|
+ 'xingzhi' => '性质',
|
|
|
+ 'zhuangxiu' => '装修'
|
|
|
+ ];
|
|
|
}
|