WxappPage.php 2.0 KB

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