| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\models;
- use app\modules\admin\models\MerchantForm;
- use yii\behaviors\TimestampBehavior;
- /**
- * Class StoreMedia
- * @package app\models
- * @property integer $id
- * @property integer $store_id
- * @property string $cloud_cat_id
- * @property integer $is_delete
- * @property string $created_at
- * @property string $updated_at
- * @property string $cloud_cat_name
- **/
- class StoreForbiddenDirectory extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%store_forbidden_directory}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [["id", "store_id", "is_delete"], 'integer'],
- [["cloud_cat_id", "created_at", "updated_at", 'cloud_cat_name'], 'string'],
- ];
- }
- public function behaviors()
- {
- return [
- [
- 'class' => 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' => ''
- ];
- }
- }
|