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