StoreForbiddenDirectory.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\models;
  3. use app\modules\admin\models\MerchantForm;
  4. use yii\behaviors\TimestampBehavior;
  5. /**
  6. * Class StoreMedia
  7. * @package app\models
  8. * @property integer $id
  9. * @property integer $store_id
  10. * @property string $cloud_cat_id
  11. * @property integer $is_delete
  12. * @property string $created_at
  13. * @property string $updated_at
  14. * @property string $cloud_cat_name
  15. **/
  16. class StoreForbiddenDirectory extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * @inheritdoc
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%store_forbidden_directory}}';
  24. }
  25. /**
  26. * @inheritdoc
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [["id", "store_id", "is_delete"], 'integer'],
  32. [["cloud_cat_id", "created_at", "updated_at", 'cloud_cat_name'], 'string'],
  33. ];
  34. }
  35. public function behaviors()
  36. {
  37. return [
  38. [
  39. 'class' => TimestampBehavior::class,
  40. ]
  41. ];
  42. }
  43. public function afterSave($insert, $changedAttributes)
  44. {
  45. parent::afterSave($insert, $changedAttributes);
  46. $store_id = $this->store_id;
  47. $t = \Yii::$app->db->beginTransaction();
  48. try {
  49. $access_token = get_merchant_token(0, $store_id);
  50. if ($access_token) {
  51. if (intval($this->is_delete) === 0) {
  52. $form = new MerchantForm();
  53. $form->store_id = $store_id;
  54. $result = $form->getCloudForbiddenGoods();
  55. if ($result['code'] === 0) {
  56. //先将所有的已禁用商品放开 待云仓返回云仓商品ID后 将对应的云仓商品给禁用
  57. Goods::updateAll(['is_forbidden' => 0, 'is_delete' => 0], ['store_id' => $store_id, 'is_forbidden' => 1]);
  58. $cloud_goods_id = $result['data']['goods_id'];
  59. if (!empty($cloud_goods_id)) {
  60. Goods::updateAll(['is_forbidden' => 1, 'is_delete' => 1], ['store_id' => $store_id, 'is_forbidden' => 0, 'cloud_goods_id' => $cloud_goods_id, 'is_delete' => 0]);
  61. }
  62. }
  63. } else {
  64. //如果已经删除就去掉禁用
  65. Goods::updateAll(['is_forbidden' => 0, 'is_delete' => 0], ['store_id' => $store_id, 'is_forbidden' => 1]);
  66. }
  67. }
  68. $t->commit();
  69. } catch (\Exception $e) {
  70. $t->rollBack();
  71. }
  72. }
  73. /**
  74. * @inheritdoc
  75. */
  76. public function attributeLabels()
  77. {
  78. return [
  79. "id" => "ID",
  80. "store_id" => "商城ID",
  81. "cloud_cat_id" => "云仓分类id",
  82. "is_delete" => "是否删除",
  83. "created_at" => "",
  84. "updated_at" => "",
  85. 'cloud_cat_name' => ''
  86. ];
  87. }
  88. }