Help.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class Help extends BaseModel {
  17. public $page_info;
  18. /**
  19. * 增加帮助类型
  20. * @access public
  21. * @author csdeshang
  22. * @param type $type_array 类型数组
  23. * @return bool
  24. */
  25. public function addHelptype($type_array) {
  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. $help_id = Db::name('help')->insertGetId($help_array);
  39. if ($help_id && !empty($upload_ids)) {
  40. $this->editHelpPic($help_id, $upload_ids); //更新帮助图片
  41. }
  42. return $help_id;
  43. }
  44. /**
  45. * 删除帮助类型记录
  46. * @access public
  47. * @author csdeshang
  48. * @param array $condition 检索条件
  49. * @return bool
  50. */
  51. public function delHelptype($condition) {
  52. if (empty($condition)) {
  53. return false;
  54. } else {
  55. $condition[]=array('helptype_code','=','auto'); //只有auto的可删除
  56. $result = Db::name('helptype')->where($condition)->delete();
  57. return $result;
  58. }
  59. }
  60. /**
  61. * 删除帮助记录
  62. * @access public
  63. * @author csdeshang
  64. * @param type $condition 检索条件
  65. * @param type $help_ids 帮助id数组
  66. * @return boolean
  67. */
  68. public function delHelp($condition, $help_ids = array()) {
  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. if (empty($condition)) {
  90. return false;
  91. } else {
  92. $upload_list = $this->getHelpPicList($condition);
  93. if (!empty($upload_list) && is_array($upload_list)) {
  94. foreach ($upload_list as $key => $value) {
  95. @unlink(BASE_UPLOAD_PATH . DIRECTORY_SEPARATOR .'admin/storehelp'. DIRECTORY_SEPARATOR . $value['file_name']);
  96. }
  97. }
  98. $result = Db::name('upload')->where($condition)->delete();
  99. return $result;
  100. }
  101. }
  102. /**
  103. * 修改帮助类型记录
  104. * @access public
  105. * @author csdeshang
  106. * @param type $condition 条件
  107. * @param type $data 参数内容
  108. * @return boolean
  109. */
  110. public function editHelptype($condition, $data) {
  111. if (empty($condition)) {
  112. return false;
  113. }
  114. if (is_array($data)) {
  115. $result = Db::name('helptype')->where($condition)->update($data);
  116. return $result;
  117. } else {
  118. return false;
  119. }
  120. }
  121. /**
  122. * 修改帮助记录
  123. * @access public
  124. * @author csdeshang
  125. * @param type $condition 条件
  126. * @param type $data 数据
  127. * @return boolean
  128. */
  129. public function editHelp($condition, $data) {
  130. if (empty($condition)) {
  131. return false;
  132. }
  133. if (is_array($data)) {
  134. $result = Db::name('help')->where($condition)->update($data);
  135. return $result;
  136. } else {
  137. return false;
  138. }
  139. }
  140. /**
  141. * 更新帮助图片
  142. * @access public
  143. * @author csdeshang
  144. * @param type $help_id 帮助ID
  145. * @param type $upload_ids 上传ID数组
  146. * @return boolean
  147. */
  148. public function editHelpPic($help_id, $upload_ids = array()) {
  149. if ($help_id && !empty($upload_ids)) {
  150. $condition = array();
  151. $data = array();
  152. $condition[] = array('upload_id','in', $upload_ids);
  153. $condition[] = array('upload_type','=','2');
  154. $condition[] = array('item_id','=','0');
  155. $data['item_id'] = $help_id;
  156. $result = Db::name('upload')->where($condition)->update($data);
  157. return $result;
  158. } else {
  159. return false;
  160. }
  161. }
  162. /**
  163. * 帮助类型记录
  164. * @access public
  165. * @author csdeshang
  166. * @param type $condition 条件
  167. * @param type $pagesize 分页
  168. * @param type $fields 字段
  169. * @return type
  170. */
  171. public function getHelptypeList($condition = array(), $pagesize = '', $fields = '*') {
  172. if($pagesize){
  173. $result = Db::name('helptype')->field($fields)->where($condition)->order('helptype_sort asc,helptype_id desc')->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  174. $this->page_info=$result;
  175. $result=$result->items();
  176. }else{
  177. $result=Db::name('helptype')->field($fields)->where($condition)->order('helptype_sort asc,helptype_id desc')->select()->toArray();
  178. }
  179. return $result;
  180. }
  181. /**
  182. * 帮助记录
  183. * @access public
  184. * @author csdeshang
  185. * @param type $condition 条件
  186. * @param type $pagesize 分页
  187. * @param type $limit 限制
  188. * @param type $fields 字段
  189. * @return array
  190. */
  191. public function getHelpList($condition = array(), $pagesize = '', $limit = 0, $fields = '*') {
  192. if($pagesize) {
  193. $res=Db::name('help')->field($fields)->where($condition)->order('help_sort asc,help_id desc')->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  194. $this->page_info=$res;
  195. $result=$res->items();
  196. }else{
  197. $result = Db::name('help')->field($fields)->where($condition)->limit($limit)->order('help_sort asc,help_id desc')->select()->toArray();
  198. }
  199. return $result;
  200. }
  201. /**
  202. * 帮助图片记录
  203. * @access public
  204. * @author csdeshang
  205. * @param array $condition 条件数组
  206. * @return type
  207. */
  208. public function getHelpPicList($condition = array()) {
  209. $condition[]=array('upload_type','=','2'); //帮助内容图片
  210. $result = Db::name('upload')->where($condition)->select()->toArray();
  211. return $result;
  212. }
  213. /**
  214. * 店铺页面帮助类型记录
  215. * @access public
  216. * @author csdeshang
  217. * @param array $condition 条件
  218. * @param type $pagesize 分页
  219. * @param type $limit 限制
  220. * @return type
  221. */
  222. public function getStoreHelptypeList($condition = array(), $pagesize = '', $limit = 0) {
  223. $condition[]=array('page_show','=','1'); //页面类型:1为店铺,2为会员
  224. if($pagesize){
  225. $res = Db::name('helptype')->where($condition)->order('helptype_sort asc,helptype_id desc')->paginate(['list_rows'=>$pagesize,'query' => request()->param()],false);
  226. $this->page_info=$res;
  227. $result=$res->items();
  228. }else{
  229. $result = Db::name('helptype')->where($condition)->order('helptype_sort asc,helptype_id desc')->select()->toArray();
  230. }
  231. $result = ds_change_arraykey($result, 'helptype_id');
  232. return $result;
  233. }
  234. /**
  235. * 店铺页面帮助记录
  236. * @access public
  237. * @author csdeshang
  238. * @param array $condition 检索条件
  239. * @param type $pagesize
  240. * @return type
  241. */
  242. public function getStoreHelpList($condition = array(), $pagesize = '') {
  243. $condition[]=array('page_show','=','1'); //页面类型:1为店铺,2为会员
  244. $result = $this->getHelpList($condition, $pagesize);
  245. return $result;
  246. }
  247. /**
  248. * 前台商家帮助显示数据
  249. * @access public
  250. * @author csdeshang
  251. * @param array $condition 检索条件
  252. * @return array
  253. */
  254. public function getShowStoreHelpList($condition = array()) {
  255. $list = array();
  256. $help_list = array(); //帮助内容
  257. $condition[]=array('helptype_show','=','1'); //是否显示,0为否,1为是
  258. $list = $this->getStoreHelptypeList($condition); //帮助类型
  259. if (!empty($list) && is_array($list)) {
  260. $type_ids = array_keys($list); //类型编号数组
  261. $condition = array();
  262. $condition[] = array('helptype_id','in', $type_ids);
  263. $help_list = $this->getStoreHelpList($condition);
  264. if (!empty($help_list) && is_array($help_list)) {
  265. foreach ($help_list as $key => $value) {
  266. $type_id = $value['helptype_id']; //类型编号
  267. $help_id = $value['help_id']; //帮助编号
  268. $list[$type_id]['help_list'][$help_id] = $value;
  269. }
  270. }
  271. }
  272. return $list;
  273. }
  274. }