help.model.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. /**
  3. * 帮助模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class helpModel extends Model{
  11. public function __construct() {
  12. parent::__construct();
  13. }
  14. /**
  15. * 增加帮助类型
  16. *
  17. * @param
  18. * @return int
  19. */
  20. public function addHelpType($type_array) {
  21. $type_id = $this->table('help_type')->insert($type_array);
  22. return $type_id;
  23. }
  24. /**
  25. * 增加帮助
  26. *
  27. * @param
  28. * @return int
  29. */
  30. public function addHelp($help_array, $upload_ids = array()) {
  31. $help_id = $this->table('help')->insert($help_array);
  32. if ($help_id && !empty($upload_ids)) {
  33. $this->editHelpPic($help_id, $upload_ids);//更新帮助图片
  34. }
  35. return $help_id;
  36. }
  37. /**
  38. * 删除帮助类型记录
  39. *
  40. * @param
  41. * @return bool
  42. */
  43. public function delHelpType($condition) {
  44. if (empty($condition)) {
  45. return false;
  46. } else {
  47. $condition['help_code'] = 'auto';//只有auto的可删除
  48. $result = $this->table('help_type')->where($condition)->delete();
  49. return $result;
  50. }
  51. }
  52. /**
  53. * 删除帮助记录
  54. *
  55. * @param
  56. * @return bool
  57. */
  58. public function delHelp($condition, $help_ids = array()) {
  59. if (empty($condition)) {
  60. return false;
  61. } else {
  62. $result = $this->table('help')->where($condition)->delete();
  63. if ($result && !empty($help_ids)) {
  64. $condition = array();
  65. $condition['item_id'] = array('in', $help_ids);
  66. $this->delHelpPic($condition);//删除帮助中所用的图片
  67. }
  68. return $result;
  69. }
  70. }
  71. /**
  72. * 删除帮助图片
  73. *
  74. * @param
  75. * @return bool
  76. */
  77. public function delHelpPic($condition) {
  78. if (empty($condition)) {
  79. return false;
  80. } else {
  81. $upload_list = $this->getHelpPicList($condition);
  82. if (!empty($upload_list) && is_array($upload_list)) {
  83. foreach ($upload_list as $key => $value) {
  84. @unlink(BASE_UPLOAD_PATH.DS.ATTACH_ARTICLE.DS.$value['file_name']);
  85. }
  86. }
  87. $result = $this->table('upload')->where($condition)->delete();
  88. return $result;
  89. }
  90. }
  91. /**
  92. * 修改帮助类型记录
  93. *
  94. * @param
  95. * @return bool
  96. */
  97. public function editHelpType($condition, $data) {
  98. if (empty($condition)) {
  99. return false;
  100. }
  101. if (is_array($data)) {
  102. $result = $this->table('help_type')->where($condition)->update($data);
  103. return $result;
  104. } else {
  105. return false;
  106. }
  107. }
  108. /**
  109. * 修改帮助记录
  110. *
  111. * @param
  112. * @return bool
  113. */
  114. public function editHelp($condition, $data) {
  115. if (empty($condition)) {
  116. return false;
  117. }
  118. if (is_array($data)) {
  119. $result = $this->table('help')->where($condition)->update($data);
  120. return $result;
  121. } else {
  122. return false;
  123. }
  124. }
  125. /**
  126. * 更新帮助图片
  127. *
  128. * @param
  129. * @return bool
  130. */
  131. public function editHelpPic($help_id, $upload_ids = array()) {
  132. if ($help_id && !empty($upload_ids)) {
  133. $condition = array();
  134. $data = array();
  135. $condition['upload_id'] = array('in', $upload_ids);
  136. $condition['upload_type'] = '2';
  137. $condition['item_id'] = '0';
  138. $data['item_id'] = $help_id;
  139. $result = $this->table('upload')->where($condition)->update($data);
  140. return $result;
  141. } else {
  142. return false;
  143. }
  144. }
  145. /**
  146. * 帮助类型记录
  147. *
  148. * @param
  149. * @return array
  150. */
  151. public function getHelpTypeList($condition = array(), $page = '', $limit = '', $fields = '*') {
  152. $result = $this->table('help_type')->field($fields)->where($condition)->page($page)->limit($limit)->order('type_sort asc,type_id desc')->select();
  153. return $result;
  154. }
  155. /**
  156. * 帮助记录
  157. *
  158. * @param
  159. * @return array
  160. */
  161. public function getHelpList($condition = array(), $page = '', $limit = '', $fields = '*') {
  162. $result = $this->table('help')->field($fields)->where($condition)->page($page)->limit($limit)->order('help_sort asc,help_id desc')->select();
  163. return $result;
  164. }
  165. /**
  166. * 帮助图片记录
  167. *
  168. * @param
  169. * @return array
  170. */
  171. public function getHelpPicList($condition = array()) {
  172. $condition['upload_type'] = '2';//帮助内容图片
  173. $result = $this->table('upload')->where($condition)->select();
  174. return $result;
  175. }
  176. /**
  177. * 店铺页面帮助类型记录
  178. *
  179. * @param
  180. * @return array
  181. */
  182. public function getStoreHelpTypeList($condition = array(), $page = '', $limit = 0) {
  183. $condition['page_show'] = '1';//页面类型:1为店铺,2为会员
  184. $result = $this->table('help_type')->where($condition)->page($page)->limit($limit)->order('type_sort asc,type_id desc')->key('type_id')->select();
  185. return $result;
  186. }
  187. /**
  188. * 店铺页面帮助记录
  189. *
  190. * @param
  191. * @return array
  192. */
  193. public function getStoreHelpList($condition = array(), $page = '') {
  194. $condition['page_show'] = '1';//页面类型:1为店铺,2为会员
  195. $result = $this->getHelpList($condition, $page);
  196. return $result;
  197. }
  198. /**
  199. * 前台商家帮助显示数据
  200. *
  201. * @param
  202. * @return array
  203. */
  204. public function getShowStoreHelpList($condition = array()) {
  205. $list = array();
  206. $help_list = array();//帮助内容
  207. $condition['help_show'] = '1';//是否显示,0为否,1为是
  208. $list = $this->getStoreHelpTypeList($condition);//帮助类型
  209. if (!empty($list) && is_array($list)) {
  210. $type_ids = array_keys($list);//类型编号数组
  211. $condition = array();
  212. $condition['type_id'] = array('in', $type_ids);
  213. $help_list = $this->getStoreHelpList($condition);
  214. if (!empty($help_list) && is_array($help_list)) {
  215. foreach ($help_list as $key => $value) {
  216. $type_id = $value['type_id'];//类型编号
  217. $help_id = $value['help_id'];//帮助编号
  218. $list[$type_id]['help_list'][$help_id] = $value;
  219. }
  220. }
  221. }
  222. return $list;
  223. }
  224. }