with(['mallProduct']) ->hasWhere('mallProduct', $where_mall_product, $field) ->where($where)->order($order)->select()->each(function ($item, $key) { if ($item['product_is_publish'] == 0 || !empty($item['product_delete_time'])) { // 是否有效 0--失效 1--有效 $item['is_effective'] = 0; } else { $item['is_effective'] = 1; } unset($item['mallProduct']); unset($item['product_delete_time']); unset($item['product_is_publish']); }); } /** * 一对一关联产品 * @date 2022-12-01 */ public function mallProduct() { return $this->hasOne('mallProduct', 'id', 'product_id')->removeOption('soft_delete')->bind([ 'product_name' => 'name', 'product_cover_img' => 'cover_img', 'product_price' => 'price_min', 'product_is_publish' => 'is_publish', 'product_delete_time' => 'delete_time', ]); } }