Storeplate.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * 店铺模型管理
  4. */
  5. namespace app\common\model;
  6. use think\facade\Db;
  7. /**
  8. * ============================================================================
  9. *
  10. * ============================================================================
  11. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  12. * 网站地址: https://www.valimart.net/
  13. * ----------------------------------------------------------------------------
  14. *
  15. * ============================================================================
  16. * 数据层模型
  17. */
  18. class Storeplate extends BaseModel {
  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. if($pagesize){
  31. $result = Db::name('storeplate')->field($field)->where($condition)->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  32. $this->page_info = $result;
  33. return $result->items();
  34. }else{
  35. return Db::name('storeplate')->field($field)->where($condition)->select()->toArray();
  36. }
  37. }
  38. /**
  39. * 版式详细信息
  40. * @access public
  41. * @author csdeshang
  42. * @param array $condition 条件
  43. * @return array
  44. */
  45. public function getStoreplateInfo($condition) {
  46. return Db::name('storeplate')->where($condition)->find();
  47. }
  48. public function getStoreplateInfoByID($storeplate_id) {
  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. return Db::name('storeplate')->insertGetId($data);
  65. }
  66. /**
  67. * 更新版式
  68. * @access public
  69. * @author csdeshang
  70. * @param array $update 更新数据
  71. * @param array $condition 条件
  72. * @return boolean
  73. */
  74. public function editStoreplate($update, $condition) {
  75. $list = $this->getStoreplateList($condition, 'storeplate_id');
  76. if (empty($list)) {
  77. return true;
  78. }
  79. $result = Db::name('storeplate')->where($condition)->update($update);
  80. if ($result) {
  81. foreach ($list as $val) {
  82. $this->_dStoreplateCache($val['storeplate_id']);
  83. }
  84. }
  85. return $result;
  86. }
  87. /**
  88. * 删除版式
  89. * @access public
  90. * @author csdeshang
  91. * @param array $condition 条件
  92. * @return boolean
  93. */
  94. public function delStoreplate($condition) {
  95. $list = $this->getStoreplateList($condition, 'storeplate_id');
  96. if (empty($list)) {
  97. return true;
  98. }
  99. $result = Db::name('storeplate')->where($condition)->delete();
  100. if ($result) {
  101. foreach ($list as $val) {
  102. $this->_dStoreplateCache($val['storeplate_id']);
  103. }
  104. }
  105. return $result;
  106. }
  107. /**
  108. * 读取店铺关联板式缓存缓存
  109. * @access public
  110. * @author csdeshang
  111. * @param int $storeplate_id 店铺关联版式id
  112. * @return array
  113. */
  114. private function _rStoreplateCache($storeplate_id) {
  115. return rcache($storeplate_id, 'store_plate');
  116. }
  117. /**
  118. * 写入店铺关联板式缓存缓存
  119. * @access public
  120. * @author csdeshang
  121. * @param int $storeplate_id 店铺关联版式id
  122. * @param array $info
  123. * @return boolean
  124. */
  125. private function _wStoreplateCache($storeplate_id, $info) {
  126. return wcache($storeplate_id, $info, 'store_plate');
  127. }
  128. /**
  129. * 删除店铺关联板式缓存缓存
  130. * @access public
  131. * @author csdeshang
  132. * @param int $storeplate_id 店铺关联版式id
  133. * @return boolean
  134. */
  135. private function _dStoreplateCache($storeplate_id) {
  136. return dcache($storeplate_id, 'store_plate');
  137. }
  138. }