WechatVideoShop.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace addons\WechatVideoShop\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\common\Region;
  5. use Yii;
  6. /**
  7. * This is the model class for table "{{%addons_wechat_video_shop}}".
  8. *
  9. * @property int $id ID
  10. * @property int $mall_id 商城ID
  11. * @property string $name 店铺名称
  12. * @property string $wechat_appid 微信视频小店APPID
  13. * @property string $wechat_secret 微信视频小店密钥
  14. * @property string $wechat_token 微信视频小店消息推送令牌(Token)
  15. * @property string $wechat_aes_key 微信视频小店消息加密密钥
  16. * @property int $status 状态[-1删除;0禁用;1正常]
  17. * @property int $created_at 创建时间
  18. * @property int $updated_at 更新时间
  19. * @property int $province_id 更新时间
  20. * @property int $city_id 更新时间
  21. * @property int $district_id 更新时间
  22. * @property int $is_auto_down_up_goods 更新时间
  23. * @property string $district 更新时间
  24. * @property string $province 更新时间
  25. * @property string $city 更新时间
  26. * @property string $contact_person 更新时间
  27. * @property string $phone 更新时间
  28. * @property string $address 更新时间
  29. * @property string $logo 更新时间
  30. * @property string $third_status 更新时间
  31. * @property int $is_auth 更新时间
  32. */
  33. class WechatVideoShop extends \common\models\base\BaseActiveRecord
  34. {
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public static function tableName()
  39. {
  40. return '{{%addons_wechat_video_shop}}';
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function rules()
  46. {
  47. return [
  48. [['mall_id', 'status', 'created_at', 'updated_at', 'province_id', 'city_id', 'district_id',
  49. 'is_auto_down_up_goods', 'is_auth'], 'integer'],
  50. [['name'], 'string', 'max' => 64],
  51. [['province', 'city', 'district'], 'string', 'max' => 50],
  52. [['address', 'logo'], 'string', 'max' => 255],
  53. [['contact_person'], 'string', 'max' => 30],
  54. [['phone'], 'string', 'max' => 13],
  55. [['third_status'], 'string', 'max' => 20],
  56. [['wechat_appid', 'wechat_secret', 'wechat_token', 'wechat_aes_key'], 'string', 'max' => 128],
  57. ];
  58. }
  59. /**
  60. * {@inheritdoc}
  61. */
  62. public function attributeLabels()
  63. {
  64. return [
  65. 'id' => 'ID',
  66. 'mall_id' => '商城ID',
  67. 'name' => '店铺名称',
  68. 'wechat_appid' => '微信视频小店APPID',
  69. 'wechat_secret' => '微信视频小店密钥',
  70. 'wechat_token' => '微信视频小店消息推送令牌(Token)',
  71. 'wechat_aes_key' => '微信视频小店消息加密密钥',
  72. 'status' => '状态[-1删除;0禁用;1正常]',
  73. 'created_at' => '创建时间',
  74. 'updated_at' => '更新时间',
  75. ];
  76. }
  77. public static function setData(array $params)
  78. {
  79. try {
  80. if (!empty($params['id'])) {
  81. $model = self::findOne(['and', ['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]]);
  82. if (empty($model)) throw new \Exception('id参数错误');
  83. } else {
  84. $model = new self();
  85. $model->loadDefaultValues();
  86. }
  87. if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
  88. return $model;
  89. } catch (\Exception $e) {
  90. self::setStaticError($e->getMessage());
  91. return false;
  92. }
  93. }
  94. public function getProvinceInfo()
  95. {
  96. return $this->hasOne(Region::class, ['id' => 'province_id']);
  97. }
  98. public function getCityInfo()
  99. {
  100. return $this->hasOne(Region::class, ['id' => 'city_id']);
  101. }
  102. public function getDistrictInfo()
  103. {
  104. return $this->hasOne(Region::class, ['id' => 'district_id']);
  105. }
  106. public function getAddress()
  107. {
  108. return $this->hasOne(WechatVideoShopAddress::class, ['shop_id' => 'id']);
  109. }
  110. }