StoreCommunity.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_store_cate".
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property int $store_id 门店id
  12. * @property int $province_id 省id
  13. * @property int $city_id 市id
  14. * @property int $district_id 区id
  15. * @property int $street_id 街道id
  16. * @property string $community_name 社区名称
  17. * @property int $sort 排序
  18. * @property int $status 状态[0禁用 1启用 -1删除]
  19. * @property int $created_at 创建时间
  20. * @property int $updated_at 修改时间
  21. */
  22. class StoreCommunity extends BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_store_community}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'province_id', 'city_id', 'district_id', 'street_id', 'created_at', 'updated_at','status'], 'integer'],
  38. [['community_name'], 'string', 'max' => 100],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => 'Mall ID',
  49. 'province_id' => '省级ID',
  50. 'city_id' => '市级ID',
  51. 'district_id' => '区级ID',
  52. 'street_id' => '街道ID',
  53. 'community_name' => '社区名称',
  54. 'status' => '是否删除',
  55. 'created_at' => '创建时间',
  56. 'updated_at' => '修改时间',
  57. ];
  58. }
  59. /**
  60. * @desc:保存数据
  61. * @Author: hua
  62. * @Date: 2024/08/21
  63. * @Time: 18:07
  64. * @Copyright: copyright (c) 2021 广东七件事集团
  65. * @param array $params
  66. * @return StoreClerk|false|null
  67. */
  68. public static function setData(array $params)
  69. {
  70. try {
  71. if (!empty($params['mall_id']) && !empty($params['user_id'])) {
  72. $model = self::findOne(['mall_id' => $params['mall_id'],'province_id' => $params['province_id'], 'city_id'=>$params['city_id'],'district_id' => $params['district_id'], 'street_id' => $params['street_id'],'community_name'=>$params['community_name'],'status' => 0]);
  73. if (empty($model)) {
  74. $model = new self();
  75. $model->loadDefaultValues();
  76. }
  77. } else {
  78. $model = new self();
  79. $model->loadDefaultValues();
  80. }
  81. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  82. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  83. return $model;
  84. } catch (\Exception $e) {
  85. self::$static_error = $e->getMessage();
  86. return false;
  87. }
  88. }
  89. }