60], [['status'], 'default', 'value' => -1], [['accessories_image'], 'string'], [['goods_id'], 'safe'] ]; } /** * 保存商品搭配图片 * @return array */ public function save() { $goods_id = $this->goods_id; $store_id = $this->store_id; $accessories_image = $this->accessories_image; if (is_string($goods_id) || is_int($goods_id)) { $goods_id = explode(',', $goods_id); } if (!empty($goods_id)) { foreach ($goods_id as $item) { $goods = Goods::findOne(['store_id' => $store_id, 'id' => $item, 'is_delete' => 0]); if ($goods) { $goods->accessories_image = $accessories_image; if (!$goods->save()) { return [ 'code' => 1, 'msg' => '商品' . $goods->name . '操作失败:' . json_encode($goods->errors, JSON_UNESCAPED_UNICODE) ]; } } } } return [ 'code' => 0, 'msg' => '提交成功' ]; } /** * @return array */ public function list() { $store_id = $this->store_id; $goods_name = $this->goods_name; $status = $this->status; $cat_id = $this->cat_id; //判断商品中智配图片不为空 $query = Goods::find()->alias('g')->where(['g.store_id' => $store_id, 'g.is_delete' => 0])->andWhere(['AND', ['<>', 'g.accessories_image', ''], ['IS NOT', 'g.accessories_image', NULL]]); if ($goods_name) { $query->andWhere(['LIKE', 'g.name', $goods_name]); } if (isset($status) && intval($status) !== -1) { $query->andWhere(['g.status' => $status]); } if ($cat_id) { $query->leftJoin(['gc' => GoodsCat::tableName()], 'g.id = gc.goods_id')->andWhere([ 'gc.cat_id' => Cat::getCatId($cat_id) ])->groupBy('gc.goods_id'); } $query->select('g.id, g.cover_pic, g.name, g.price, g.status, g.accessories_image')->orderBy('id desc'); $list = pagination_make($query); foreach ($list['list'] as &$item) { $goods_cat = GoodsCat::find()->alias('gc') ->leftJoin(['c' => Cat::tableName()], 'gc.cat_id=c.id') ->where([ 'gc.goods_id' => $item['id'] ]) ->select(['c.name']) ->asArray() ->all(); $item['cat'] = $goods_cat; $item['status'] = (int)$item['status']; } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list['list'], 'pageNo' => $list['pageNo'], 'totalCount' => $list['totalCount'] ] ]; } }