15669368801 4 years ago
parent
commit
a8abf8a36c

+ 72 - 2
app/adminapi/controller/v1/company/Company.php

@@ -6,6 +6,8 @@ use app\adminapi\controller\AuthController;
 use crmeb\services\{UtilService as Util};
 use app\models\section\SectionModel;
 use app\models\company\CompanyModel;
+use app\models\company\ExampleModel;
+use app\models\company\DesignerModel;
 use think\Request;
 
 class Company extends AuthController
@@ -19,10 +21,78 @@ class Company extends AuthController
     {
         $where = Util::getMore([
             ['title', ''],
-            ['sid', 0],
+            ['sid', ''],
             ['page', 1],
             ['limit', 10]
         ], $this->request);
         $list = CompanyModel::systemPage($where);
         return $this->success($list);
-    }
+    }
+
+    /**
+     * 保存新建的资源
+     *
+     * @param \think\Request $request
+     * @return \think\Response
+     */
+    public function save(Request $request)
+    {
+        $data = Util::postMore([
+            ['id', 0],
+            ['sid', ''],
+            ['title', ''],
+            ['logo', ''],
+            ['intro', ''],
+            ['contact', ''],
+            ['phone', ''],
+            ['project', ''],
+            ['slider_image', ''],
+            ['sort', 0],
+            ['status', 1],
+            ['example', []],
+            ['designer', []],
+        ]);
+        if (!$data['title']) return $this->fail('缺少参数');
+        $example = $data['example'];
+        $designer = $data['designer'];
+        unset($data['example'], $data['designer']);
+        if ($data['id']) {
+            $id = $data['id'];
+            unset($data['id']);
+            $res = CompanyModel::edit($data, $id, 'id');
+            ExampleModel::saveExample($example, $id);
+            DesignerModel::saveDesigner($designer, $id);
+            return $this->success('修改成功!', ['id' => $id]);
+        } else {
+            $data['add_time'] = time();
+            $res = CompanyModel::create($data);
+            foreach($example as $key => $value){
+                $example[$key]['cid'] = (int)($res['id']);
+            }
+            foreach($designer as $key => $value){
+                $designer[$key]['cid'] = (int)($res['id']);
+            }
+            ExampleModel::saveExample($example, $res['id']);
+            DesignerModel::saveDesigner($designer, $res['id']);
+            return $this->success('添加成功!', ['id' => $res->id]);
+        }
+    }
+
+    /**
+     * 显示指定的资源
+     *
+     * @param int $id
+     * @return \think\Response
+     */
+    public function read($id)
+    {
+        if ($id) {
+            $info = ArticleModel::where('n.id', $id)->alias('n')->field('n.*,c.content')->join('ArticleContent c', 'c.nid=n.id', 'left')->find();
+            if (!$info) return $this->fail('数据不存在!');
+            $info['cid'] = intval($info['cid']);
+        }
+        $info = CompanyModel::getOne($id);
+        return $this->success(compact('info'));
+    }
+
+}

+ 29 - 1
app/models/company/CompanyModel.php

@@ -30,8 +30,36 @@ class CompanyModel extends BaseModel
         $model = $model->where('is_del', 0);
         $model = $model->order('sort desc,id desc');
         $count = $model->count();
-        $list = $model->page((int)$where['page'], (int)$where['limit'])->select()->toArray();
+        $list = $model->page((int)$where['page'], (int)$where['limit'])->select()->each(function ($item) {
+            $item['_add_time'] = date('Y-m-d H:i:s', $item['add_time']);
+        })->toArray();
         return compact('count', 'list');
     }
 
+    /**
+     * 详情
+     */
+    public static function getOne($id)
+    {
+        $info = self::where('is_del', 0)->find($id);
+        if ($info) {
+            if ($info['start_time'])
+                $start_time = date('Y-m-d H:i:s', $info['start_time']);
+
+            if ($info['end_time'])
+                $end_time = date('Y-m-d H:i:s', $info['end_time']);
+            if (isset($start_time) && isset($end_time))
+                $info['section_time'] = [$start_time, $end_time];
+            else
+                $info['section_time'] = [];
+            unset($info['start_time'], $info['end_time']);
+        }
+        if ($info['poster'])
+            $info['poster'] = json_decode($info['poster'], true);
+        else
+            $info['poster'] = [];
+        $info['brokerage'] = StoreRechargeCardBrokerage::where(['cid' => $id])->order('role asc, level asc')->select();
+        return $info;
+    }
+
 }

+ 50 - 0
app/models/company/DesignerModel.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\models\company;
+
+use think\facade\Db;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+class DesignerModel extends BaseModel
+{
+	/**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'designer';
+
+    use ModelTrait;
+
+    /**
+     * 新增或编辑设计师
+     */
+    public static function saveDesigner($indata, $cid)
+    {
+        $ids = array();
+        foreach($indata as $value){
+            if(!$value){
+                return $this->fail('请输入正确的案例');
+            }
+            if(!empty($value['id'])){
+                $ids[] = $value['id'];
+                self::edit($value, $value['id']);
+            }else{
+                $ids[] = self::insertGetId($value);
+            }
+        }
+        $data[] = ['id', 'not in', $ids];
+        $data[] = ['cid', '=', $cid];
+        $overs = self::where($data)->select();
+        foreach($overs as $over){
+            self::destroy($over['id']);
+        }
+    }
+
+}

+ 50 - 0
app/models/company/ExampleModel.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\models\company;
+
+use think\facade\Db;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+class ExampleModel extends BaseModel
+{
+	/**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'example';
+
+    use ModelTrait;
+
+    /**
+     * 新增或编辑案例
+     */
+    public static function saveExample($indata, $cid)
+    {
+        $ids = array();
+        foreach($indata as $value){
+            if(!$value){
+                return $this->fail('请输入正确的案例');
+            }
+            if(!empty($value['id'])){
+                $ids[] = $value['id'];
+                self::edit($value, $value['id']);
+            }else{
+                $ids[] = self::insertGetId($value);
+            }
+        }
+        $data[] = ['id', 'not in', $ids];
+        $data[] = ['cid', '=', $cid];
+        $overs = self::where($data)->select();
+        foreach($overs as $over){
+            self::destroy($over['id']);
+        }
+    }
+
+}