'ID', 'mall_id' => 'Mall ID', 'supply_id' => 'Supply ID', 'goods_id' => 'Goods ID', 'middle_goods_id' => 'middle goods id', 'is_delete' => 'Is Delete', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'is_import' => 'Is Import', 'mall_goods_id' => 'Mall Goods ID', 'import_at' => 'Import At', 'import_msg' => 'Import Msg', 'batch_no' => '批次好', ]; } public function goods() { return $this->hasOne(GoodsModel::class, ['id' => 'goods_id']); } /** * 批量插入员工 * @desc * * @param $user_list * * @return int * @throws \yii\db\Exception */ public static function batchAdd($data) { $field = array_keys($data[0]); $value = []; foreach ($data as $item) { $value[] = array_values($item); } $result = \Yii::$app->db->createCommand()->batchInsert(self::tableName(), $field, $value)->execute(); return $result; } public static function getGoodsIds($ids) { return self::find()->select('id,middle_goods_id')->where(['id' => $ids])->asArray()->all(); } public static function findGoodsIds($mall_id, $supply_id, $goods_ids) { return self::find()->select('middle_goods_id')->where(['mall_id' => $mall_id, 'supply_id' => $supply_id, 'middle_goods_id' => $goods_ids])->asArray()->column(); } public static function byGoodsIdFindStorageId($goods_ids) { return self::find()->select('id')->where([ 'middle_goods_id' => $goods_ids, ])->asArray()->column(); } /** * @PostMapping("updateImportStatus") * @Middlewares({ * @Middleware() * }) * @param array $ids * @param int $status 0 未导入 1导入中 2导入成功 * @param string $msg 导入错误信息 */ public static function updateImportStatus(array $ids, $status = 1, $msg = '') { return self::updateAll(['is_import' => $status, 'import_msg' => $msg], ['id' => $ids]); } public static function remove(array $ids, bool $del_goods = true) { $t = Yii::$app->db->beginTransaction(); try { if ($del_goods) { $goods_ids = self::find()->where(['id' => $ids])->select('mall_goods_id')->column(); if (!empty($goods_ids)) { $goods_ids = array_filter($goods_ids, function ($val) { return !empty($val); }); if (!empty($goods_ids)) Goods::updateAll(['status' => StatusEnum::DELETE], ['id' => $goods_ids]); } } self::deleteAll(['id' => $ids]); // 移除商城商品 $t->commit(); return true; } catch (\Exception $e) { $t->rollBack(); \Yii::error(FormatHelper::exception($e, __METHOD__)); return false; } } /** * 获取该供应链下选品数量 * * @param integer $mall_id * @param integer $supply_id * @param boolean $is_import * @return int */ public static function getStorageNumBySupplyId(int $mall_id, int $supply_id, bool $is_import = true) { return static::find()->where([ 'mall_id' => $mall_id, 'supply_id' => $supply_id, 'is_import' => 2, ])->count(); } /** * 获取中台商品ID * * @param integer $mall_id * @param integer $supply_id * @param integer $limit * @param integer $page * @return array */ public static function getMiddleGoodsIdsBySupplyId(int $mall_id, int $supply_id) { return static::find() ->alias('storage') ->leftJoin([ 'goods' => GoodsModel::tableName() ], 'goods.id = storage.goods_id') ->where([ 'storage.mall_id' => $mall_id, 'storage.supply_id' => $supply_id, 'storage.is_import' => 2, 'goods.is_display' => 1, ]) ->select('storage.middle_goods_id') ->column(); } /** * 通过中台商品ids获取主商城商品ids * * @param array $ids * @return array */ public static function getMallGoodIdsByMiddleGoodsIds(array $ids) { return static::find() ->where(['middle_goods_id' => $ids]) ->select('mall_goods_id') ->column(); } /** * 标记删除 * * @param integer $mall_id * @param array $goods_ids * @return boolean */ public static function changeStatusByMidGoodsIds(int $mall_id, array $goods_ids, int $status = 3) { return self::updateAll(['is_import' => $status], ['middle_goods_id' => $goods_ids, 'mall_id' => $mall_id]); } /** * 获取主商城商品id * * @param integer $mall_id * @param integer|array $goods_ids * @return array */ public static function getMallGoodsIds(int $mall_id, $goods_ids) { return static::find() ->where(['mall_id' => $mall_id, 'middle_goods_id' => $goods_ids]) ->select('mall_goods_id') ->column(); } }