ShowTemplate.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\system\controller;
  4. use app\BaseController;
  5. use app\model\api\ShowTemplate as ShowTemplateModel;
  6. use app\model\api\ServiceType as ServiceTypeModel;
  7. use app\model\api\ServiceTimeType as ServiceTimeTypeModel;
  8. use app\Request;
  9. use library\services\UtilService;
  10. // +----------------------------------------------------------------------
  11. // | [ WE CAN DO IT MORE SIMPLE ]
  12. // +----------------------------------------------------------------------
  13. // | Copyright (c) 2018-2020 rights reserved.
  14. // +----------------------------------------------------------------------
  15. // | [ 皮肤模板管理 ]
  16. // +----------------------------------------------------------------------
  17. // | Date: 2020-09-06 21:53
  18. // +----------------------------------------------------------------------
  19. class ShowTemplate extends BaseController{
  20. /**
  21. * 商品列表
  22. * @param Request $request
  23. * @return type
  24. */
  25. public function list(Request $request) {
  26. $post = UtilService::getMore([
  27. ['is_hot', ''],
  28. ['is_recommend', ''],
  29. ['status', ''],
  30. ['page', 1],
  31. ['pageSize', 50],
  32. ], $request);
  33. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  34. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  35. $data = (new ShowTemplateModel)->getDataList($post,"*",1);
  36. return app('json')->success(["list" =>$data["list"], "pageSize" => $data["pageSize"],"page"=>$data["page"],"pageCount"=>$data["totalCount"]]);
  37. }
  38. /**
  39. * 添加编辑商品
  40. * @param Request $request
  41. * @return type
  42. */
  43. public function add(Request $request){
  44. $post = UtilService::getMore([
  45. ['id',''],
  46. ['title','','empty','请填写模板标题'],
  47. ['price','0','is_numeric','请输入正确的模板售价'],
  48. ['old_price','0','is_numeric','请输入正确的模板原价'],
  49. // ['imgs',[],'empty','请上传商品主图'],
  50. ['imgs',[]],
  51. ['is_hot','0'],
  52. ['is_recommend','0'],
  53. ['is_init','0'],
  54. ['code','','empty','请输入CODE'],
  55. ['status','0'],
  56. ['unreal_sales','0'],
  57. ],$request);
  58. $save=[];
  59. $save["title"] = $post["title"];
  60. $save["price"] = floatval($post["price"]);
  61. $save["old_price"] = floatval($post["old_price"]);
  62. $save["status"] = (int)$post["status"] == 1 ? 1 : 0;
  63. $save["imgs"] = empty($post["imgs"]) ? "" : implode(",", $post["imgs"]);
  64. $save["is_hot"] = (int)$post["is_hot"] == 1 ? 1 : 0;
  65. $save["is_recommend"] = (int)$post["is_recommend"]== 1 ? 1 : 0;
  66. $save["is_init"] = (int)$post["is_init"] == 1 ? 1 : 0;
  67. $save["code"] = $post["code"];
  68. $save["unreal_sales"] = (int)$post["unreal_sales"];
  69. $save["admin_time"] = time();
  70. $save["admin_id"] = $request->adminInfo['id'];
  71. if($save["price"]<0 || $save["old_price"]<0){
  72. return app('json')->fail("请输入正确的价格");
  73. }
  74. $id = empty($post["id"])?0:(int)$post["id"];
  75. $codeWhere[]=["code","=",$save["code"]];
  76. if($id>0){
  77. $codeWhere[]=["id","<>",$id];
  78. }
  79. $count = (new ShowTemplateModel)->where($codeWhere)->where("id","<>",$id)->count();
  80. if($count>0){
  81. return app('json')->fail("当前code已存在");
  82. }
  83. $r=0;
  84. if(empty($id) || $id=="0"){
  85. $save["time"] = time();
  86. $r = (new ShowTemplateModel)->insert($save);
  87. }else{
  88. $r = (new ShowTemplateModel)->where("id",$id)->update($save);
  89. }
  90. if($r){
  91. return app('json')->success("数据保存成功");
  92. }else{
  93. return app('json')->fail("数据保存失败");
  94. }
  95. }
  96. /**
  97. * 服务类型列表
  98. * @param Request $request
  99. * @return type
  100. */
  101. public function serviceType(Request $request) {
  102. $post = UtilService::getMore([
  103. ['page',1],
  104. ['pageSize', 50],
  105. ['title',''],
  106. ['status',''],
  107. ],$request);
  108. $data = (new ServiceTypeModel)->getList($post);
  109. return app('json')->success([
  110. 'list' => $data["list"],
  111. 'pageCount' => $data["totalCount"],
  112. 'pageSize' => $data["pageSize"],
  113. 'page' => $data["page"],
  114. ]);
  115. }
  116. /**
  117. * 添加服务内容
  118. */
  119. public function serviceTypeAdd(Request $request){
  120. $post = UtilService::getMore([
  121. ['id','0'],
  122. ['title','','empty','请填写名称'],
  123. ['seq','0'],
  124. ['content',''],
  125. ['img',''],
  126. ['status','0']
  127. ],$request);
  128. $id = $post["id"];
  129. unset($post["id"]);
  130. $r=0;
  131. if(empty($id) || $id=="0"){
  132. $r = (new ServiceTypeModel)->insert($post);
  133. }else{
  134. $r = (new ServiceTypeModel)->where("id",$id)->update($post);
  135. }
  136. if($r){
  137. return app('json')->success("数据保存成功");
  138. }else{
  139. return app('json')->fail("数据保存失败");
  140. }
  141. }
  142. /**
  143. * 分类删除
  144. * @param Request $request
  145. */
  146. public function serviceTypeDel(Request $request) {
  147. [$id] = UtilService::getMore([
  148. ['id',0,'empty','参数错误']
  149. ],$request,true);
  150. return app('json')->success("暂不支持删除");
  151. $bool = (new ServiceTypeModel)->where("id",$id)->delete();
  152. return app('json')->success("删除成功");
  153. }
  154. /**
  155. * 服务时长类型
  156. * @param Request $request
  157. */
  158. public function serviceTimeTypeList(Request $request){
  159. $post = UtilService::getMore([
  160. ['page',1],
  161. ['pageSize', 50],
  162. ['title',''],
  163. ['status',''],
  164. ],$request);
  165. $data = (new ServiceTimeTypeModel)->getList($post);
  166. return app('json')->success([
  167. 'list' => $data["list"],
  168. 'pageCount' => $data["totalCount"],
  169. 'pageSize' => $data["pageSize"],
  170. 'page' => $data["page"],
  171. ]);
  172. }
  173. /**
  174. * 添加服务时长类型
  175. */
  176. public function serviceTimeTypeAdd(Request $request){
  177. $post = UtilService::getMore([
  178. ['id','0'],
  179. ['seq','0'],
  180. ['code','','empty','请填写code'],
  181. ['title','','empty','请填写名称'],
  182. ['content',''],
  183. ['status','0'],
  184. ['img','']
  185. ],$request);
  186. $id = $post["id"];
  187. unset($post["id"]);
  188. $r=0;
  189. if(empty($id) || $id=="0"){
  190. $r = (new ServiceTimeTypeModel)->insert($post);
  191. }else{
  192. $r = (new ServiceTimeTypeModel)->where("id",$id)->update($post);
  193. }
  194. if($r){
  195. return app('json')->success("数据保存成功");
  196. }else{
  197. return app('json')->fail("数据保存失败");
  198. }
  199. }
  200. /**
  201. * 分类删除
  202. * @param Request $request
  203. */
  204. public function serviceTimeTypeDel(Request $request) {
  205. [$id] = UtilService::getMore([
  206. ['id',0,'empty','参数错误']
  207. ],$request,true);
  208. return app('json')->success("暂不支持删除");
  209. $bool = (new ServiceTimeTypeModel)->where("id",$id)->delete();
  210. return app('json')->success("删除成功");
  211. }
  212. }