AddonsSmartFormSetting.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace addons\SmartForm\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_smart_form_setting".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $is_export 是否开启一键导入功能:0:否;1是
  12. * @property int $agree_on 是否开启协议:0:否;1是
  13. * @property int $status 状态[-1:删除;0:禁用;1启用]
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class AddonsSmartFormSetting extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_smart_form_setting}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id'], 'required'],
  33. [['mall_id', 'is_export', 'agree_on', 'status', 'created_at', 'updated_at'], 'integer'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => '商城ID',
  44. 'is_export' => '是否开启一键导入功能:0:否;1是',
  45. 'agree_on' => '是否开启协议:0:否;1是',
  46. 'status' => '状态[-1:删除;0:禁用;1启用]',
  47. 'created_at' => 'Created At',
  48. 'updated_at' => 'Updated At',
  49. ];
  50. }
  51. /**
  52. * @method setData
  53. * desc
  54. * @author zqh
  55. * @datetime 2022-05-31T14:41:23+0800
  56. */
  57. public static function setData($params)
  58. {
  59. $where['mall_id'] = $params['mall_id'];
  60. $where['status'] = StatusEnum::ENABLED;
  61. # 判断当前标题是否已经存在
  62. $find = self::findOne($where,true);
  63. if($find){
  64. $find->updated_at = time();
  65. $find->is_export = $params['is_export'];
  66. $find->agree_on = $params['agree_on'];
  67. $s = $find->save();
  68. }else {
  69. $tplModel = new self();
  70. $tplModel->loadDefaultValues();
  71. $tplModel->mall_id = $params['mall_id'];
  72. $create['mall_id'] = $params['mall_id'];# 商城id
  73. $create['is_export'] = $params['is_export'];
  74. $create['agree_on'] = $params['agree_on'];
  75. $create['updated_at'] = time();
  76. if(!$tplModel->load($create,'') || !$tplModel->save()){
  77. self::$static_error = $tplModel->getErrorMessage();
  78. return false;
  79. }
  80. }
  81. return true;
  82. }
  83. }