Server.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Validate;
  4. use think\Lang;
  5. class Server extends AdminControl
  6. {
  7. public function _initialize()
  8. {
  9. parent::_initialize();
  10. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/member.lang.php');
  11. }
  12. public function index()
  13. {
  14. $productModel = Model('Product');
  15. $fartherProduct = $productModel->getFartherList();
  16. $this->assign('fartherProduct', $fartherProduct);
  17. $fartherId = input('get.id') ?? $fartherProduct[0]->product_id;
  18. $this->assign('id', $fartherId);
  19. $sonProductWhere['product_pid'] = $fartherId;
  20. $sonProduct = $productModel->getSonList($sonProductWhere);
  21. $this->assign('sonProduct', $sonProduct);
  22. $this->assign('show_page', $sonProduct->render());
  23. return $this->fetch();
  24. }
  25. public function add()
  26. {
  27. $productModel = Model('Product');
  28. $product_pid = input('param.id');
  29. if (!request()->isPost()) {
  30. return $this->fetch('form');
  31. } else {
  32. $files = request()->file('product_img');
  33. $product_name = input('post.product_name');
  34. $product_content = input('post.product_content');
  35. $product_money = input('post.product_money');
  36. $product_status = input('post.product_status');
  37. $product_TypeOne = input('post.product_TypeOne');
  38. $product_TypeTwo = input('post.product_TypeTwo');
  39. $product_TypeFour = input('post.product_TypeFour');
  40. $product_TypeThree = input('post.product_TypeThree');
  41. if (!$product_name || !$files || !$product_content || !$product_money || !$product_status
  42. || !$product_TypeOne || !$product_TypeTwo || !$product_TypeFour || !$product_TypeThree) {
  43. $this->error("操作失败");
  44. }
  45. $addData = array(
  46. 'product_name' => $product_name,
  47. 'product_pid' => $product_pid,
  48. 'product_content' => $product_content,
  49. 'product_money' => $product_money,
  50. 'product_status' => $product_status,
  51. 'product_TypeOne' => $product_TypeOne,
  52. 'product_TypeTwo' => $product_TypeTwo,
  53. 'product_TypeFour' => $product_TypeFour,
  54. 'product_TypeThree' => $product_TypeThree,
  55. );
  56. $imgurl = DS_THEME_UPLOADS_URL . '\home';
  57. $fileName = ImgName();
  58. $files = $files->setSaveName($fileName);//设置保存文件名
  59. $imgt = $files->move($imgurl, $savename = $fileName, $replace = true);
  60. if($imgt){
  61. $addData['product_img'] = '/home/' . $fileName.'.png';
  62. }
  63. $result = $productModel->addProduct($addData);
  64. if ($result) {
  65. dsLayerOpenSuccess("新增成功");
  66. } else {
  67. $this->error("操作失败");
  68. }
  69. }
  70. }
  71. public function delete()
  72. {
  73. $product_id = intval(input('param.product_id'));
  74. if ($product_id) {
  75. $condition['product_id'] = $product_id;
  76. $result = model('Product')->deleteProduct($condition);
  77. if ($result) {
  78. $this->log(lang('ds_product').'-'.lang('del_succ') . '[' . $product_id . ']', null);
  79. ds_json_encode(10000, lang('del_succ'));
  80. } else {
  81. ds_json_encode(10001, lang('del_fail'));
  82. }
  83. } else {
  84. ds_json_encode(10001, lang('del_fail'));
  85. }
  86. }
  87. public function fartherList()
  88. {
  89. $productModel = Model('Product');
  90. $fartherProduct = $productModel->getFartherList();
  91. $this->assign('fartherProduct', $fartherProduct);
  92. return $this->fetch('fartherList');
  93. }
  94. public function fartherEdit()
  95. {
  96. $productModel = Model('Product');
  97. $product_id = input('post.product_id');
  98. $status = input('post.status');
  99. $product_name= input('post.product_name');
  100. if ($product_id) {
  101. $updateData = array(
  102. 'product_name' => $product_name,
  103. 'product_status' => $status,
  104. );
  105. $result = $productModel->updateProduct($product_id, $updateData);
  106. if ($result) {
  107. return ["msg"=>"编辑成功"];
  108. } else {
  109. return ["msg"=>"操作失败"];
  110. }
  111. } else {
  112. $nowDate = date('Y-m-d H:i:s');
  113. $addData = array(
  114. 'product_name' => $product_name,
  115. 'product_status' => $status,
  116. 'product_content' => '',
  117. 'product_updatetime' => $nowDate,
  118. 'product_addtime' => $nowDate,
  119. 'product_pid' => 0,
  120. );
  121. $result = $productModel->addProduct($addData);
  122. if ($result) {
  123. return ["msg"=>"新增成功"];
  124. } else {
  125. return ["msg"=>"操作失败"];
  126. }
  127. }
  128. }
  129. public function edit()
  130. {
  131. $productModel = Model('Product');
  132. $product_id = input('param.product_id');
  133. if (!request()->isPost()) {
  134. $productWhere['product_id'] = $product_id;
  135. $product = $productModel->findProduct($productWhere);
  136. $this->assign('product', $product);
  137. return $this->fetch('form');
  138. } else {
  139. $updateData = array(
  140. 'product_name' => input('post.product_name'),
  141. 'product_content' => input('post.product_content'),
  142. 'product_money' => input('post.product_money'),
  143. 'product_status' => input('post.product_status'),
  144. 'product_TypeOne' => input('post.product_TypeOne'),
  145. 'product_TypeTwo' => input('post.product_TypeTwo'),
  146. 'product_TypeFour' => input('post.product_TypeFour'),
  147. 'product_TypeThree' => input('post.product_TypeThree'),
  148. );
  149. $files = request()->file('product_img');
  150. if($files){
  151. $imgurl = DS_THEME_UPLOADS_URL . '\home';
  152. $fileName = ImgName();
  153. $files = $files->setSaveName($fileName);//设置保存文件名
  154. $imgt = $files->move($imgurl, $savename = $fileName, $replace = true);
  155. if($imgt){
  156. $updateData['product_img'] = '/home/' . $fileName.'.png';
  157. }
  158. }
  159. $result = $productModel->updateProduct($product_id, $updateData);
  160. if ($result) {
  161. dsLayerOpenSuccess("编辑成功");
  162. } else {
  163. $this->error("操作失败");
  164. }
  165. }
  166. }
  167. public function info()
  168. {
  169. $productInfoModel = Model('Productinfo');
  170. $product_id = input('param.product_id');
  171. $productInfoWhere['product_id'] = $product_id;
  172. $productInfo = $productInfoModel->getProductInfo($productInfoWhere);
  173. $this->assign('productInfo', $productInfo);
  174. return $this->fetch('information');
  175. }
  176. public function deleteInfo()
  177. {
  178. $productInfo_id = intval(input('param.productInfo_id'));
  179. if ($productInfo_id) {
  180. $condition['productInfo_id'] = $productInfo_id;
  181. $result = model('Productinfo')->deleteProductInfo($condition);
  182. if ($result) {
  183. $this->log(lang('ds_productinfo').'-'.lang('del_succ') . '[' . $productInfo_id . ']', null);
  184. ds_json_encode(10000, lang('del_succ'));
  185. } else {
  186. ds_json_encode(10001, lang('del_fail'));
  187. }
  188. } else {
  189. ds_json_encode(10001, lang('del_fail'));
  190. }
  191. }
  192. public function addInfo()
  193. {
  194. $productInfoModel = Model('Productinfo');
  195. $product_id = input('param.product_id');
  196. if (!request()->isPost()) {
  197. return $this->fetch('infoForm');
  198. } else {
  199. $productInfo_title = input('post.productInfo_title');
  200. $productInfo_content = input('post.productInfo_content');
  201. $files = request()->file('productInfo_img');
  202. if (!$productInfo_title || !$productInfo_content || !$files) {
  203. $this->error("操作失败");
  204. }
  205. $addData = array(
  206. 'productInfo_title' => $productInfo_title,
  207. 'productInfo_content' => $productInfo_content,
  208. 'product_id' => $product_id,
  209. );
  210. $imgurl = DS_THEME_UPLOADS_URL . '\home';
  211. $fileName = ImgName();
  212. $files = $files->setSaveName($fileName);//设置保存文件名
  213. $imgt = $files->move($imgurl, $savename = $fileName, $replace = true);
  214. if ($imgt) {
  215. $addData['productInfo_img'] = '/home/' . $fileName . '.png';
  216. }
  217. $result = $productInfoModel->addProductInfo($addData);
  218. if ($result) {
  219. dsLayerOpenSuccess("添加成功");
  220. } else {
  221. $this->error("操作失败");
  222. }
  223. }
  224. }
  225. public function editInfo()
  226. {
  227. $productInfoModel = Model('Productinfo');
  228. $productInfo_id = input('param.productInfo_id');
  229. if (!request()->isPost()) {
  230. $productInfoWhere['productInfo_id'] = $productInfo_id;
  231. $productInfo = $productInfoModel->findProductInfo($productInfoWhere);
  232. $this->assign('productInfo', $productInfo);
  233. return $this->fetch('infoForm');
  234. } else {
  235. $updateData = array(
  236. 'productInfo_title' => input('post.productInfo_title'),
  237. 'productInfo_content' => input('post.productInfo_content'),
  238. );
  239. $files = request()->file('productInfo_img');
  240. if($files){
  241. $imgurl = DS_THEME_UPLOADS_URL . '\home';
  242. $fileName = ImgName();
  243. $files = $files->setSaveName($fileName);//设置保存文件名
  244. $imgt = $files->move($imgurl, $savename = $fileName, $replace = true);
  245. if($imgt){
  246. $updateData['productInfo_img'] = '/home/' . $fileName.'.png';
  247. }
  248. }
  249. $result = $productInfoModel->updateProductInfo($productInfo_id, $updateData);
  250. if ($result) {
  251. dsLayerOpenSuccess("编辑成功");
  252. } else {
  253. $this->error("操作失败");
  254. }
  255. }
  256. }
  257. public function renewalList()
  258. {
  259. $renewalModel = Model('Renewal');
  260. $renewal = $renewalModel->getRenewal();
  261. $this->assign('renewal', $renewal);
  262. return $this->fetch('renewalList');
  263. }
  264. public function renewalEdit()
  265. {
  266. $renewalModel = Model('Renewal');
  267. $renewal_identity = input('post.renewal_identity');
  268. $status = input('post.status');
  269. $renewal_name = input('post.renewal_name');
  270. $renewal_day = input('post.renewal_day');
  271. $updateData = array(
  272. 'renewal_name' => $renewal_name,
  273. 'renewal_status' => $status,
  274. 'renewal_day' => $renewal_day,
  275. );
  276. $result = $renewalModel->updateRenewal($renewal_identity, $updateData);
  277. if ($result) {
  278. return ["msg"=>"编辑成功"];
  279. } else {
  280. return ["msg"=>"操作失败"];
  281. }
  282. }
  283. public function userServer()
  284. {
  285. $UserProductModel = Model('Userproduct');
  286. $userName = input('post.user_name');
  287. $productName = input('post.product_name');
  288. $userProductIdentity = input('post.userProduct_identity');
  289. $userProductWhere = [];
  290. if ($userName) {
  291. $userProductWhere['user_email'] = $userName;
  292. }
  293. if ($productName) {
  294. $userProductWhere['product_name'] = $productName;
  295. }
  296. if ($userProductIdentity) {
  297. $userProductWhere['userProduct_identity'] = $userProductIdentity;
  298. }
  299. $userproduct = $UserProductModel->getUserproduct($userProductWhere);
  300. $this->assign('userproduct', $userproduct);
  301. $this->assign('show_page', $userproduct->render());
  302. return $this->fetch('userServer');
  303. }
  304. }