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.
 
 
 
 

270 lines
9.6 KiB

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