Product.php 6.5 KB

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