store_plate.model.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * 店铺模型管理
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class store_plateModel extends Model {
  11. public function __construct(){
  12. parent::__construct('store_plate');
  13. }
  14. /**
  15. * 版式列表
  16. * @param array $condition
  17. * @param string $field
  18. * @param int $page
  19. * @return array
  20. */
  21. public function getStorePlateList($condition, $field = '*', $page = 0) {
  22. return $this->field($field)->where($condition)->page($page)->select();
  23. }
  24. /**
  25. * 版式详细信息
  26. * @param array $condition
  27. * @return array
  28. */
  29. public function getStorePlateInfo($condition) {
  30. return $this->where($condition)->find();
  31. }
  32. public function getStorePlateInfoByID($plate_id, $fields = '*') {
  33. $info = $this->_rStorePlateCache($plate_id, $fields);
  34. if (empty($info)) {
  35. $info = $this->getStorePlateInfo(array('plate_id' => $plate_id));
  36. $this->_wStorePlateCache($plate_id, $info);
  37. }
  38. return $info;
  39. }
  40. /**
  41. * 添加版式
  42. * @param unknown $insert
  43. * @return boolean
  44. */
  45. public function addStorePlate($insert) {
  46. return $this->insert($insert);
  47. }
  48. /**
  49. * 更新版式
  50. * @param array $update
  51. * @param array $condition
  52. * @return boolean
  53. */
  54. public function editStorePlate($update, $condition) {
  55. $list = $this->getStorePlateList($condition, 'plate_id');
  56. if (empty($list)) {
  57. return true;
  58. }
  59. $result = $this->where($condition)->update($update);
  60. if ($result) {
  61. foreach ($list as $val) {
  62. $this->_dStorePlateCache($val['plate_id']);
  63. }
  64. }
  65. return $result;
  66. }
  67. /**
  68. * 删除版式
  69. * @param array $condition
  70. * @return boolean
  71. */
  72. public function delStorePlate($condition) {
  73. $list = $this->getStorePlateList($condition, 'plate_id');
  74. if (empty($list)) {
  75. return true;
  76. }
  77. $result = $this->where($condition)->delete();
  78. if ($result) {
  79. foreach ($list as $val) {
  80. $this->_dStorePlateCache($val['plate_id']);
  81. }
  82. }
  83. return $result;
  84. }
  85. /**
  86. * 读取店铺关联板式缓存缓存
  87. * @param int $plate_id
  88. * @param string $fields
  89. * @return array
  90. */
  91. private function _rStorePlateCache($plate_id, $fields) {
  92. return rcache($plate_id, 'store_plate', $fields);
  93. }
  94. /**
  95. * 写入店铺关联板式缓存缓存
  96. * @param int $plate_id
  97. * @param array $info
  98. * @return boolean
  99. */
  100. private function _wStorePlateCache($plate_id, $info) {
  101. return wcache($plate_id, $info, 'store_plate');
  102. }
  103. /**
  104. * 删除店铺关联板式缓存缓存
  105. * @param int $plate_id
  106. * @return boolean
  107. */
  108. private function _dStorePlateCache($plate_id) {
  109. return dcache($plate_id, 'store_plate');
  110. }
  111. }