123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <?php
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- namespace app\common\model\goods;
-
- use app\common\basics\Models;
- use app\common\model\distribution\DistributionGoods;
- use app\common\model\shop\Shop;
- use app\common\server\UrlServer;
-
-
-
- class Goods extends Models
- {
-
-
- public function GoodsImage()
- {
- return $this->hasMany('GoodsImage', 'goods_id', 'id')->field('goods_id, uri');
- }
-
-
- public function GoodsItem()
- {
- return $this->hasMany('GoodsItem', 'goods_id', 'id')
- ->field('id, goods_id, image, spec_value_ids, spec_value_str, market_price, price, stock, chengben_price');
- }
-
-
-
- public function Shop()
- {
- return $this->hasOne(Shop::class, 'id', 'shop_id')
- ->field('id, name, logo, type, star, score, intro,is_pay, mobile,is_freeze,is_run,expire_time')
- ->append([ 'is_expire' ]);
- }
-
- public function getIsDistributionDescAttr($value, $data)
- {
- return $data['is_distribution'] ? '是': '否';
- }
-
- function getIsMemberDescAttr($value, $data)
- {
- return $data['is_member'] ? '是': '否';
- }
-
-
-
- public function getGoodsNameById($goods_id)
- {
- return $this->where('id',$goods_id)->value('name');
-
- }
-
-
-
- public function checkStatusById($goods_id)
- {
- $status = $this
- ->where([
- ['id','=',$goods_id],
- ['del','=',0],
- ])
- ->value('status');
- if ($status){
- if ($status == 1){
- return true;
- }
- if (empty($status) || $status ===0){
- return false;
- }
- }
- return false;
- }
-
-
-
-
- public function getExpressType($goods_id)
- {
- return $this->where('id',$goods_id)->column('express_type,express_money,express_template_id')[0];
- }
-
-
-
- public function getMinMaxPriceAttr($value, $data)
- {
- return '¥ ' . $data['min_price'] . '~ ¥ '. $data['max_price'];
- }
-
-
-
- public function getDistributionFlagAttr($value)
- {
- $data = DistributionGoods::where('goods_id', $value)->findOrEmpty()->toArray();
- if (!empty($data) && $data['is_distribution'] == 1) {
- return true;
- }
- return false;
- }
-
-
-
-
- public function getContentAttr($value,$data){
-
-
-
- $content = $data['content'];
- if (!empty($content)) {
- $content = HtmlGetImage($content);
- }
- return $content;
- }
- public function setContentAttr($value,$data)
- {
- $content = $data['content'];
- if (!empty($content)) {
- $content = HtmlSetImage($content);
- }
- return $content;
- }
-
-
-
- public function searchIsDistributionAttr($query, $value, $data)
- {
-
- if (isset($data['is_distribution']) && $data['is_distribution'] == '0') {
-
- $ids = DistributionGoods::where('is_distribution', 1)->column('goods_id');
-
- $query->where('id', 'not in', $ids);
-
- }
-
- if (isset($data['is_distribution']) && $data['is_distribution'] == '1') {
-
- $ids = DistributionGoods::where('is_distribution', 1)->column('goods_id');
-
- $query->where('id', 'in', $ids);
- }
- }
- }
|