SpecialModel.class.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Model;
  15. use Think\Model;
  16. class SpecialModel extends Model{
  17. protected $tableName ='mb_special';
  18. public function show_special_page($search = array()){
  19. $sql='SELECT * FROM '.C('DB_PREFIX').'mb_special ';
  20. $count=count(M()->query($sql));
  21. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  22. $show = $Page->show();// 分页显示输出
  23. $sql.=' order by special_id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  24. $list=M()->query($sql);
  25. foreach ($list as $key => $value) {
  26. $value['image']=resize($value['special_bgimage'], 100, 100);
  27. $list[$key]= $value;
  28. }
  29. return array(
  30. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  31. 'list'=>$list,
  32. 'page'=>$show
  33. );
  34. }
  35. /**
  36. * 编辑专题项目启用状态
  37. * @param string usable-启用/unsable-不启用
  38. * @param int $item_id
  39. * @param int $special_id
  40. *
  41. */
  42. public function editMbSpecialItemUsableByID($usable, $item_id, $special_id) {
  43. $update = array();
  44. if($usable == 'usable') {
  45. $update['item_usable'] = 1;
  46. } else {
  47. $update['item_usable'] = 0;
  48. }
  49. return $this->editMbSpecialItemByID($update, $item_id, $special_id);
  50. }
  51. /**
  52. * 编辑专题项目
  53. * @param array $update
  54. * @param int $item_id
  55. * @param int $special_id
  56. * @return bool
  57. *
  58. */
  59. public function editMbSpecialItemByID($update, $item_id, $special_id) {
  60. if(isset($update['item_data'])) {
  61. $update['item_data'] = serialize($update['item_data']);
  62. }
  63. $condition = array();
  64. $condition['item_id'] = $item_id;
  65. return M('mb_special_item')->where($condition)->save($update);
  66. }
  67. /**
  68. * 获取项目详细信息
  69. * @param int $item_id
  70. *
  71. */
  72. public function getMbSpecialItemInfoByID($item_id) {
  73. $item_id = intval($item_id);
  74. if($item_id <= 0) {
  75. return false;
  76. }
  77. $condition = array();
  78. $condition['item_id'] = $item_id;
  79. $item_info = M('mb_special_item')->where($condition)->find();
  80. $item_info['item_data'] = $this->_initMbSpecialItemData($item_info['item_data'], $item_info['item_type']);
  81. return $item_info;
  82. }
  83. /**
  84. * 整理项目内容
  85. *
  86. */
  87. private function _initMbSpecialItemData($item_data, $item_type) {
  88. if(!empty($item_data)) {
  89. $item_data = unserialize($item_data);
  90. if($item_type == 'goods') {
  91. $item_data = $this->_initMbSpecialItemGoodsData($item_data, $item_type);
  92. }
  93. } else {
  94. $item_data = $this->_initMbSpecialItemNullData($item_type);
  95. }
  96. return $item_data;
  97. }
  98. /**
  99. * 处理goods类型内容
  100. */
  101. private function _initMbSpecialItemGoodsData($item_data, $item_type) {
  102. $goods_id_string = '';
  103. if(!empty($item_data['item'])) {
  104. foreach ($item_data['item'] as $value) {
  105. $goods_id_string .= $value . ',';
  106. }
  107. $goods_id_string = rtrim($goods_id_string, ',');
  108. //查询商品信息
  109. $condition['goods_id'] = array('in', $goods_id_string);
  110. $model_goods = M('goods');
  111. $goods_list = $model_goods->where($condition)->select();
  112. $goods_list = array_under_reset($goods_list, 'goods_id');
  113. //整理商品数据
  114. $new_goods_list = array();
  115. foreach ($item_data['item'] as $value) {
  116. if(!empty($goods_list[$value])) {
  117. $new_goods_list[] = $goods_list[$value];
  118. }
  119. }
  120. $item_data['item'] = $new_goods_list;
  121. }
  122. return $item_data;
  123. }
  124. /**
  125. * 初始化空项目内容
  126. */
  127. private function _initMbSpecialItemNullData($item_type) {
  128. $item_data = array();
  129. switch ($item_type) {
  130. case 'home1':
  131. $item_data = array(
  132. 'title' => '',
  133. 'image' => '',
  134. 'type' => '',
  135. 'data' => '',
  136. );
  137. break;
  138. case 'home2':
  139. case 'home4':
  140. $item_data= array(
  141. 'title' => '',
  142. 'square_image' => '',
  143. 'square_type' => '',
  144. 'square_data' => '',
  145. 'rectangle1_image' => '',
  146. 'rectangle1_type' => '',
  147. 'rectangle1_data' => '',
  148. 'rectangle2_image' => '',
  149. 'rectangle2_type' => '',
  150. 'rectangle2_data' => '',
  151. );
  152. break;
  153. default:
  154. }
  155. return $item_data;
  156. }
  157. /*
  158. * 删除
  159. * @param array $condition
  160. * @return bool
  161. *
  162. */
  163. public function delMbSpecialItem($condition, $special_id) {
  164. return M('mb_special_item')->where($condition)->delete();
  165. }
  166. /**
  167. * 获取专题模块类型列表
  168. * @return array
  169. *
  170. */
  171. public function getMbSpecialModuleList() {
  172. $module_list = array();
  173. $module_list['adv_list'] = array('name' => 'adv_list' , 'desc' => '广告条版块');
  174. $module_list['home1'] = array('name' => 'home1' , 'desc' => '模型版块布局A');
  175. $module_list['home2'] = array('name' => 'home2' , 'desc' => '模型版块布局B');
  176. $module_list['home3'] = array('name' => 'home3' , 'desc' => '模型版块布局C');
  177. $module_list['home4'] = array('name' => 'home4' , 'desc' => '模型版块布局D');
  178. $module_list['goods'] = array('name' => 'goods' , 'desc' => '商品版块');
  179. return $module_list;
  180. }
  181. public function addMbSpecialItem($param) {
  182. $param['item_usable'] = 0;
  183. $param['item_sort'] = 255;
  184. $result = M('mb_special_item')->add($param);
  185. //删除缓存
  186. if($result) {
  187. $param['item_id'] = $result;
  188. return $param;
  189. } else {
  190. return false;
  191. }
  192. }
  193. public function isMbSpecialItemExist($condition) {
  194. $item_list = M('mb_special_item')->where($condition)->select();
  195. if($item_list) {
  196. return true;
  197. } else {
  198. return false;
  199. }
  200. }
  201. /**
  202. * 专题项目列表(用于后台编辑显示所有项目)
  203. * @param int $special_id
  204. *
  205. */
  206. public function getMbSpecialItemListByID($special_id) {
  207. $condition = array();
  208. $condition['special_id'] = $special_id;
  209. return $this->_getMbSpecialItemList($condition);
  210. }
  211. /**
  212. * 查询专题项目列表
  213. */
  214. private function _getMbSpecialItemList($condition, $order = 'item_sort asc') {
  215. $item_list = M('mb_special_item')->where($condition)->order($order)->select();
  216. foreach ($item_list as $key => $value) {
  217. $item_list[$key]['item_data'] = $this->_initMbSpecialItemData($value['item_data'], $value['item_type']);
  218. if($value['item_usable'] == 1) {
  219. $item_list[$key]['usable_class'] = 'usable';
  220. $item_list[$key]['usable_text'] = '禁用';
  221. } else {
  222. $item_list[$key]['usable_class'] = 'unusable';
  223. $item_list[$key]['usable_text'] = '启用';
  224. }
  225. }
  226. return $item_list;
  227. }
  228. public function edit_special($data){
  229. $special_id=$data['special_id'];
  230. $special = array();
  231. $special['special_id']=$special_id;
  232. $special['special_desc'] = $data['special_desc'];
  233. $special['share_title'] = $data['share_title'];
  234. $special['share_descript'] = $data['share_descript'];
  235. $special['share_image'] = $data['share_image'];
  236. $special['special_bgcolor'] = $data['special_bgcolor'];
  237. $special['special_bgimage'] = $data['image'];
  238. $r=M('mb_special')->save($special);
  239. if($r){
  240. return array(
  241. 'status'=>'success',
  242. 'message'=>'修改成功',
  243. 'jump'=>U('Special/index')
  244. );
  245. }else{
  246. return array(
  247. 'status'=>'success',
  248. 'message'=>'修改失败',
  249. 'jump'=>U('Special/index')
  250. );
  251. }
  252. }
  253. function add_special($data){
  254. if(empty($data['special_desc']))
  255. {
  256. return array(
  257. 'status'=>'fail',
  258. 'message'=>'新增失败,专题名称未填写!',
  259. 'jump'=>U('Special/index')
  260. );
  261. } else {
  262. $special = array();
  263. $special['special_desc'] = $data['special_desc'];
  264. $special['special_bgcolor'] = $data['special_bgcolor'];
  265. $special['share_title'] = $data['share_title'];
  266. $special['share_descript'] = $data['share_descript'];
  267. $special['share_image'] = $data['share_image'];
  268. $special['special_bgimage'] = $data['image'];
  269. $special_id=M('mb_special')->add($special);
  270. if($special_id){
  271. return array(
  272. 'status'=>'success',
  273. 'message'=>'新增成功',
  274. 'jump'=>U('Special/index')
  275. );
  276. }else{
  277. return array(
  278. 'status'=>'fail',
  279. 'message'=>'新增失败',
  280. 'jump'=>U('Special/index')
  281. );
  282. }
  283. }
  284. }
  285. }
  286. ?>