Product.php 6.6 KB

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