StoreSyncExtLog.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\models;
  3. use yii\behaviors\TimestampBehavior;
  4. use yii\db\ActiveRecord;
  5. /**
  6. * Class StoreSync
  7. * @package app\modules\common\models
  8. *
  9. * @property integer $id
  10. * @property integer $from_id
  11. * @property integer $to_id
  12. * @property integer $from_store_id
  13. * @property integer $to_store_id
  14. * @property string $type
  15. * @property integer $created_at
  16. * @property integer $updated_at
  17. */
  18. class StoreSyncExtLog extends ActiveRecord
  19. {
  20. const TYPE_POSTAGE_RULES ='delivery_rules';//配送规则
  21. const TYPE_PRODUCT ='product';//商品
  22. const TYPE_PRODUCT_ATTR_GROUP ='product_attr_group';//商品规格名
  23. const TYPE_PRODUCT_ATTR ='product_attr';//商品规格
  24. const TYPE_PRODUCT_CAT ='product_cat';
  25. const TYPE_PRODUCT_GOODS_CAT ='product_goods_cat';
  26. const TYPE_PRODUCT_GOODS_PIC ='product_goods_pic';
  27. const TYPE_DIY ='diy';
  28. const TYPE_ACTIVITY_CUT_PRICE ='activityCutPrice';
  29. const TYPE_ACTIVITY_CUT_PRICE_GOODS ='activity_cut_price_goods';
  30. const TYPE_ACTIVITY_CUT_PRICE_CAT ='activity_cut_price_cat';
  31. const TYPE_PT ='pintuan';
  32. const TYPE_PT_GOODS ='pintuan_goods';
  33. const TYPE_PT_GOODS_CAT ='pintuan_goods_cat';
  34. const TYPE_SECKILL ='seckill';
  35. const TYPE_SECKILL_GOODS ='seckill_goods';
  36. const TYPE_SHARE_CONFIG ='shareConfig';
  37. const TYPE_SHARE_HOLDER_CONFIG ='shareHolderConfig';
  38. const TYPE_VIDEO_GOODS ='videoGoods';
  39. const TYPE_VIDEO_GOODS_CAT ='video_Goods_Cat';
  40. const TYPE_INTEGRAL_STORE ='integralStore';
  41. const TYPE_INTEGRAL_STORE_CAT = 'integral_store_cat';
  42. const TYPE_WORKER_CONFIG_GOODS ='workerConfig';
  43. const TYPE_WORKER_CONFIG_CAT ='worker_config_cat';
  44. const TYPE_WORKER_CONFIG_GOODS_CAT ='worker_config_goods_cat';
  45. const TYPE_WORKER_CONFIG_LEVEL ='worker_config_level';
  46. const TYPE_BOOKING_GOODS = 'bookingGoods';
  47. const TYPE_BOOKING_GOODS_CAT = 'bookingGoodsCat';
  48. const TYPE_ARTICLE = 'article';
  49. const TYPE_TOPIC = 'topic';
  50. const TYPE_TOPIC_TYPE = 'topic_type';
  51. const TYPE_ARR = [
  52. self::TYPE_PRODUCT,
  53. self::TYPE_PRODUCT_CAT,
  54. self::TYPE_DIY,
  55. self::TYPE_ACTIVITY_CUT_PRICE,
  56. self::TYPE_PT,
  57. self::TYPE_SECKILL,
  58. self::TYPE_SHARE_CONFIG,
  59. self::TYPE_SHARE_HOLDER_CONFIG,
  60. self::TYPE_VIDEO_GOODS,
  61. self::TYPE_INTEGRAL_STORE,
  62. self::TYPE_WORKER_CONFIG_GOODS,
  63. self::TYPE_BOOKING_GOODS,
  64. self::TYPE_ARTICLE,
  65. self::TYPE_TOPIC,
  66. self::TYPE_POSTAGE_RULES
  67. ];
  68. public static function tableName()
  69. {
  70. return '{{%store_sync_ext_log}}';
  71. }
  72. public function behaviors()
  73. {
  74. return [
  75. [
  76. // 自动更新创建和更新时间
  77. 'class' => TimestampBehavior::class,
  78. 'value' => time()
  79. ]
  80. ];
  81. }
  82. public function rules()
  83. {
  84. return [
  85. [['id', 'from_id', 'to_id', 'from_store_id', 'to_store_id'], 'integer'],
  86. [['type'], 'string'],
  87. [['create_at', 'update_at'], 'safe'],
  88. ];
  89. }
  90. public function attributeLabels()
  91. {
  92. return [
  93. 'id' => '',
  94. 'from_id' => '原店铺内容id',
  95. 'to_id' => '新店铺内容id',
  96. 'from_store_id' => '原店铺id',
  97. 'to_store_id' => '新店铺id',
  98. 'type' => '类型 代码中给示例值',
  99. 'created_at' => '',
  100. 'updated_at' => ''
  101. ];
  102. }
  103. public static function handleData($from_store_id, $to_store_id, $from_id, $to_id, $type = self::TYPE_PRODUCT) {
  104. $storeSyncExtLog = self::findOne([
  105. 'from_store_id' => $from_store_id,
  106. 'to_store_id' => $to_store_id,
  107. 'from_id' => $from_id,
  108. 'type' => $type
  109. ]) ?: new self();
  110. $storeSyncExtLog->from_id = $from_id;
  111. $storeSyncExtLog->type = $type;
  112. $storeSyncExtLog->to_id = $to_id;
  113. $storeSyncExtLog->from_store_id = $from_store_id;
  114. $storeSyncExtLog->to_store_id = $to_store_id;
  115. if (!$storeSyncExtLog->save()) {
  116. //debug_log(['storeSyncExtLog' => $storeSyncExtLog->errors], 'goods_job.log');
  117. };
  118. }
  119. }