Help.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Help extends BaseModel
  12. {
  13. public $page_info;
  14. /**
  15. * 增加帮助类型
  16. * @access public
  17. * @author csdeshang
  18. * @param type $type_array 类型数组
  19. * @return bool
  20. */
  21. public function addHelptype($type_array)
  22. {
  23. $type_id = Db::name('helptype')->insertGetId($type_array);
  24. return $type_id;
  25. }
  26. /**
  27. * 增加帮助
  28. * @access public
  29. * @author csdeshang
  30. * @param type $help_array 帮助内容
  31. * @param type $upload_ids 更新ID
  32. * @return type
  33. */
  34. public function addHelp($help_array, $upload_ids = array())
  35. {
  36. $help_id = Db::name('help')->insertGetId($help_array);
  37. if ($help_id && !empty($upload_ids)) {
  38. $this->editHelpPic($help_id, $upload_ids); //更新帮助图片
  39. }
  40. return $help_id;
  41. }
  42. /**
  43. * 删除帮助类型记录
  44. * @access public
  45. * @author csdeshang
  46. * @param array $condition 检索条件
  47. * @return bool
  48. */
  49. public function delHelptype($condition)
  50. {
  51. if (empty($condition)) {
  52. return false;
  53. } else {
  54. $condition[] = array('helptype_code', '=', 'auto'); //只有auto的可删除
  55. $result = Db::name('helptype')->where($condition)->delete();
  56. return $result;
  57. }
  58. }
  59. /**
  60. * 删除帮助记录
  61. * @access public
  62. * @author csdeshang
  63. * @param type $condition 检索条件
  64. * @param type $help_ids 帮助id数组
  65. * @return boolean
  66. */
  67. public function delHelp($condition, $help_ids = array())
  68. {
  69. if (empty($condition)) {
  70. return false;
  71. } else {
  72. $result = Db::name('help')->where($condition)->delete();
  73. if ($result && !empty($help_ids)) {
  74. $condition = array();
  75. $condition[] = array('item_id', 'in', $help_ids);
  76. $this->delHelpPic($condition); //删除帮助中所用的图片
  77. }
  78. return $result;
  79. }
  80. }
  81. /**
  82. * 删除帮助图片
  83. * @access public
  84. * @author csdeshang
  85. * @param array $condition 检索条件
  86. * @return bool
  87. */
  88. public function delHelpPic($condition)
  89. {
  90. if (empty($condition)) {
  91. return false;
  92. } else {
  93. $upload_list = $this->getHelpPicList($condition);
  94. if (!empty($upload_list) && is_array($upload_list)) {
  95. foreach ($upload_list as $key => $value) {
  96. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR . 'admin/storehelp' . DIRECTORY_SEPARATOR . $value['file_name']);
  97. }
  98. }
  99. $result = Db::name('upload')->where($condition)->delete();
  100. return $result;
  101. }
  102. }
  103. /**
  104. * 修改帮助类型记录
  105. * @access public
  106. * @author csdeshang
  107. * @param type $condition 条件
  108. * @param type $data 参数内容
  109. * @return boolean
  110. */
  111. public function editHelptype($condition, $data)
  112. {
  113. if (empty($condition)) {
  114. return false;
  115. }
  116. if (is_array($data)) {
  117. $result = Db::name('helptype')->where($condition)->update($data);
  118. return $result;
  119. } else {
  120. return false;
  121. }
  122. }
  123. /**
  124. * 修改帮助记录
  125. * @access public
  126. * @author csdeshang
  127. * @param type $condition 条件
  128. * @param type $data 数据
  129. * @return boolean
  130. */
  131. public function editHelp($condition, $data)
  132. {
  133. if (empty($condition)) {
  134. return false;
  135. }
  136. if (is_array($data)) {
  137. $result = Db::name('help')->where($condition)->update($data);
  138. return $result;
  139. } else {
  140. return false;
  141. }
  142. }
  143. /**
  144. * 更新帮助图片
  145. * @access public
  146. * @author csdeshang
  147. * @param type $help_id 帮助ID
  148. * @param type $upload_ids 上传ID数组
  149. * @return boolean
  150. */
  151. public function editHelpPic($help_id, $upload_ids = array())
  152. {
  153. if ($help_id && !empty($upload_ids)) {
  154. $condition = array();
  155. $data = array();
  156. $condition[] = array('upload_id', 'in', $upload_ids);
  157. $condition[] = array('upload_type', '=', '2');
  158. $condition[] = array('item_id', '=', '0');
  159. $data['item_id'] = $help_id;
  160. $result = Db::name('upload')->where($condition)->update($data);
  161. return $result;
  162. } else {
  163. return false;
  164. }
  165. }
  166. /**
  167. * 帮助类型记录
  168. * @access public
  169. * @author csdeshang
  170. * @param type $condition 条件
  171. * @param type $pagesize 分页
  172. * @param type $fields 字段
  173. * @return type
  174. */
  175. public function getHelptypeList($condition = array(), $pagesize = '', $fields = '*')
  176. {
  177. if ($pagesize) {
  178. $result = Db::name('helptype')->field($fields)->where($condition)->order('helptype_sort asc,helptype_id desc')->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  179. $this->page_info = $result;
  180. $result = $result->items();
  181. } else {
  182. $result = Db::name('helptype')->field($fields)->where($condition)->order('helptype_sort asc,helptype_id desc')->select()->toArray();
  183. }
  184. return $result;
  185. }
  186. /**
  187. * 帮助记录
  188. * @access public
  189. * @author csdeshang
  190. * @param type $condition 条件
  191. * @param type $pagesize 分页
  192. * @param type $limit 限制
  193. * @param type $fields 字段
  194. * @return array
  195. */
  196. public function getHelpList($condition = array(), $pagesize = '', $limit = 0, $fields = '*')
  197. {
  198. if ($pagesize) {
  199. $res = Db::name('help')->field($fields)->where($condition)->order('help_sort asc,help_id desc')->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  200. $this->page_info = $res;
  201. $result = $res->items();
  202. } else {
  203. $result = Db::name('help')->field($fields)->where($condition)->limit($limit)->order('help_sort asc,help_id desc')->select()->toArray();
  204. }
  205. return $result;
  206. }
  207. /**
  208. * 帮助图片记录
  209. * @access public
  210. * @author csdeshang
  211. * @param array $condition 条件数组
  212. * @return type
  213. */
  214. public function getHelpPicList($condition = array())
  215. {
  216. $condition[] = array('upload_type', '=', '2'); //帮助内容图片
  217. $result = Db::name('upload')->where($condition)->select()->toArray();
  218. return $result;
  219. }
  220. /**
  221. * 店铺页面帮助类型记录
  222. * @access public
  223. * @author csdeshang
  224. * @param array $condition 条件
  225. * @param type $pagesize 分页
  226. * @param type $limit 限制
  227. * @return type
  228. */
  229. public function getStoreHelptypeList($condition = array(), $pagesize = '', $limit = 0)
  230. {
  231. $condition[] = array('page_show', '=', '1'); //页面类型:1为店铺,2为会员
  232. if ($pagesize) {
  233. $res = Db::name('helptype')->where($condition)->order('helptype_sort asc,helptype_id desc')->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  234. $this->page_info = $res;
  235. $result = $res->items();
  236. } else {
  237. $result = Db::name('helptype')->where($condition)->order('helptype_sort asc,helptype_id desc')->select()->toArray();
  238. }
  239. $result = ds_change_arraykey($result, 'helptype_id');
  240. return $result;
  241. }
  242. /**
  243. * 店铺页面帮助记录
  244. * @access public
  245. * @author csdeshang
  246. * @param array $condition 检索条件
  247. * @param type $pagesize
  248. * @return type
  249. */
  250. public function getStoreHelpList($condition = array(), $pagesize = '')
  251. {
  252. $condition[] = array('page_show', '=', '1'); //页面类型:1为店铺,2为会员
  253. $result = $this->getHelpList($condition, $pagesize);
  254. return $result;
  255. }
  256. /**
  257. * 前台商家帮助显示数据
  258. * @access public
  259. * @author csdeshang
  260. * @param array $condition 检索条件
  261. * @return array
  262. */
  263. public function getShowStoreHelpList($condition = array())
  264. {
  265. $list = array();
  266. $help_list = array(); //帮助内容
  267. $condition[] = array('helptype_show', '=', '1'); //是否显示,0为否,1为是
  268. $list = $this->getStoreHelptypeList($condition); //帮助类型
  269. if (!empty($list) && is_array($list)) {
  270. $type_ids = array_keys($list); //类型编号数组
  271. $condition = array();
  272. $condition[] = array('helptype_id', 'in', $type_ids);
  273. $help_list = $this->getStoreHelpList($condition);
  274. if (!empty($help_list) && is_array($help_list)) {
  275. foreach ($help_list as $key => $value) {
  276. $type_id = $value['helptype_id']; //类型编号
  277. $help_id = $value['help_id']; //帮助编号
  278. $list[$type_id]['help_list'][$help_id] = $value;
  279. }
  280. }
  281. }
  282. return $list;
  283. }
  284. }