CommonOverRun.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\models\common;
  8. use app\models\Option;
  9. use yii\base\Model;
  10. use yii\helpers\Json;
  11. class CommonOverRun extends Model
  12. {
  13. public $max_picture;
  14. public $max_diy;
  15. public $over_picture;
  16. public $over_diy;
  17. public $max_file;
  18. public $over_file;
  19. public function rules()
  20. {
  21. return [
  22. [['max_file'], 'integer', 'min' => 0],
  23. [['over_diy'], 'integer', 'min' => 0],
  24. [['over_file'], 'integer', 'min' => 0],
  25. [['max_picture'], 'number', 'min' => 0],
  26. [['over_picture', 'over_diy'], 'default', 'value' => 0],
  27. [['max_picture'], 'default', 'value' => 1],
  28. [['max_diy'], 'default', 'value' => 20],
  29. ];
  30. }
  31. /**
  32. * @return array
  33. * @throws \yii\db\Exception
  34. */
  35. public function save()
  36. {
  37. if (!$this->validate()) {
  38. return [
  39. 'code' => 1,
  40. 'msg' => $this->getErrorSummary(false)[0]
  41. ];
  42. }
  43. if (!isset($this->max_file)) {
  44. $this->max_file = $this->max_picture;
  45. }
  46. Option::set('overrun', Json::encode([
  47. 'max_picture' => $this->max_picture,
  48. 'max_diy' => $this->max_diy,
  49. 'max_file' => $this->max_file,
  50. 'over_picture' => $this->over_picture,
  51. 'over_diy' => $this->over_diy,
  52. 'over_file' => $this->over_file,
  53. ]), get_store_id(), 'store');
  54. return [
  55. 'code' => 0,
  56. 'msg' => '保存成功'
  57. ];
  58. }
  59. public function search()
  60. {
  61. $data = Option::get('overrun', get_store_id(), 'store')['value'];
  62. $data = Json::decode($data);
  63. if (!$data) {
  64. $data = [
  65. 'max_picture' => 1,
  66. 'max_diy' => 20,
  67. 'max_file' => 20,
  68. 'over_picture' => 0,
  69. 'over_diy' => 0,
  70. 'over_file' => 0,
  71. ];
  72. }
  73. if (!isset($data['max_file'])) {
  74. $data['max_file'] = $data['max_picture'];
  75. }
  76. if (!isset($data['over_file'])) {
  77. $data['over_file'] = $data['over_picture'];
  78. }
  79. return [
  80. 'code' => 0,
  81. 'msg' => '',
  82. 'data' => $data
  83. ];
  84. }
  85. }