TimestampBehavior::class, ] ]; } public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); $store_id = $this->store_id; $t = \Yii::$app->db->beginTransaction(); try { $access_token = get_merchant_token(0, $store_id); if ($access_token) { if (intval($this->is_delete) === 0) { $form = new MerchantForm(); $form->store_id = $store_id; $result = $form->getCloudForbiddenGoods(); if ($result['code'] === 0) { //先将所有的已禁用商品放开 待云仓返回云仓商品ID后 将对应的云仓商品给禁用 Goods::updateAll(['is_forbidden' => 0, 'is_delete' => 0], ['store_id' => $store_id, 'is_forbidden' => 1]); $cloud_goods_id = $result['data']['goods_id']; if (!empty($cloud_goods_id)) { Goods::updateAll(['is_forbidden' => 1, 'is_delete' => 1], ['store_id' => $store_id, 'is_forbidden' => 0, 'cloud_goods_id' => $cloud_goods_id, 'is_delete' => 0]); } } } else { //如果已经删除就去掉禁用 Goods::updateAll(['is_forbidden' => 0, 'is_delete' => 0], ['store_id' => $store_id, 'is_forbidden' => 1]); } } $t->commit(); } catch (\Exception $e) { $t->rollBack(); } } /** * @inheritdoc */ public function attributeLabels() { return [ "id" => "ID", "store_id" => "商城ID", "cloud_cat_id" => "云仓分类id", "is_delete" => "是否删除", "created_at" => "", "updated_at" => "", 'cloud_cat_name' => '' ]; } }