You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.4 KiB
77 lines
2.4 KiB
<?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\sku;
|
|
|
|
|
|
use app\dao\product\sku\StoreProductAttrResultDao;
|
|
use app\services\BaseServices;
|
|
use crmeb\exceptions\AdminException;
|
|
|
|
/**
|
|
* Class StoreProductAttrResultService
|
|
* @package app\services\product\sku
|
|
* @mixin StoreProductAttrResultDao
|
|
*/
|
|
class StoreProductAttrResultServices extends BaseServices
|
|
{
|
|
/**
|
|
* StoreProductAttrResultServices constructor.
|
|
* @param StoreProductAttrResultDao $dao
|
|
*/
|
|
public function __construct(StoreProductAttrResultDao $dao)
|
|
{
|
|
$this->dao = $dao;
|
|
}
|
|
|
|
/**
|
|
* 获取属性规格
|
|
* @param array $where
|
|
* @return mixed
|
|
*/
|
|
public function getResult(array $where)
|
|
{
|
|
return json_decode($this->dao->value($where, 'result'), true);
|
|
}
|
|
|
|
/**
|
|
* 删除属性
|
|
* @param int $id
|
|
* @param int $type
|
|
* @return bool
|
|
*/
|
|
public function del(int $id, int $type)
|
|
{
|
|
return $this->dao->del($id, $type);
|
|
}
|
|
|
|
/**
|
|
* 设置属性
|
|
* @param array $data
|
|
* @param int $id
|
|
* @param int $type
|
|
* @return bool
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function setResult(array $data, int $id, int $type)
|
|
{
|
|
$result = $this->dao->get(['product_id' => $id, 'type' => $type]);
|
|
if ($result) {
|
|
$res = $this->dao->update($result['id'], ['result' => json_encode($data), 'change_time' => time()]);
|
|
} else {
|
|
$res = $this->dao->save(['product_id' => $id, 'result' => json_encode($data), 'change_time' => time(), 'type' => $type]);
|
|
}
|
|
if (!$res) throw new AdminException('规格保存失败');
|
|
return true;
|
|
}
|
|
}
|
|
|