SettingForm.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * @Author: your name
  9. * @Date: 2021-05-08 17:28:23
  10. * @LastEditTime: 2021-05-19 10:57:22
  11. * @LastEditors: Please set LastEditors
  12. * @Description: In User Settings Edit
  13. * @FilePath: \admin_php\modules\client\models\v1\admin\CatForm.php
  14. */
  15. namespace app\modules\client\models\v1\admin;
  16. use app\constants\OptionSetting;
  17. use app\models\Option;
  18. use yii\base\Model;
  19. use yii\helpers\Json;
  20. class SettingForm extends Model
  21. {
  22. public $store_id = 1;
  23. public function get()
  24. {
  25. $key = [
  26. OptionSetting::STORE_NAME,
  27. OptionSetting::STORE_CONTACT_TEL,
  28. OptionSetting::STORE_DELIVERY_TIME,
  29. OptionSetting::STORE_AFTER_SALE_TIME
  30. ];
  31. $data = Option::get($key,$this->store_id);
  32. $value = [];
  33. foreach ($data as $val) {
  34. $value[$val['name']] = json_decode($val['value']) ?: $val['value'];
  35. }
  36. $value[OptionSetting::STORE_SEND_TYPE] = Option::get(OptionSetting::STORE_SEND_TYPE, $this->store_id, 'pay', Option::get(OptionSetting::STORE_SEND_TYPE, $this->store_id, 'store')['value'])['value'];
  37. $value[OptionSetting::STORE_PAYMENT] = Option::get(OptionSetting::STORE_PAYMENT, $this->store_id, 'pay', Option::get(OptionSetting::STORE_PAYMENT, $this->store_id, 'store')['value'])['value'];
  38. return [
  39. 'code' => 0,
  40. 'data' => $value
  41. ];
  42. }
  43. /**
  44. * 保存分类
  45. * @return array
  46. */
  47. public function save($type, $val)
  48. {
  49. if (empty($type)) {
  50. return [
  51. 'code' => 1,
  52. 'msg' => '参数错误'
  53. ];
  54. }
  55. $res = Option::set($type, $val);
  56. if ($res) {
  57. return [
  58. 'code' => 0,
  59. 'msg' => '保存成功'
  60. ];
  61. } else {
  62. return [
  63. 'code' => 1,
  64. 'msg' => "保存失败"
  65. ];
  66. }
  67. }
  68. }