'全部', self::Stop => '停用', self::Normal => '正常' ]; //获取产品信息 public static function getBySynthesisProduct(string $product_id, int $type_id, $lan = 'zh') { if(empty($product_id)) return []; $info = self::whereIn('id', $product_id); if($type_id == ProductPledges::Combin) $info = $info->orderRaw('field(id,'. $product_id.')'); $info = $info->field('id,thum,'.$lan.'_name as name')->select(); return $info ; } //地区 public function productarea() { return $this->hasMany('ProductArea', 'product_id', 'id')->field('id,product_id'); } //已出售地区 public function productareastop() { return $this->hasMany('ProductArea', 'product_id', 'id')->where('status', 0)->field('id,product_id'); } //hold_num public function productorder() { return $this->hasMany('ProductOrder', 'product_id', 'id')->where('status', 'in', [ProductOrder::Paid, ProductOrder::Transferred, ProductOrder::Freeze])->field('id,product_id'); } //分类 public function products() { return $this->hasOne('ProductsModel', 'id', 'type_id', [], 'LEFT')->setEagerlyType(0); } //抢购 ProductPopular public function productpopular() { return $this->hasOne('ProductPopular', 'product_id', 'id', [], 'INNER')->order('start_time')->setEagerlyType(0); } //寄售 public function producttransfer() { $map = []; $transfer = input('post.transfer_id/d', 0); if($transfer > 0) $map['id'] = $transfer; $order = 'id desc,price ASC'; if(input('post.sort') == 1) $order = 'price desc'; if(input('post.sort') == 2) $order = 'price asc'; return $this->hasMany('ProductTransfer', 'product_id', 'id', [], 'LEFT')->where($map)->where('status', self::Normal)->order($order); } //收藏 public function collect() { return $this->hasOne('UserCollect', 'product_id', 'id', [], 'LEFT')->where('user_id', Auth::instance()->getUser()['id']); } //获取产品分类 public static function getProductTypeById(int $productId) { return self::where('id', $productId)->value('type_id'); } //获取状态 public function getStatusTextAttr($value, $data){ $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); } protected static function init() { self::afterInsert(function ($row) { $pk = $row->getPk(); $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]); }); } public function getCreateTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } public function getUpdateTimeTextAttr($value, $data) { $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : ''); return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value; } protected function setCreateTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } protected function setUpdateTimeAttr($value) { return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value); } }