Storeplate.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * 店铺模型管理
  4. */
  5. namespace app\common\model;
  6. use think\facade\Db;
  7. /**
  8. *
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * 数据层模型
  13. */
  14. class Storeplate extends BaseModel
  15. {
  16. public $page_info;
  17. /**
  18. * 版式列表
  19. * @access public
  20. * @author csdeshang
  21. * @param array $condition 条件
  22. * @param string $field 字段
  23. * @param int $pagesize 分页
  24. * @return array
  25. */
  26. public function getStoreplateList($condition, $field = '*', $pagesize = 0)
  27. {
  28. if ($pagesize) {
  29. $result = Db::name('storeplate')->field($field)->where($condition)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  30. $this->page_info = $result;
  31. return $result->items();
  32. } else {
  33. return Db::name('storeplate')->field($field)->where($condition)->select()->toArray();
  34. }
  35. }
  36. /**
  37. * 版式详细信息
  38. * @access public
  39. * @author csdeshang
  40. * @param array $condition 条件
  41. * @return array
  42. */
  43. public function getStoreplateInfo($condition)
  44. {
  45. return Db::name('storeplate')->where($condition)->find();
  46. }
  47. public function getStoreplateInfoByID($storeplate_id)
  48. {
  49. $info = $this->_rStoreplateCache($storeplate_id);
  50. if (empty($info)) {
  51. $info = $this->getStoreplateInfo(array('storeplate_id' => $storeplate_id));
  52. $this->_wStoreplateCache($storeplate_id, $info);
  53. }
  54. return $info;
  55. }
  56. /**
  57. * 添加版式
  58. * @access public
  59. * @author csdeshang
  60. * @param array $data 参数内容
  61. * @return boolean
  62. */
  63. public function addStoreplate($data)
  64. {
  65. return Db::name('storeplate')->insertGetId($data);
  66. }
  67. /**
  68. * 更新版式
  69. * @access public
  70. * @author csdeshang
  71. * @param array $update 更新数据
  72. * @param array $condition 条件
  73. * @return boolean
  74. */
  75. public function editStoreplate($update, $condition)
  76. {
  77. $list = $this->getStoreplateList($condition, 'storeplate_id');
  78. if (empty($list)) {
  79. return true;
  80. }
  81. $result = Db::name('storeplate')->where($condition)->update($update);
  82. if ($result) {
  83. foreach ($list as $val) {
  84. $this->_dStoreplateCache($val['storeplate_id']);
  85. }
  86. }
  87. return $result;
  88. }
  89. /**
  90. * 删除版式
  91. * @access public
  92. * @author csdeshang
  93. * @param array $condition 条件
  94. * @return boolean
  95. */
  96. public function delStoreplate($condition)
  97. {
  98. $list = $this->getStoreplateList($condition, 'storeplate_id');
  99. if (empty($list)) {
  100. return true;
  101. }
  102. $result = Db::name('storeplate')->where($condition)->delete();
  103. if ($result) {
  104. foreach ($list as $val) {
  105. $this->_dStoreplateCache($val['storeplate_id']);
  106. }
  107. }
  108. return $result;
  109. }
  110. /**
  111. * 读取店铺关联板式缓存缓存
  112. * @access public
  113. * @author csdeshang
  114. * @param int $storeplate_id 店铺关联版式id
  115. * @return array
  116. */
  117. private function _rStoreplateCache($storeplate_id)
  118. {
  119. return rcache($storeplate_id, 'store_plate');
  120. }
  121. /**
  122. * 写入店铺关联板式缓存缓存
  123. * @access public
  124. * @author csdeshang
  125. * @param int $storeplate_id 店铺关联版式id
  126. * @param array $info
  127. * @return boolean
  128. */
  129. private function _wStoreplateCache($storeplate_id, $info)
  130. {
  131. return wcache($storeplate_id, $info, 'store_plate');
  132. }
  133. /**
  134. * 删除店铺关联板式缓存缓存
  135. * @access public
  136. * @author csdeshang
  137. * @param int $storeplate_id 店铺关联版式id
  138. * @return boolean
  139. */
  140. private function _dStoreplateCache($storeplate_id)
  141. {
  142. return dcache($storeplate_id, 'store_plate');
  143. }
  144. }