Setting.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\controller;
  10. use app\store\model\Printer as PrinterModel;
  11. use app\store\model\Setting as SettingModel;
  12. use app\common\library\sms\Driver as SmsDriver;
  13. /**
  14. * 系统设置
  15. * Class Setting
  16. * @package app\store\controller
  17. */
  18. class Setting extends Controller
  19. {
  20. /**
  21. * 商城设置
  22. * @return mixed
  23. * @throws \think\exception\DbException
  24. */
  25. public function store()
  26. {
  27. return $this->updateEvent('store');
  28. }
  29. /**
  30. * 交易设置
  31. * @return mixed
  32. * @throws \think\exception\DbException
  33. */
  34. public function trade()
  35. {
  36. return $this->updateEvent('trade');
  37. }
  38. /**
  39. * 短信通知
  40. * @return mixed
  41. * @throws \think\exception\DbException
  42. */
  43. public function sms()
  44. {
  45. return $this->updateEvent('sms');
  46. }
  47. /**
  48. * 模板消息
  49. * @return mixed
  50. * @throws \think\exception\DbException
  51. */
  52. public function tplMsg()
  53. {
  54. return $this->updateEvent('tplMsg');
  55. }
  56. /**
  57. * 发送短信通知测试
  58. * @param $AccessKeyId
  59. * @param $AccessKeySecret
  60. * @param $sign
  61. * @param $msg_type
  62. * @param $template_code
  63. * @param $accept_phone
  64. * @return array
  65. * @throws \think\Exception
  66. */
  67. public function smsTest($AccessKeyId, $AccessKeySecret, $sign, $msg_type, $template_code, $accept_phone)
  68. {
  69. $SmsDriver = new SmsDriver([
  70. 'default' => 'aliyun',
  71. 'engine' => [
  72. 'aliyun' => [
  73. 'AccessKeyId' => $AccessKeyId,
  74. 'AccessKeySecret' => $AccessKeySecret,
  75. 'sign' => $sign,
  76. $msg_type => compact('template_code', 'accept_phone'),
  77. ],
  78. ],
  79. ]);
  80. $templateParams = [];
  81. if ($msg_type === 'order_pay') {
  82. $templateParams = ['order_no' => '2018071200000000'];
  83. }
  84. if ($SmsDriver->sendSms($msg_type, $templateParams, true)) {
  85. return $this->renderSuccess('发送成功');
  86. }
  87. return $this->renderError('发送失败 ' . $SmsDriver->getError());
  88. }
  89. /**
  90. * 上传设置
  91. * @return mixed
  92. * @throws \think\exception\DbException
  93. */
  94. public function storage()
  95. {
  96. return $this->updateEvent('storage');
  97. }
  98. /**
  99. * 小票打印设置
  100. * @return mixed
  101. * @throws \think\exception\DbException
  102. */
  103. public function printer()
  104. {
  105. // 获取打印机列表
  106. $printerList = PrinterModel::getAll();
  107. return $this->updateEvent('printer', compact('printerList'));
  108. }
  109. /**
  110. * 更新商城设置事件
  111. * @param $key
  112. * @param $vars
  113. * @return array|mixed
  114. * @throws \think\exception\DbException
  115. */
  116. private function updateEvent($key, $vars = [])
  117. {
  118. if (!$this->request->isAjax()) {
  119. $vars['values'] = SettingModel::getItem($key);
  120. return $this->fetch($key, $vars);
  121. }
  122. $model = new SettingModel;
  123. if ($model->edit($key, $this->postData($key))) {
  124. return $this->renderSuccess('操作成功');
  125. }
  126. return $this->renderError($model->getError() ?: '操作失败');
  127. }
  128. }