123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace huo\model\shop;
- use huo\model\common\CommonModel;
- class GoodsModel extends CommonModel {
- protected $name = 'goods';
-
- protected $readonly = ['admin_id'];
-
- protected $autoWriteTimestamp = true;
-
- protected function base($query) {
- $query->where('delete_time', 0)
- ->where('is_on_sale', 2);
- }
-
- public function getGoodsContentAttr($value) {
- return cmf_replace_content_file_url(htmlspecialchars_decode($value));
- }
-
- public function getOriginalImgAttr($value) {
- if (!empty($value)) {
- return cmf_get_image_url($value);
- }
- return $value;
- }
-
- public function setOriginalImgAttr($value) {
- if (!empty($value)) {
- return str_replace(STATICSITE.'/upload/', '', $value);
- }
- return $value;
- }
-
- public function setGoodsContentAttr($value) {
- return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
- }
-
- public function addGoods($data) {
- if (empty($data)) {
- return false;
- }
- if ($_obj = self::create($data, true)) {
- return $_obj->id;
- } else {
- return false;
- }
- }
-
- 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;
- }
- }
- }
|