Setting.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\store\controller\apps\dealer;
  3. use app\store\controller\Controller;
  4. use app\store\model\dealer\Setting as SettingModel;
  5. use app\store\model\Goods as GoodsModel;
  6. /**
  7. * 分销设置
  8. * Class Setting
  9. * @package app\store\controller\apps\dealer
  10. */
  11. class Setting extends Controller
  12. {
  13. /**
  14. * 分销设置
  15. * @return array|bool|mixed
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. * @throws \think\exception\DbException
  19. * @throws \think\exception\PDOException
  20. */
  21. public function index()
  22. {
  23. if (!$this->request->isAjax()) {
  24. $data = SettingModel::getAll();
  25. // 购买指定商品成为分销商:商品列表
  26. $goodsList = (new GoodsModel)->getListByIds($data['condition']['values']['become__buy_goods_ids']);
  27. return $this->fetch('index', compact('data', 'goodsList'));
  28. }
  29. $model = new SettingModel;
  30. if ($model->edit($this->postData('setting'))) {
  31. return $this->renderSuccess('更新成功');
  32. }
  33. return $this->renderError($model->getError() ?: '更新失败');
  34. }
  35. /**
  36. * 分销海报
  37. * @return array|mixed
  38. * @throws \think\exception\PDOException
  39. */
  40. public function qrcode()
  41. {
  42. if (!$this->request->isAjax()) {
  43. $data = SettingModel::getItem('qrcode');
  44. return $this->fetch('qrcode', [
  45. 'data' => json_encode($data, JSON_UNESCAPED_UNICODE)
  46. ]);
  47. }
  48. $model = new SettingModel;
  49. if ($model->edit(['qrcode' => $this->postData('qrcode')])) {
  50. return $this->renderSuccess('更新成功');
  51. }
  52. return $this->renderError($model->getError() ?: '更新失败');
  53. }
  54. }