Help.php 9.6 KB

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