* @version : HUOSDK 8.0 */ namespace huo\model\shop; use huo\model\common\CommonModel; class GoodsModel extends CommonModel { protected $name = 'goods'; //设置只读字段 protected $readonly = ['admin_id']; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = true; /** * 基础查询 * 上线未删除 * * @param $query */ protected function base($query) { $query->where('delete_time', 0) ->where('is_on_sale', 2); } /** * goods_content 自动转化 * * @param $value * * @return string */ public function getGoodsContentAttr($value) { return cmf_replace_content_file_url(htmlspecialchars_decode($value)); } /** * @param $value * * @return string */ public function getOriginalImgAttr($value) { if (!empty($value)) { return cmf_get_image_url($value); } return $value; } /** * image 自动转化 * * * @param $value * * @return array */ public function setOriginalImgAttr($value) { if (!empty($value)) { return str_replace(STATICSITE.'/upload/', '', $value); } return $value; } /** * goods_content 自动转化 * * @param $value * * @return string */ public function setGoodsContentAttr($value) { return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true)); } /** * 添加商品 * * @param $data * * @return bool|mixed */ public function addGoods($data) { if (empty($data)) { return false; } if ($_obj = self::create($data, true)) { return $_obj->id; } else { return false; } } /** * 更新商品 * * @param array $goods_data * @param string $goods_id * * @return bool */ public function updateGoods($goods_data, $goods_id) { $_map['id'] = $goods_id; $_data = $goods_data; $_rs = self::update($_data, $_map, true); if (false == $_rs) { return false; } else { return true; } } }