Index.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. ->field('b.*,u.itemid')
  72. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  73. ->where($where)
  74. ->append(['company_name'])
  75. ->withAttr('company_name', function ($val, $data) {
  76. return implode('/', array_column(GetPart($data['itemid']), 'name'));
  77. })
  78. ->page($page, $size)
  79. ->order("addtime desc,id desc")
  80. ->select()
  81. ->toArray();
  82. return json_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  83. }
  84. //获取单位列表
  85. public function getUnitList()
  86. {
  87. $param = $this->request->filter('trim')->only(['keyword' => '', 'page' => 1, 'size' => 15], 'post');
  88. $val = Validate::rule(Config::get('validate_rules.common'));
  89. if (!$val->check($param)) throw new ValidateException($val->getError());
  90. return IndexLogic::getUnitList($param['keyword'], $param['page'], $param['size']);
  91. }
  92. //获取规格标题列表
  93. public function getSpecsTitleList()
  94. {
  95. $param = $this->request->filter('trim')->only(['keyword' => ''], 'post');
  96. $val = Validate::rule(Config::get('validate_rules.keyword'));
  97. if (!$val->check($param)) throw new ValidateException($val->getError());
  98. return IndexLogic::getSpecsTitleList($param['keyword']);
  99. }
  100. //获取规格值列表
  101. public function getSpecsValueByTitleList()
  102. {
  103. $param = $this->request->filter('trim')->only(['spec_id'], 'post');
  104. $val = Validate::rule(Config::get('validate_rules.getSpecsValueByTitleList'));
  105. if (!$val->check($param)) throw new ValidateException($val->getError());
  106. return IndexLogic::getSpecsValueByTitleList($param['spec_id']);
  107. }
  108. //获取省市区列表
  109. public function getAreaList()
  110. {
  111. $param = $this->request->filter('trim')->only(['level' => 1, 'pid_code' => ''], 'post');
  112. $val = Validate::rule(Config::get('validate_rules.getAreaList'));
  113. if (!$val->check($param)) throw new ValidateException($val->getError());
  114. return IndexLogic::getAreaList($param['level'], $param['pid_code']);
  115. }
  116. //获取业务公司编码-api
  117. public function getCompanyNoList()
  118. {
  119. $param = $this->request->filter('trim')->only(['keyword' => ''], 'post');
  120. $val = Validate::rule(Config::get('validate_rules.keyword'));
  121. if (!$val->check($param)) throw new ValidateException($val->getError());
  122. return IndexLogic::getCompanyNoList($param['keyword']);
  123. }
  124. //获取业务公司编码-前端
  125. public function businessList()
  126. {
  127. $this->post = $this->request->filter('trim')->post();
  128. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  129. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  130. $where = [["b.is_del", "=", 0]];
  131. $company = isset($this->post['company']) && $this->post['company'] !== "" ? trim($this->post['company']) : "";
  132. if ($company !== "") {
  133. $where[] = ['b.company', "like", "%$company%"];
  134. }
  135. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  136. if ($status !== "") {
  137. $where[] = ['b.status', "=", $status];
  138. }
  139. $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
  140. if ($creater !== "") {
  141. $where[] = ['b.creater', "like", "%$creater%"];
  142. }
  143. $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  144. if ($start !== "") {
  145. $where[] = ['b.addtime', ">=", date('Y-m-d H:i:s', strtotime($start))];
  146. }
  147. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  148. if ($end !== "") {
  149. $where[] = ['b.addtime', "<", date('Y-m-d H:i:s', strtotime($end) + 24 * 3600)];
  150. }
  151. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  152. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  153. $count = Db::name('business')
  154. ->alias('b')
  155. ->where($where)
  156. ->count();
  157. $total = ceil($count / $size);
  158. $page = $page >= $total ? $total : $page;
  159. $list = Db::name('business')
  160. ->alias('b')
  161. ->where($where)
  162. ->page($page, $size)
  163. ->field("b.id,b.company,b.companyNo,b.status,b.creater,b.addtime,b.type,u.itemid")
  164. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  165. ->order("addtime desc")
  166. ->append(['company_name'])
  167. ->withAttr('company_name', function ($val, $data) {
  168. return implode('/', array_column(GetPart($data['itemid']), 'name'));
  169. })
  170. ->select()
  171. ->toArray();
  172. return json_show(0, "获取成功", ['list' => $list, 'count' => $count]);
  173. }
  174. //专属类型列表
  175. public function getExclusiveList()
  176. {
  177. $pid = $this->request->filter('trim')->post('pid/d', 0);
  178. $where = [["is_del", "=", 0], ["pid", "=", $pid]];
  179. $cat_name = $this->request->filter('trim')->post('cat_name', '');
  180. if ($cat_name !== "") $where[] = ['cat_name', "like", "%$cat_name%"];
  181. $data = Db::name("exclusive")
  182. ->where($where)
  183. ->select()
  184. ->toArray();
  185. $vmp = [];
  186. foreach ($data as $sts) {
  187. $vmp[] = coco($sts);
  188. }
  189. return json_show(0, "获取成功", $vmp);
  190. }
  191. //上传图片
  192. public function uploadImg()
  193. {
  194. $files = $this->request->file('image');
  195. $list = "";
  196. if ($files != "") $list = UploadImg($files);
  197. if (is_array($list) && !empty($list)) return json_show(0, "上传成功!", $list);
  198. else return json_show(1005, "上传失败!" . $list);
  199. }
  200. }