WxappPage.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\model;
  10. use app\common\model\WxappPage as WxappPageModel;
  11. /**
  12. * 微信小程序diy页面模型
  13. * Class WxappPage
  14. * @package app\common\model
  15. */
  16. class WxappPage extends WxappPageModel
  17. {
  18. /**
  19. * 获取列表
  20. * @return false|\PDOStatement|string|\think\Collection
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. * @throws \think\exception\DbException
  24. */
  25. public function getList()
  26. {
  27. return $this->where(['is_delete' => 0])->order(['create_time' => 'desc'])->select();
  28. }
  29. /**
  30. * 新增页面
  31. * @param $data
  32. * @return bool
  33. */
  34. public function add($data)
  35. {
  36. // 删除wxapp缓存
  37. Wxapp::deleteCache();
  38. return $this->save([
  39. 'page_type' => 20,
  40. 'page_name' => $data['page']['params']['name'],
  41. 'page_data' => $data,
  42. 'wxapp_id' => self::$wxapp_id
  43. ]);
  44. }
  45. /**
  46. * 更新页面
  47. * @param $data
  48. * @return bool
  49. */
  50. public function edit($data)
  51. {
  52. // 删除wxapp缓存
  53. Wxapp::deleteCache();
  54. // 保存数据
  55. return $this->save([
  56. 'page_name' => $data['page']['params']['name'],
  57. 'page_data' => $data
  58. ]) !== false;
  59. }
  60. /**
  61. * 删除记录
  62. * @return int
  63. */
  64. public function setDelete()
  65. {
  66. if ($this['page_type'] == 10) {
  67. $this->error = '默认首页不可以删除';
  68. return false;
  69. }
  70. // 删除wxapp缓存
  71. Wxapp::deleteCache();
  72. return $this->save(['is_delete' => 1]);
  73. }
  74. /**
  75. * 设为默认首页
  76. * @return int
  77. */
  78. public function setHome()
  79. {
  80. // 取消原默认首页
  81. $this->where(['page_type' => 10])->update(['page_type' => 20]);
  82. // 删除wxapp缓存
  83. Wxapp::deleteCache();
  84. return $this->save(['page_type' => 10]);
  85. }
  86. }