Product.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace app\user\controller;
  3. use think\Controller;
  4. use think\Lang;
  5. use think\Request;
  6. class Product extends AdminControl
  7. {
  8. public function _initialize()
  9. {
  10. parent::_initialize();
  11. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/product.lang.php');
  12. }
  13. public function index()
  14. {
  15. $model_product = Model('product');
  16. $product_keywords = input('post.product_keywords');
  17. $product_type = input('post.product_type');
  18. $condition = array();
  19. if($product_keywords){
  20. $condition['product_keywords'] = $product_keywords;
  21. }
  22. if($product_type){
  23. $condition['product_type'] = $product_type;
  24. }
  25. $product_list = $model_product->getProductList($condition,'*',10);
  26. $allpower = $this->qxhans();
  27. $this->assign('allpower',$allpower);
  28. $this->assign('product_list', $product_list);
  29. $this->assign('show_page', $model_product->page_info->render());
  30. $this->setAdminCurItem('index');
  31. return $this->fetch();
  32. }
  33. public function add()
  34. {
  35. $allpower = $this->qxhans();
  36. $this->assign('allpower',$allpower);
  37. if (request()->isPost()) {
  38. $data = array(
  39. 'product_type' => input('post.product_type'),
  40. 'product_title' => input('post.product_title'),
  41. 'product_ctitle' => input('post.product_ctitle'),
  42. 'product_keywords' => input('post.product_keywords'),
  43. 'product_status' => input('post.product_status'),
  44. 'product_isjump' => input('post.product_isjump'),
  45. 'product_content' => input('post.product_content'),
  46. );
  47. if (!input('param.product_addtime')) {
  48. $data['product_addtime'] = TIMESTAMP;
  49. } else {
  50. $data['product_addtime'] = strtotime(input('param.product_addtime'));
  51. }
  52. $result = model('product')->addproduct($data);
  53. if ($result){
  54. $this->success(lang('add_succ'), url('product/index'));
  55. }
  56. $this->error(lang('add_fail'));
  57. } else {
  58. $product = array(
  59. 'product_isjump' => 0,
  60. 'product_status' => 0,
  61. 'product_type' => '',
  62. );
  63. $pic_list = model('pic')->getPicList(array('pic_id' => 0));
  64. $this->assign('product', $product);
  65. $this->assign('product_pic_type', ['pic_type' => 'product']);
  66. $this->assign('pic_list', $pic_list);
  67. $this->setAdminCurItem('add');
  68. return $this->fetch('form');
  69. }
  70. }
  71. public function edit()
  72. {
  73. $allpower = $this->qxhans();
  74. $this->assign('allpower',$allpower);
  75. $product_id = input('param.product_id');
  76. if ($product_id <= 0) {
  77. $this->error('系统错误');
  78. }
  79. $condition['pic_type'] = 'product';
  80. $condition['pic_type_id'] = $product_id;
  81. if (request()->isPost()) {
  82. $data = array(
  83. 'product_type' => input('post.product_type'),
  84. 'product_title' => input('post.product_title'),
  85. 'product_ctitle' => input('post.product_ctitle'),
  86. 'product_keywords' => input('post.product_keywords'),
  87. 'product_status' => input('post.product_status'),
  88. 'product_isjump' => input('post.product_isjump'),
  89. 'product_content' => input('post.product_content'),
  90. );
  91. if (!input('param.product_updatetime')) {
  92. $data['product_updatetime'] = TIMESTAMP;
  93. } else {
  94. $data['product_updatetime'] = strtotime(input('param.product_updatetime'));
  95. }
  96. $result = model('product')->editproduct(['product_id' => $product_id], $data);
  97. if ($result >= 0) {
  98. $this->success(lang('edit_succ'), 'product/index');
  99. } else {
  100. $this->error(lang('edit_fail'));
  101. }
  102. } else {
  103. $pic_list = model('pic')->getpicList($condition);
  104. $this->assign('pic_list', $pic_list);
  105. $where = array();
  106. //获取当前帮助中心的内容
  107. $product = model('product')->getOneProduct(['product_id' => $product_id]);
  108. $this->assign('product_pic_type', ['pic_type' => 'product']);
  109. $this->assign('product', $product);
  110. $this->setAdminCurItem('edit');
  111. return $this->fetch('form');
  112. }
  113. }
  114. function del()
  115. {
  116. $product_id = intval(input('param.product_id'));
  117. if ($product_id) {
  118. $condition['product_id'] = $product_id;
  119. $result = model('product')->delproduct($condition);
  120. if ($result) {
  121. ds_json_encode(10000, lang('del_succ'));
  122. } else {
  123. ds_json_encode(10001, lang('del_fail'));
  124. }
  125. } else {
  126. ds_json_encode(10001, lang('param_error'));
  127. }
  128. }
  129. function ajax()
  130. {
  131. $branch = input('param.branch');
  132. switch ($branch) {
  133. case 'product':
  134. $product_mod = model('product');
  135. $condition = array('product_id' => intval(input('param.id')));
  136. $update[input('param.column')] = input('param.value');
  137. $product_mod->editproduct($condition, $update);
  138. echo 'true';
  139. }
  140. }
  141. function setproduct()
  142. {
  143. $product_type = input('param.product_type');
  144. $product_id = input('param.product_id');
  145. $res = model('product')->getOneProduct(['product_id' => $product_id], $product_type);
  146. $id = $res[$product_type] == 0 ? 1 : 0;
  147. $update[$product_type] = $id;
  148. $condition['product_id'] = $product_id;
  149. if (model('product')->editproduct($condition, $update)) {
  150. ds_json_encode(10000, lang('edit_succ'));
  151. } else {
  152. $this->error(lang('edit_fail'));
  153. }
  154. }
  155. protected function getAdminItemList()
  156. {
  157. $menu_array = array(
  158. array(
  159. 'name' => 'index', 'text' => '管理', 'url' => url('product/index')
  160. ), array(
  161. 'name' => 'add', 'text' => '新增', 'url' => url('product/add')
  162. ),
  163. );
  164. if (request()->action() == 'edit') {
  165. $menu_array[] = array(
  166. 'name' => 'edit', 'text' => '编辑', 'url' => url('product/edit')
  167. );
  168. }
  169. return $menu_array;
  170. }
  171. }