You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get.php 9.6 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <?php
  2. /*
  3. * 添加供应商
  4. * author:张帅
  5. */
  6. class get_channel_list
  7. {
  8. //获取供应商列表主要流程
  9. function execGetChannelList($supplier_name, $product_type, $is_disabled,$current,$pagesize)
  10. {
  11. //1.获取筛选条件
  12. $sql_where = $this->getWhere($supplier_name, $is_disabled);
  13. //2.获取数据库原始数据
  14. $db_data = $this->getDbData($sql_where, $product_type,$current,$pagesize);
  15. //3.处理数据
  16. $tidyData = $this->tidyData($db_data['supplier_array']);
  17. $tidyData['total_page'] = (string)$db_data['total_page'];
  18. echo json_encode($tidyData);
  19. exit();
  20. }
  21. //获取筛选条件
  22. function getWhere($supplier_name, $is_disabled)
  23. {
  24. $res = array();
  25. if (!empty($is_disabled) && $is_disabled != -1) {
  26. $res[] = " is_disabled = " . $is_disabled;
  27. }
  28. if (!empty($supplier_name)) {
  29. $res[] = " supplier_name like '%%" . $supplier_name . "%%' ";
  30. }
  31. $main_corp_id = isset($_COOKIE["user_main_corp"]) ? $_COOKIE["user_main_corp"] : 0;
  32. if( $main_corp_id == 0 ) {
  33. $res[] = " main_corp_id = 0 ";
  34. } else {
  35. $res[] = " main_corp_id IN(0,{$main_corp_id}) ";
  36. }
  37. if (count($res) > 0) {
  38. $res = " and " . implode(" and ", $res);
  39. } else {
  40. $res = '';
  41. }
  42. return $res;
  43. }
  44. //获取数据库原始数据
  45. function getDbData($sql_where, $product_type,$current,$pagesize)
  46. {
  47. global $pdo;
  48. if (!empty($product_type) && $product_type != -1)//如果选了采购类型
  49. {
  50. $sale_sql = "SELECT
  51. supplier_id,
  52. product_type,
  53. parent_type
  54. FROM
  55. base_supplier_sale
  56. WHERE
  57. product_type = " . $product_type . " or parent_type = " . $product_type . " and cancel_flag = 0
  58. GROUP BY
  59. supplier_id";
  60. writeLog("select base_supplier_sale:" . $sale_sql);
  61. $result = $pdo->query($sale_sql);
  62. $supplier_id_array = $result->fetchAll(PDO::FETCH_ASSOC);//获取有该采购类型的所有supplier_id
  63. //如果没有该采购类型的supplier,返回空数组
  64. if (count($supplier_id_array) == 0) {
  65. $json['code'] = '0';
  66. $json['info'] = '没有符合条件的数据';
  67. $json['list'] = array();
  68. $json['count'] = '0';
  69. $json['total_page'] = '0';
  70. echo json_encode($json);
  71. exit();
  72. }
  73. //如果有该采购类型的supplier
  74. foreach ($supplier_id_array as $k => $v) {
  75. $supplier_id_array[$k] = $v['supplier_id'];
  76. }
  77. $sql_where .= " and id in(" . implode(",", $supplier_id_array) . ")" . $sql_where . " ";
  78. }
  79. $supplier_sql = "SELECT
  80. id,
  81. supplier_name,
  82. area_id,
  83. is_disabled,
  84. supplier_type,
  85. manage_type
  86. FROM
  87. base_supplier
  88. WHERE
  89. cancel_flag = 0
  90. " . $sql_where . "
  91. AND supplier_type = 301
  92. LIMIT " . ($current-1)*$pagesize . "," . $pagesize;
  93. writeLog("select base_supplier:" . $supplier_sql);
  94. $result = $pdo->query($supplier_sql);
  95. $supplier_array1 = $result->fetchAll(PDO::FETCH_ASSOC);//获取所有数据
  96. if(count($supplier_array1) > 0)
  97. {
  98. foreach($supplier_array1 as $k => $v)
  99. {
  100. $id_array[$v['id']] = $v['id'];
  101. $supplier_array[$v['id']] = $v;
  102. // $v['product_type'] = explode(",",$v['product_type']);
  103. // $v['parent_type'] = explode(",",$v['parent_type']);
  104. // foreach ($v['product_type'] as $key => $value)
  105. // {
  106. // if(empty($value))
  107. // {
  108. // $v['product_type'][$key] = $v['parent_type'][$key];
  109. // }
  110. // }
  111. // $v['product_type'] = array_unique($v['product_type']);
  112. // $v['product_type'] = implode(",",$v['product_type']);
  113. // unset($v['parent_type']);
  114. // $supplier_array[$k] = $v;
  115. }
  116. $sql = "select group_concat(product_type) as product_type,group_concat(parent_type) as parent_type,supplier_id from base_supplier_sale where supplier_id in (" . implode(",",$id_array) . ") and cancel_flag = 0 group by supplier_id";
  117. $result = $pdo->query($sql);
  118. $sale_array1 = $result->fetchAll(PDO::FETCH_ASSOC);
  119. foreach($sale_array1 as $k => $v)
  120. {
  121. $v['product_type'] = explode(",",$v['product_type']);
  122. $v['parent_type'] = explode(",",$v['parent_type']);
  123. foreach ($v['product_type'] as $key => $value)
  124. {
  125. if(empty($value))
  126. {
  127. $v['product_type'][$key] = $v['parent_type'][$key];
  128. }
  129. }
  130. $v['product_type'] = array_unique($v['product_type']);
  131. $v['product_type'] = implode(",",$v['product_type']);
  132. $sale_array[$v['supplier_id']] = $v;
  133. }
  134. foreach($supplier_array as $k => $v)
  135. {
  136. if(isset($sale_array[$k]))
  137. {
  138. $supplier_array[$k]['product_type'] = $sale_array[$k]['product_type'];
  139. }
  140. else
  141. {
  142. $supplier_array[$k]['product_type'] = '';
  143. }
  144. }
  145. $count_sql = "SELECT
  146. id
  147. FROM
  148. base_supplier
  149. WHERE
  150. cancel_flag = 0
  151. " . $sql_where . "
  152. AND supplier_type = 301";
  153. $result = $pdo->query($count_sql);
  154. $total_page = $result->fetchAll(PDO::FETCH_ASSOC);//获取所有数据
  155. $res['supplier_array'] = $supplier_array;
  156. $res['total_page'] = ceil(count($total_page)/$pagesize);
  157. }
  158. else
  159. {
  160. $json['code'] = '0';
  161. $json['info'] = '没有符合条件的数据';
  162. $json['list'] = array();
  163. $json['count'] = '0';
  164. $json['total_page'] = '0';
  165. echo json_encode($json);
  166. exit();
  167. }
  168. return $res;
  169. }
  170. //处理数据
  171. function tidyData($db_data)
  172. {
  173. global $pdo;
  174. $supplier_array = array();
  175. $area_id_array = array();
  176. $type = array(
  177. 0 => '正常',
  178. 1 => '关闭',
  179. 25 => '酒店',
  180. 255 => '直通巴士',
  181. 256 => '穿梭巴士',
  182. 259 => '车队',
  183. 284 => '城际商务车',
  184. 310 => '巴士',
  185. 311 => '门票'
  186. );
  187. foreach($db_data as $key => $vel)
  188. {
  189. $vel['product_type'] = explode(",",$vel['product_type']);
  190. //获取采购范围的中文
  191. foreach($vel['product_type'] as $k => $v)
  192. {
  193. $vel['product_type'][$k] = $type[$v];
  194. }
  195. $vel['product_type'] = implode(",",$vel['product_type']);
  196. if($vel['manage_type'] == '1')
  197. {
  198. $vel['manage_type'] = '公司';
  199. }
  200. else
  201. {
  202. $vel['manage_type'] = '个人';
  203. }
  204. $supplier_array[$vel['id']] = $vel;
  205. //获取所有的area_id
  206. if(!isset($area_id_array[$vel['area_id']]))
  207. {
  208. $area_id_array[$vel['area_id']] = $vel['area_id'];
  209. }
  210. }
  211. //查询area_id的中文
  212. $area_sql = "SELECT
  213. id,
  214. area_name
  215. FROM
  216. base_area
  217. WHERE
  218. id in(" . implode(",",$area_id_array) . ")";
  219. writeLog("select base_area:" . $area_sql);
  220. $result = $pdo->query($area_sql);
  221. $area_id_array = $result->fetchAll(PDO::FETCH_ASSOC);//获取area中文
  222. foreach($area_id_array as $key => $vel)
  223. {
  224. $area_array[$vel['id']] = $vel['area_name'];
  225. }
  226. foreach($supplier_array as $key => $vel)
  227. {
  228. $supplier_array[$key]['is_disabled'] = $type[$vel['is_disabled']];
  229. $supplier_array[$key]['area_name'] = $area_array[$vel['area_id']];
  230. unset($supplier_array[$key]['area_id']);
  231. }
  232. $supplier_array = array_values($supplier_array);
  233. $json['code'] = '0';
  234. $json['info'] = '返回渠道商列表成功';
  235. $json['list'] = $supplier_array;
  236. $json['count'] = (string)count($supplier_array);
  237. return $json;
  238. }
  239. }
  240. $supplier_name = trim($_POST['supplier_name']);//渠道商名称
  241. $product_type = trim($_POST['product_type']);//销售范围
  242. $is_disabled = trim($_POST['is_disabled']);//状态
  243. $pagesize = trim($_POST['pagesize']);//每页的数据量
  244. $current = trim($_POST['current']);//当前页数
  245. $get_channel_list = new get_channel_list();
  246. $get_channel_list->execGetChannelList($supplier_name, $product_type, $is_disabled,$current,$pagesize);
  247. ?>