Help.php 9.6 KB

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