id; $store_id = $this->store_id; $goods_id = $this->goods_id; $goods_team_grades = $this->goods_team_grades; $goods = \app\models\Goods::findOne(['id' => $goods_id, 'is_delete' => 0]); if (!$goods) { throw new \Exception('商品不存在'); } $form = TeamGradesGoods::findOne($id); if (!$form) { $form = TeamGradesGoods::findOne(['goods_id' => $goods_id, 'is_delete' => 0]); } $form = $form ?: new TeamGradesGoods(); $form->goods_team_grades = $goods_team_grades; $form->goods_id = $goods_id; $form->store_id = $store_id; if (!$form->save()) { throw new \Exception('商品不存在'); } return [ 'code' => 0, 'msg' => '保存成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function list() { $store_id = $this->store_id; $cat_id = $this->cat_id; $goods_name = $this->goods_name; $query = TeamGradesGoods::find()->alias('tg') ->leftJoin(['g' => Goods::tableName()], 'g.id=tg.goods_id') ->where(['tg.is_delete' => 0, 'tg.store_id' => $store_id, 'g.is_delete' => 0]); if (!empty(trim($goods_name))) { $query->andWhere(['LIKE', 'g.name', trim($goods_name)]); } if (isset($cat_id) && $cat_id > 0) { $query->leftJoin(['gc' => GoodsCat::tableName()], 'g.id = gc.goods_id')->andWhere([ 'gc.cat_id' => Cat::getCatId($cat_id) ])->groupBy('gc.goods_id'); } $query->orderBy('tg.id DESC')->select('tg.id, tg.goods_team_grades, g.id goods_id, g.name, g.cover_pic'); $pagination = pagination_make($query); foreach ($pagination['list'] as &$list) { $goods_cat = GoodsCat::find()->alias('gc') ->leftJoin(['c' => Cat::tableName()], 'gc.cat_id=c.id') ->where([ 'gc.goods_id' => $list['goods_id'], 'c.is_delete' => 0, 'gc.is_delete' => 0, 'c.store_id' => $store_id ]) ->select(['c.name', 'c.id']) ->asArray() ->all(); $list['cat'] = $goods_cat; } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $pagination['list'], 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'], ] ]; } //删除商品业绩分红值 public function del() { try { $ids = $this->ids; $ids = explode(',', $ids); foreach ($ids as $id) { $form = TeamGradesGoods::findOne($id); if (!$form) { throw new \Exception('数据不存在'); } $form->is_delete = 1; if (!$form->save()) { throw new \Exception('删除失败'); } } return [ 'code' => 0, 'msg' => '删除成功' ]; }catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }