69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
// +----------------------------------------------------------------------
|
||
// | Author: CRMEB Team <admin@crmeb.com>
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\services\product\product;
|
||
|
||
|
||
use app\dao\product\product\StoreDescriptionDao;
|
||
use app\services\BaseServices;
|
||
use crmeb\exceptions\AdminException;
|
||
|
||
/**
|
||
* Class StoreDescriptionService
|
||
* @package app\services\product\product
|
||
* @mixin StoreDescriptionDao
|
||
*/
|
||
class StoreDescriptionServices extends BaseServices
|
||
{
|
||
/**
|
||
* StoreDescriptionServices constructor.
|
||
* @param StoreDescriptionDao $dao
|
||
*/
|
||
public function __construct(StoreDescriptionDao $dao)
|
||
{
|
||
$this->dao = $dao;
|
||
}
|
||
|
||
/**
|
||
* 获取商品详情
|
||
* @param array $where
|
||
* @return string
|
||
*/
|
||
public function getDescription(array $where)
|
||
{
|
||
$info = $this->dao->getDescription($where);
|
||
if ($info) return htmlspecialchars_decode($info->description);
|
||
return '';
|
||
}
|
||
|
||
/**
|
||
* 保存商品详情
|
||
* @param int $id
|
||
* @param string $description
|
||
* @param int $type
|
||
* @return bool
|
||
*/
|
||
public function saveDescription(int $id, string $description, int $type = 0)
|
||
{
|
||
$description = htmlspecialchars($description);
|
||
$data = ['product_id' => $id, 'type' => $type];
|
||
$info = $this->dao->count($data);
|
||
if ($info) {
|
||
$res = $this->dao->update($data, ['description' => $description]);
|
||
} else {
|
||
$data['description'] = $description;
|
||
$res = $this->dao->save($data);
|
||
}
|
||
if (!$res) throw new AdminException('商品详情保存失败!');
|
||
}
|
||
|
||
}
|