123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- /**
- * GoodsModel.php UTF-8
- * 商品表
- *
- * @date : 2018/5/7 18:35
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @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;
- }
- }
- }
|