更新活动接口

wysf
Wayne 9 months ago
parent a2d4d99b0c
commit ffb2cf800e
  1. 9
      app/common/model/ActiveCol.php
  2. 4
      app/common/model/ActiveMain.php
  3. 59
      app/store/controller/market/Active.php
  4. 10
      app/store/model/ActiveCol.php

@ -28,5 +28,14 @@ class ActiveCol extends BaseModel
// 定义主键
protected $pk = 'id';
/**
* col_image关联
* @return HasOne
*/
public function colImage(): HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'col_image_id')
->bind(['col_image_url' => 'preview_url']);
}
}

@ -46,7 +46,7 @@ class ActiveMain extends BaseModel
public function indexImage(): HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'index_image_id')
->bind(['image_url' => 'preview_url']);
->bind(['index_image_url' => 'preview_url']);
}
/**
@ -56,7 +56,7 @@ class ActiveMain extends BaseModel
public function themeImage(): HasOne
{
return $this->hasOne('UploadFile', 'file_id', 'theme_image_id')
->bind(['image_url' => 'preview_url']);
->bind(['theme_image_url' => 'preview_url']);
}
}

@ -8,6 +8,7 @@ use think\response\Json;
use app\store\controller\Controller;
use app\store\model\ActiveMain as ActiveMainModal;
use app\store\model\ActiveCol as ActiveColModal;
use app\store\model\Goods as GoodsModal;
/**
* 活动管理
@ -70,7 +71,7 @@ class Active extends Controller
$model = new ActiveColModal;
$list = $model->getList($activeId);
if (count($list) > 0) {
return $this->renderError('请先删除活动模块');
return $this->renderError('请先删除活动栏目');
}
$model = ActiveMainModal::detail($activeId);
@ -92,4 +93,60 @@ class Active extends Controller
return $this->renderSuccess(compact('list'));
}
/**
* 添加活动模块
* @return Json
*/
public function colAdd(): Json
{
// 新增记录
$model = new ActiveColModal;
if ($model->add($this->postForm())) {
return $this->renderSuccess('添加成功');
}
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* 更新活动模块
* @param int $activeColId
* @return Json
*/
public function colEdit(int $activeColId): Json
{
$model = ActiveColModal::detail($activeColId);
// 更新记录
if ($model->edit($this->postForm())) {
return $this->renderSuccess('更新成功');
}
return $this->renderError($model->getError() ?: '更新失败');
}
/**
* 删除活动模块
* @param int $activeColId
* @return Json
*/
public function colDelete(int $activeColId): Json
{
$model = ActiveColModal::detail($activeColId);
if ($model->setDelete()) {
return $this->renderSuccess('删除成功');
}
return $this->renderError($model->getError() ?: '删除失败');
}
/**
* goodsList 获取商品列表
* @return Json
*/
public function goodsList(string $goodsIds): Json
{
$goodsIds = explode(',', $goodsIds);
$model = new GoodsModal;
$list = $model->getListByIds($goodsIds);
return $this->renderSuccess(compact('list'));
}
}

@ -28,9 +28,12 @@ class ActiveCol extends ActiveColModal
*/
public function getList($activeId): \think\Paginator
{
return $this->where(
$data = $this->where(
['active_id' => $activeId]
)->paginate();
$data = self::preload($data, ['colImage']);
return $data;
}
/**
@ -51,6 +54,11 @@ class ActiveCol extends ActiveColModal
*/
public function add(array $data): bool
{
if (empty($data['active_id'])) {
$this->error = '活动ID不能为空';
return false;
}
$data['store_id'] = self::$storeId;
return $this->save($data);
}

Loading…
Cancel
Save