Index.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. namespace app\abutment\controller;
  3. use app\abutment\logic\Index as IndexLogic;
  4. use think\exception\ValidateException;
  5. use think\facade\Config;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. class Index extends HomeBaseController
  9. {
  10. //获取上线平台列表
  11. public function getPlatformList()
  12. {
  13. $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
  14. $val = Validate::rule(Config::get('validate_rules.common'));
  15. if (!$val->check($param)) throw new ValidateException($val->getError());
  16. return IndexLogic::getPlatformList($param['keyword'], $param['page'], $param['size']);
  17. }
  18. //获取分类列表
  19. public function getCatList()
  20. {
  21. $param = $this->request->filter('trim')->only(['keyword' => '', 'pid' => 0], 'post');
  22. $val = Validate::rule(Config::get('validate_rules.getCatList'));
  23. if (!$val->check($param)) throw new ValidateException($val->getError());
  24. return IndexLogic::getCatList($param['keyword'], $param['pid']);
  25. }
  26. //获取品牌列表-api
  27. public function getBrandList()
  28. {
  29. $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
  30. $val = Validate::rule(Config::get('validate_rules.common'));
  31. if (!$val->check($param)) throw new ValidateException($val->getError());
  32. return IndexLogic::getBrandList($param['keyword'], $param['page'], $param['size']);
  33. }
  34. //获取品牌列表-前端
  35. public function brandList()
  36. {
  37. $this->post = $this->request->filter('trim')->post();
  38. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  39. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  40. $where = [["b.is_del", "=", 0]];
  41. $brand_name = isset($this->post['brand_name']) && $this->post['brand_name'] !== "" ? trim($this->post['brand_name']) : "";
  42. if ($brand_name !== "") {
  43. $where[] = ['b.brand_name', "like", "%$brand_name%"];
  44. }
  45. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  46. if ($status !== "") {
  47. $where[] = ['b.status', "=", $status];
  48. }
  49. $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
  50. if ($creater !== "") {
  51. $where[] = ['b.creater', "like", "%$creater%"];
  52. }
  53. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  54. if ($start !== "") {
  55. $where[] = ['b.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  56. }
  57. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  58. if ($end !== "") {
  59. $where[] = ['b.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  60. }
  61. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  62. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  63. $count = Db::name('brand')
  64. ->alias('b')
  65. ->where($where)
  66. ->count();
  67. $total = ceil($count / $size);
  68. $page = $page >= $total ? $total : $page;
  69. $list = Db::name('brand')
  70. ->alias('b')
  71. ->where($where)
  72. ->page($page, $size)
  73. ->order("addtime desc,id desc")
  74. ->select()
  75. ->toArray();
  76. $all_createrid = array_column($list,'createrid');
  77. $item = get_company_name_by_uid($all_createrid);
  78. foreach ($list as &$value){
  79. $value['company_name']=$item[$value['createrid']]??'';
  80. }
  81. return json_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  82. }
  83. //获取单位列表
  84. public function getUnitList()
  85. {
  86. $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
  87. $val = Validate::rule(Config::get('validate_rules.common'));
  88. if (!$val->check($param)) throw new ValidateException($val->getError());
  89. return IndexLogic::getUnitList($param['keyword'], $param['page'], $param['size']);
  90. }
  91. //获取规格标题列表
  92. public function getSpecsTitleList()
  93. {
  94. $param = $this->request->filter('trim')->only(['keyword' => ''], 'post');
  95. $val = Validate::rule(Config::get('validate_rules.keyword'));
  96. if (!$val->check($param)) throw new ValidateException($val->getError());
  97. return IndexLogic::getSpecsTitleList($param['keyword']);
  98. }
  99. //获取规格值列表
  100. public function getSpecsValueByTitleList()
  101. {
  102. $param = $this->request->filter('trim')->only(['spec_id'], 'post');
  103. $val = Validate::rule(Config::get('validate_rules.getSpecsValueByTitleList'));
  104. if (!$val->check($param)) throw new ValidateException($val->getError());
  105. return IndexLogic::getSpecsValueByTitleList($param['spec_id']);
  106. }
  107. //获取省市区列表
  108. public function getAreaList()
  109. {
  110. $param = $this->request->filter('trim')->only(['level' => 1, 'pid_code' => ''], 'post');
  111. $val = Validate::rule(Config::get('validate_rules.getAreaList'));
  112. if (!$val->check($param)) throw new ValidateException($val->getError());
  113. return IndexLogic::getAreaList($param['level'], $param['pid_code']);
  114. }
  115. //获取业务公司编码-api
  116. public function getCompanyNoList()
  117. {
  118. $param = $this->request->filter('trim')->only(['keyword' => ''], 'post');
  119. $val = Validate::rule(Config::get('validate_rules.keyword'));
  120. if (!$val->check($param)) throw new ValidateException($val->getError());
  121. return IndexLogic::getCompanyNoList($param['keyword']);
  122. }
  123. //获取业务公司编码-前端
  124. public function businessList()
  125. {
  126. $this->post = $this->request->filter('trim')->post();
  127. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  128. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  129. $where = [["b.is_del", "=", 0]];
  130. $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : "";
  131. if ($company !== "") {
  132. $where[] = ['b.company', "like", "%$company%"];
  133. }
  134. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  135. if ($status !== "") {
  136. $where[] = ['b.status', "=", $status];
  137. }
  138. $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
  139. if ($creater !== "") {
  140. $where[] = ['b.creater', "like", "%$creater%"];
  141. }
  142. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  143. if ($start !== "") {
  144. $where[] = ['b.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  145. }
  146. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  147. if ($end !== "") {
  148. $where[] = ['b.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  149. }
  150. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  151. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  152. $count = Db::name('business')
  153. ->alias('b')
  154. ->where($where)
  155. ->count();
  156. $total = ceil($count / $size);
  157. $page = $page >= $total ? $total : $page;
  158. $list = Db::name('business')
  159. ->alias('b')
  160. ->where($where)
  161. ->page($page, $size)
  162. ->field("b.id,b.company,b.companyNo,b.status,b.creater,b.addtime,b.type")
  163. ->order("addtime desc")
  164. ->select()
  165. ->toArray();
  166. $all_createrid = array_column($list, 'createrid');
  167. $item = get_company_name_by_uid($all_createrid);
  168. foreach ($list as &$value) {
  169. $value['company_name'] = $item[$value['createrid']] ?? '';
  170. }
  171. return json_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  172. }
  173. //专属类型列表
  174. public function getExclusiveList()
  175. {
  176. $pid = $this->request->filter('trim')->post('pid/d', 0);
  177. $where = [["is_del", "=", 0], ["pid", "=", $pid]];
  178. $cat_name = $this->request->filter('trim')->post('cat_name', '');
  179. if ($cat_name !== "") $where[] = ['cat_name', "like", "%$cat_name%"];
  180. $data = Db::name("exclusive")
  181. ->where($where)
  182. ->select()
  183. ->toArray();
  184. $vmp = [];
  185. foreach ($data as $sts) {
  186. $vmp[] = coco($sts);
  187. }
  188. return json_show(0, "获取成功", $vmp);
  189. }
  190. //上传图片
  191. public function uploadImg()
  192. {
  193. $files = $this->request->file('image');
  194. $list = "";
  195. if ($files != "") $list = UploadImg($files);
  196. if (is_array($list) && !empty($list)) return json_show(0, "上传成功!", $list);
  197. else return json_show(1005, "上传失败!" . $list);
  198. }
  199. }