120 lines
3.7 KiB
PHP
120 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace addon\ali1688\model;
|
|
|
|
use app\model\BaseModel;
|
|
|
|
/**
|
|
* Common: 供应链商品相关处理
|
|
* Author: wu-hui
|
|
* Time: 2023/08/30 10:14
|
|
* Class Goods
|
|
* @package addon\funengscm\model
|
|
*/
|
|
class Template extends BaseModel
|
|
{
|
|
protected int $site_id = 0;
|
|
protected object $model;
|
|
|
|
public function __construct($siteId)
|
|
{
|
|
$this->site_id = $siteId;
|
|
$this->model = model('supply_price_template');
|
|
}
|
|
|
|
|
|
/**
|
|
* Common: 获取模板列表
|
|
* Author: wu-hui
|
|
* Time: 2023/08/30 16:54
|
|
* @param array $search
|
|
* @return mixed
|
|
*/
|
|
public function getTemplateList($search = [])
|
|
{
|
|
// 查询条件
|
|
$where = [
|
|
['site_id', '=', $search['site_id']]
|
|
];
|
|
if (!empty($search['filter']['title'])) $where[] = ['title', 'like', '%' . $search['filter']['title'] . '%'];
|
|
// 其他查询配置
|
|
$field = 'id,title,price_set,category_id,goods_class,alipaycategory_id,template_id,is_default,create_time,update_time';
|
|
$result = $this->model->pageList($where, $field, 'id DESC', $search['page'] ?? 1);
|
|
return $this->success($result ?? []);
|
|
}
|
|
|
|
/**
|
|
* 添加模板
|
|
*/
|
|
public function addTemplate($data)
|
|
{
|
|
if ($data['price_set']) $data['price_set'] = json_encode($data['price_set']);
|
|
if ($data['title_set']) $data['title_set'] = json_encode($data['title_set']);
|
|
if ($data['sku_set']) $data['sku_set'] = json_encode($data['sku_set']);
|
|
if(!isset($data['listing_mode'])){
|
|
$data['listing_mode'] = 1;//不上架
|
|
}
|
|
$result = $this->model->add($data);
|
|
if ($result) return json(['code' => '0', 'message' => '添加成功']);
|
|
else return json(['code' => '400', 'message' => '添加失败']);
|
|
}
|
|
|
|
/**
|
|
* 获取模板详情
|
|
* @param $id
|
|
* @return void
|
|
*
|
|
*/
|
|
public function templateInfo($id)
|
|
{
|
|
if (!intval($id)) {
|
|
return json(['code' => '400', 'message' => '模板ID错误']);
|
|
}
|
|
$where = ['id' => $id];
|
|
$field = 'id,title,category_id,goods_class,alipaycategory_id,template_id,price_set,listing_mode,title_set,sku_set';
|
|
$data = $this->model->getInfo($where, $field);
|
|
|
|
if ($data) {
|
|
if ($data['price_set']) $data['price_set'] = json_decode($data['price_set'], true);
|
|
if ($data['title_set']) $data['title_set'] = json_decode($data['title_set'], true);
|
|
if ($data['sku_set']) $data['sku_set'] = json_decode($data['sku_set'], true);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
* 修改模板
|
|
*/
|
|
public function editTemplate($data)
|
|
{
|
|
$id = $data['id'];
|
|
if (!intval($id)) {
|
|
return json(['code' => '400', 'message' => '模板ID错误']);
|
|
} else {
|
|
unset($data['id']);
|
|
}
|
|
if ($data['price_set']) $data['price_set'] = json_encode($data['price_set']);
|
|
if ($data['title_set']) $data['title_set'] = json_encode($data['title_set']);
|
|
if ($data['sku_set']) $data['sku_set'] = json_encode($data['sku_set']);
|
|
|
|
if ($this->model->update($data, ['id' => $id]))
|
|
return json(['code' => '0', 'message' => '保存成功']);
|
|
else return json(['code' => '400', 'message' => '保存失败']);
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
* 删除模板
|
|
*/
|
|
public function delTemplate($id)
|
|
{
|
|
if (!intval($id)) {
|
|
return json(['code' => '400', 'message' => '模板ID错误']);
|
|
}
|
|
if ($this->model->delete(['id' => $id]))
|
|
return json(['code' => '0', 'message' => '删除成功']);
|
|
else return json(['code' => '400', 'message' => '删除失败']);
|
|
}
|
|
} |