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.
 
 
 
 

257 lines
10 KiB

  1. <?php
  2. /*
  3. * 添加渠道商
  4. * author:张帅
  5. */
  6. class add_channel
  7. {
  8. //添加主要流程
  9. function execAddChannel($supplier_name, $area_id, $manage_type, $company_name, $id_card, $sale, $sett_type, $sett_frequency, $account_bank, $account_num, $account_name, $link_info, $sales_man)
  10. {
  11. global $pdo;
  12. $sql = "SELECT
  13. supplier_name
  14. FROM
  15. base_supplier
  16. WHERE
  17. cancel_flag = 0
  18. AND supplier_name = '" . $supplier_name . "' AND supplier_type=301 ";
  19. writeLog("check base_supplier:" . $sql);
  20. $result = $pdo->query($sql);
  21. $check_name = $result->fetchAll(PDO::FETCH_ASSOC);
  22. if(count($check_name) > 0)
  23. {
  24. $json['code'] = '1';
  25. $json['info'] = '用户名已存在';
  26. echo json_encode($json);
  27. exit();
  28. }
  29. //1.获取销售方式详情数组
  30. $sale_array = $this->getSale($sale);
  31. //2.获取联系人详情数组
  32. $link_array = $this->getLinkInfo($link_info);
  33. //3.判断必填数据是否为空
  34. $judgeData = $this->judgeData($supplier_name, $manage_type, $area_id, $company_name, $sett_type, $sett_frequency, $sales_man);
  35. if ($judgeData['code'] == '1') {
  36. echo json_encode($judgeData);
  37. exit();
  38. }
  39. //4.向数据库中中添加数据
  40. $res = $this->addPdoChannel($supplier_name, $area_id, $manage_type, $company_name, $id_card, $sale_array, $sett_type, $sett_frequency, $account_bank, $account_num, $account_name, $link_array, $sales_man);
  41. echo json_encode($res);
  42. exit();
  43. }
  44. //获取销售方式详情数组
  45. function getSale($sale)
  46. {
  47. if ($sale == '') {
  48. $sale_array = array();
  49. return $sale_array;
  50. }
  51. $sale = explode(",", $sale);
  52. $key = $_COOKIE['memcache'];
  53. $sale_memcache = get_memcache('ZHANGS_SALE' . $key);
  54. $i = 0;
  55. foreach ($sale as $item => $value) {
  56. $sale_array[$i] = $sale_memcache[$value];
  57. $i++;
  58. }
  59. return $sale_array;
  60. }
  61. //获取联系人详情数组
  62. function getLinkInfo($link_info)
  63. {
  64. if ($link_info == '') {
  65. $link_array = array();
  66. return $link_array;
  67. }
  68. $link_info = explode(",", $link_info);
  69. $key = $_COOKIE['memcache'];
  70. $link_memcache = get_memcache('ZHANGS_LINK' . $key);
  71. $i = 0;
  72. foreach ($link_info as $item => $value) {
  73. $status = 0;
  74. if (empty($link_memcache[$value]['link_name']) || empty($link_memcache[$value]['contact_name'])) {
  75. $status = 1;
  76. }
  77. if ($status == 0) {
  78. $link_array[$i] = $link_memcache[$value];
  79. $i++;
  80. }
  81. }
  82. return $link_array;
  83. }
  84. //检查必填数据是否为空
  85. function judgeData($supplier_name, $manage_type, $area_id, $company_name, $sett_type, $sett_frequency, $sales_man)
  86. {
  87. if (empty($supplier_name)) {
  88. $json['code'] = '1';
  89. $json['info'] = '供应商名称不能为空';
  90. } elseif (empty($area_id)) {
  91. $json['code'] = '1';
  92. $json['info'] = '供应商区域不能为空';
  93. } elseif (empty($manage_type)) {
  94. $json['code'] = '1';
  95. $json['info'] = '经营性质';
  96. } elseif (empty($company_name)) {
  97. $json['code'] = '1';
  98. $json['info'] = '供应商公司不能为空';
  99. } elseif (empty($sett_type)) {
  100. $json['code'] = '1';
  101. $json['info'] = '结算方式不能为空';
  102. } elseif (empty($sett_frequency)) {
  103. $json['code'] = '1';
  104. $json['info'] = '结算周期名称不能为空';
  105. } elseif (empty($sales_man)) {
  106. $json['code'] = '1';
  107. $json['info'] = '业务员不能为空';
  108. } else {
  109. $json['code'] = '0';
  110. $json['info'] = '成功';
  111. }
  112. return ($json);
  113. }
  114. //在数据库中添加供应商信息
  115. function addPdoChannel($supplier_name, $area_id, $manage_type, $company_name, $id_card, $sale_array, $sett_type, $sett_frequency, $account_bank, $account_num, $account_name, $link_array, $sales_man)
  116. {
  117. global $pdo;
  118. $user_id = getUserId();//$_COOKIE['user_id'];
  119. //运营主体
  120. $main_corp_id_sql = "select main_corp_id from base_user where id = " . $user_id . ' and cancel_flag = 0 limit 1';
  121. $result = $pdo->query($main_corp_id_sql);
  122. $main_corp_id = $result->fetchAll(PDO::FETCH_ASSOC);
  123. $main_corp_id = $main_corp_id[0]['main_corp_id'];
  124. $time = date('Y-m-d H:i:s', time());
  125. try {
  126. $pdo->beginTransaction();
  127. //1.添加base_supplier表
  128. $supplier_sql = "INSERT INTO base_supplier (
  129. create_user_id,
  130. create_time,
  131. supplier_type,
  132. supplier_name,
  133. area_id,
  134. manage_type,
  135. company_name,
  136. id_card,
  137. is_disabled,
  138. sett_type,
  139. sett_frequency,
  140. account_bank,
  141. account_num,
  142. account_name,
  143. sales_man,
  144. main_corp_id
  145. )
  146. VALUES
  147. (" . $user_id . ",'" . $time . "',301,'" . $supplier_name . "'," . $area_id . "," . $manage_type . ",'" . $company_name . "','" . $id_card . "',0," . $sett_type . "," . $sett_frequency . ",'" . $account_bank . "','" . $account_num . "','" . $account_name . "','" . $sales_man . "'," . $main_corp_id .")";
  148. writeLog("INSERT INTO base_supplier:" . $supplier_sql);
  149. $result = $pdo->exec($supplier_sql);
  150. if (!$result) {
  151. throw new Exception("db die");
  152. }
  153. $supplier_id = $pdo->lastInsertId();
  154. //2.添加base_supplier_sale表
  155. if (count($sale_array) > 0) {
  156. $sale_sql = "INSERT INTO base_supplier_sale (
  157. create_user_id,
  158. create_time,
  159. supplier_id,
  160. prod_supplier_id,
  161. product_type,
  162. parent_type,
  163. sale_type,
  164. commision_flag,
  165. commision_type,
  166. back_commision_type,
  167. back_commision_method,
  168. back_percent,
  169. back_value
  170. )
  171. VALUES ";
  172. foreach ($sale_array as $key => $v) {
  173. $sale_sql_array[] = "(" . $user_id . ",'" . $time . "'," . $supplier_id . "," . $v['prod_supplier_id'] . "," . $v['product_type'] . "," . $v['parent_type'] . "," . $v['sale_type'] . "," . $v['commision_flag'] . "," . $v['commision_type'] . "," . $v['back_commision_type'] . "," . $v['back_commision_method'] . ",'" . $v['back_percent'] . "','" . $v['back_value'] . "')";
  174. }
  175. $sale_sql .= implode(",", $sale_sql_array);
  176. writeLog("INSERT INTO base_supplier_purchase:" . $sale_sql);
  177. $result = $pdo->exec($sale_sql);
  178. if (!$result) {
  179. throw new Exception("db die");
  180. }
  181. }
  182. //3.添加base_supplier_link表
  183. if (count($link_array) > 0) {
  184. $link_sql = "INSERT INTO base_supplier_link (
  185. create_user_id,
  186. create_time,
  187. supplier_id,
  188. link_name,
  189. contact_name,
  190. contact_mobile,
  191. contact_telphone,
  192. fax,
  193. email,
  194. remark
  195. )
  196. VALUES ";
  197. foreach ($link_array as $key => $v) {
  198. $link_sql_array[] = "(" . $user_id . ",'" . $time . "'," . $supplier_id . ",'" . $v['link_name'] . "','" . $v['contact_name'] . "','" . $v['contact_mobile'] . "','" . $v['contact_telphone'] . "','" . $v['fax'] . "','" . $v['email'] . "','" . $v['remark'] . "')";
  199. }
  200. $link_sql .= implode(",", $link_sql_array);
  201. writeLog("INSERT INTO base_supplier_link:" . $link_sql);
  202. $result = $pdo->exec($link_sql);
  203. if (!$result) {
  204. throw new Exception("db die");
  205. }
  206. }
  207. $pdo->commit();
  208. //4.删除缓存
  209. $key = $_COOKIE['memcache'];
  210. delete_memcache('ZHANGS_LINK' . $key);
  211. delete_memcache('ZHANGS_SALE' . $key);
  212. $json['code'] = '0';
  213. $json['info'] = '添加数据成功';
  214. } catch (PDOException $ex) {
  215. $pdo->rollBack();
  216. $json['code'] = '1';
  217. $json['info'] = '添加失败';
  218. }
  219. return $json;
  220. }
  221. }
  222. $supplier_name = trim($_POST['supplier_name']);//渠道商名称
  223. $area_id = trim($_POST['area_id']);//所属区域市id
  224. $manage_type = trim($_POST['manage_type']);//经营性质 1:公司 2:个人
  225. $company_name = trim($_POST['company_name']);//公司名称
  226. $id_card = trim($_POST['id_card']);//身份证号(企业传空)
  227. $sale = trim($_POST['sale']);//销售方式
  228. $sett_type = trim($_POST['sett_type']);//结算方式 (授信:275,预付:288,单结:292)
  229. $sett_frequency = trim($_POST['sett_frequency']);//结算周期(日结:293,周结:294,月结:295)
  230. $account_bank = trim($_POST['account_bank']);//开户银行
  231. $account_num = trim($_POST['account_num']);//银行账号
  232. $account_name = trim($_POST['account_name']);//账号名称
  233. $link_info = trim($_POST['link_info']);//联系人详情
  234. $sales_man = trim($_POST['sales_man']);//业务员
  235. $add_supply = new add_channel();
  236. $add_supply->execAddChannel($supplier_name, $area_id, $manage_type, $company_name, $id_card, $sale, $sett_type, $sett_frequency, $account_bank, $account_num, $account_name, $link_info, $sales_man);
  237. ?>