store_decoration.model.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * 店铺装修模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class store_decorationModel extends Model {
  11. //装修块布局数组
  12. private $block_layout_array = array('block_1');
  13. //装修块类型数组
  14. private $block_type_array = array('html', 'slide', 'hot_area', 'goods');
  15. public function __construct(){
  16. parent::__construct('store_decoration');
  17. }
  18. /**
  19. * 列表
  20. *
  21. * @param array $condition 查询条件
  22. * @return array
  23. */
  24. public function getStoreDecorationList($condition) {
  25. $list = $this->table('store_decoration')->where($condition)->select();
  26. return $list;
  27. }
  28. /**
  29. * 查询基本数据
  30. *
  31. * @param array $condition 查询条件
  32. * @param int $store_id 店铺编号
  33. * @return array
  34. */
  35. public function getStoreDecorationInfo($condition, $store_id = null) {
  36. $info = $this->table('store_decoration')->where($condition)->find();
  37. //如果提供了$store_id,验证是否符合,不符合返回false
  38. if($store_id !== null) {
  39. if($info['store_id'] != $store_id) {
  40. return false;
  41. }
  42. }
  43. return $info;
  44. }
  45. /**
  46. * 获取完整装修数据
  47. *
  48. * @param array $decoration_id 装修编号
  49. * @param int $store_id 店铺编号
  50. * @return array
  51. */
  52. public function getStoreDecorationInfoDetail($decoration_id, $store_id) {
  53. if($decoration_id <= 0) {
  54. return false;
  55. }
  56. $condition = array();
  57. $condition['decoration_id'] = $decoration_id;
  58. $condition['store_id'] = $store_id;
  59. $store_decoration_info = $this->getStoreDecorationInfo($condition);
  60. if(!empty($store_decoration_info)) {
  61. $data = array();
  62. //处理装修背景设置
  63. $decoration_setting = array();
  64. if(empty($store_decoration_info['decoration_setting'])) {
  65. $decoration_setting['background_color'] = '';
  66. $decoration_setting['background_image'] = '';
  67. $decoration_setting['background_image_url'] = '';
  68. $decoration_setting['background_image_repeat'] = '';
  69. $decoration_setting['background_position_x'] = '';
  70. $decoration_setting['background_position_y'] = '';
  71. $decoration_setting['background_attachment'] = '';
  72. } else {
  73. $setting = unserialize($store_decoration_info['decoration_setting']);
  74. $decoration_setting['background_color'] = $setting['background_color'];
  75. $decoration_setting['background_image'] = $setting['background_image'];
  76. $decoration_setting['background_image_url'] = getStoreDecorationImageUrl($setting['background_image'], $store_id);
  77. $decoration_setting['background_image_repeat'] = $setting['background_image_repeat'];
  78. $decoration_setting['background_position_x'] = $setting['background_position_x'];
  79. $decoration_setting['background_position_y'] = $setting['background_position_y'];
  80. $decoration_setting['background_attachment'] = $setting['background_attachment'];
  81. }
  82. $data['decoration_setting'] = $decoration_setting;
  83. //处理块列表
  84. $block_list = array();
  85. $block_list = $this->getStoreDecorationBlockList(array('decoration_id' => $decoration_id));
  86. $data['block_list'] = $block_list;
  87. //处理导航条样式
  88. $data['decoration_nav'] = unserialize($store_decoration_info['decoration_nav']);
  89. //处理banner
  90. $decoration_banner = unserialize($store_decoration_info['decoration_banner']);
  91. $decoration_banner['image_url'] = getStoreDecorationImageUrl($decoration_banner['image'], $store_id);
  92. $data['decoration_banner'] = $decoration_banner;
  93. return $data;
  94. } else {
  95. return false;
  96. }
  97. }
  98. /**
  99. * 生成装修背景样式规则
  100. *
  101. * @param array $decoration_setting 样式规则数组
  102. * @return string 样式规则
  103. */
  104. public function getDecorationBackgroundStyle($decoration_setting) {
  105. $decoration_background_style = '';
  106. if($decoration_setting['background_color'] != '') {
  107. $decoration_background_style .= 'background-color: ' . $decoration_setting['background_color'] . ';';
  108. }
  109. if($decoration_setting['background_image'] != '') {
  110. $decoration_background_style .= 'background-image: url(' . $decoration_setting['background_image_url'] . ');';
  111. }
  112. if($decoration_setting['background_image_repeat'] != '') {
  113. $decoration_background_style .= 'background-repeat: ' . $decoration_setting['background_image_repeat'] . ';';
  114. }
  115. if($decoration_setting['background_position_x'] != '' || $decoration_setting['background_position_y'] != '') {
  116. $decoration_background_style .= 'background-position: ' . $decoration_setting['background_position_x'] . ' ' . $decoration_setting['background_position_y'] . ';';
  117. }
  118. if($decoration_setting['background_attachment'] != '') {
  119. $decoration_background_style .= 'background-attachment: ' . $decoration_setting['background_attachment'] .';';
  120. }
  121. return $decoration_background_style;
  122. }
  123. /*
  124. * 添加
  125. *
  126. * @param array $param 信息
  127. * @return bool
  128. */
  129. public function addStoreDecoration($param){
  130. return $this->table('store_decoration')->insert($param);
  131. }
  132. /*
  133. * 编辑
  134. *
  135. * @param array $update 更新信息
  136. * @param array $condition 条件
  137. * @return bool
  138. */
  139. public function editStoreDecoration($update, $condition){
  140. return $this->table('store_decoration')->where($condition)->update($update);
  141. }
  142. /**
  143. * 查询装修块列表
  144. *
  145. * @param array $condition 查询条件
  146. * @return array
  147. */
  148. public function getStoreDecorationBlockList($condition) {
  149. $list = $this->table('store_decoration_block')->where($condition)->order('block_sort asc')->select();
  150. foreach ($list as $key => $value) {
  151. $list[$key]['block_content'] = str_replace("\r", "", $value['block_content']);
  152. $list[$key]['block_content'] = str_replace("\n", "", $value['block_content']);
  153. }
  154. return $list;
  155. }
  156. /**
  157. * 查询装修块信息
  158. *
  159. * @param array $condition 查询条件
  160. * @param int $store_id 店铺编号
  161. * @return array
  162. */
  163. public function getStoreDecorationBlockInfo($condition, $store_id = null) {
  164. $info = $this->table('store_decoration_block')->where($condition)->find();
  165. //如果提供了$store_id,验证是否符合
  166. if($store_id !== null) {
  167. if($info['store_id'] != $store_id) {
  168. return false;
  169. }
  170. }
  171. return $info;
  172. }
  173. /*
  174. * 添加装修块
  175. *
  176. * @param array $param 信息
  177. * @return bool
  178. */
  179. public function addStoreDecorationBlock($param){
  180. return $this->table('store_decoration_block')->insert($param);
  181. }
  182. /*
  183. * 编辑装修块
  184. *
  185. * @param array $update 更新信息
  186. * @param array $condition 条件
  187. * @return bool
  188. */
  189. public function editStoreDecorationBlock($update, $condition){
  190. return $this->table('store_decoration_block')->where($condition)->update($update);
  191. }
  192. /*
  193. * 删除装修块
  194. *
  195. * @param array $condition 条件
  196. * @return bool
  197. */
  198. public function delStoreDecorationBlock($condition){
  199. return $this->table('store_decoration_block')->where($condition)->delete();
  200. }
  201. /**
  202. * 返回装修块布局数组
  203. */
  204. public function getStoreDecorationBlockLayoutArray() {
  205. return $this->block_layout_array;
  206. }
  207. /**
  208. * 返回装修块模块类型数组
  209. */
  210. public function getStoreDecorationBlockTypeArray() {
  211. return $this->block_type_array;
  212. }
  213. }