StoreReserveSetting.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_reserve_setting".
  8. *
  9. * @property int $id ID
  10. * @property int $mall_id 商城ID
  11. * @property int $store_id 门店id
  12. * @property string|null $setting
  13. * @property int $status 状态0禁用,-1删除,1正常
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 更新时间
  16. */
  17. class StoreReserveSetting extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_store_reserve_setting}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id'], 'required'],
  33. [['mall_id', 'store_id', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['setting'], 'string'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => 'Mall ID',
  45. 'store_id' => 'Store ID',
  46. 'setting' => 'Setting',
  47. 'status' => 'Status',
  48. 'created_at' => 'Created At',
  49. 'updated_at' => 'Updated At',
  50. ];
  51. }
  52. public static function setData($params)
  53. {
  54. try {
  55. $where = ['store_id' => $params['store_id'], 'status' => StatusEnum::ENABLED];
  56. $model = self::findOne($where);
  57. if (empty($model)){
  58. $model = new self();
  59. $model->loadDefaultValues();
  60. $model->store_id = $params['store_id'];
  61. $model->mall_id = $params['mall_id'];
  62. }
  63. $params['setting'] = json_encode($params['setting'],JSON_UNESCAPED_UNICODE);
  64. if (!$model->load($params, '') || !$model->save()) {
  65. throw new \Exception($model->getErrorMessage());
  66. }
  67. return $model;
  68. } catch (\Exception $e) {
  69. self::$static_error = $e->getMessage();
  70. return false;
  71. }
  72. }
  73. }