StoreModel.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_model".
  8. *
  9. * @property int $id
  10. * @property int $mall_id
  11. * @property int $store_id
  12. * @property string|null $content 内容
  13. * @property int $status 状态[0禁用 1启用 -1删除]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 修改时间
  16. */
  17. class StoreModel extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_store_model}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'store_id', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['content'], 'string'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => 'Mall ID',
  44. 'store_id' => 'Store ID',
  45. 'content' => '内容',
  46. 'status' => '状态[0禁用 1启用 -1删除]',
  47. 'created_at' => '创建时间',
  48. 'updated_at' => '修改时间',
  49. ];
  50. }
  51. public static function setData(array $params)
  52. {
  53. try {
  54. if (!empty($params['mall_id'])&&!empty($params['store_id'])) {
  55. $model = self::findOne(['mall_id' => $params['mall_id'], 'store_id' => $params['store_id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
  56. if (empty($model)) {
  57. $model = new self();
  58. $model->loadDefaultValues();
  59. }
  60. } else {
  61. $model = new self();
  62. $model->loadDefaultValues();
  63. }
  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() . $e->getLine() . $e->getFile();
  70. return false;
  71. }
  72. }
  73. }