Index.php 9.5 KB

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