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.
 
 
 
 

656 lines
22 KiB

  1. <?php
  2. /**张帅
  3. * 数据汇总
  4. * Class dataInfo
  5. */
  6. class dataInfo extends base
  7. {
  8. /**
  9. * 获取城市
  10. */
  11. public function getArea($param)
  12. {
  13. $area_id = isset($param['area_id'])?trim($param['area_id']):false;//城市id
  14. if(false === $area_id)
  15. {
  16. $json['code'] = '2';
  17. $json['info'] = '缺少必要参数';
  18. return $json;
  19. }
  20. $sql = "SELECT
  21. id,
  22. area_name
  23. FROM
  24. base_area
  25. WHERE
  26. parent_id = " . $area_id;
  27. $area_array = $this->query($sql);
  28. $json['code'] = '0';
  29. $json['info'] = '返回数据成功';
  30. $json['list'] = $area_array;
  31. $json['count'] = (string)count($area_array);
  32. return $json;
  33. }
  34. /**
  35. * 操作联系人
  36. */
  37. public function execLink($param)
  38. {
  39. $operate = isset($param['operate']) ? trim($param['operate']) : '';//操作
  40. $id = isset($param['link_id']) ? trim($param['link_id']) : '';//id
  41. $link_name = isset($param['link_name']) ? trim($param['link_name']) : '';//联系类别
  42. $contact_name = isset($param['contact_name']) ? trim($param['contact_name']) : '';//姓名
  43. $contact_mobile = isset($param['contact_mobile']) ? trim($param['contact_mobile']) : '';//手机
  44. $contact_telphone = isset($param['contact_telphone']) ? trim($param['contact_telphone']) : '';//固话
  45. $fax = isset($param['fax']) ? trim($param['fax']) : '';//传真
  46. $email = isset($param['email']) ? trim($param['email']) : '';//邮箱
  47. $remark = isset($param['remark']) ? trim($param['remark']) : '';//备注
  48. //$is_db 是否为数据库已存的
  49. if ($operate == 'insert') {
  50. $result = $this->insertLink($link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark);
  51. }
  52. if ($operate == 'delete') {
  53. $result = $this->deleteLink($id);
  54. }
  55. if ($operate == 'update') {
  56. $result = $this->updateLink($id, $link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark);
  57. }
  58. if ($operate == 'select') {
  59. $result = $this->selectLink($id);
  60. }
  61. return $result;
  62. }
  63. //增
  64. private function insertLink($link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark)
  65. {
  66. if(!isset($_COOKIE['memcache']))
  67. {
  68. $time = time();
  69. setcookie('memcache',$time,time()+36000,"/");
  70. $_COOKIE['memcache']=$time;
  71. }
  72. $key = $_COOKIE['memcache'];
  73. $link_memcache = $this->get_memcache('ZHANGS_LINK' . $key);
  74. if (!$link_memcache) {
  75. $link_memcache = array();
  76. }
  77. $link_info = array();
  78. $link_info['link_name'] = $link_name;
  79. $link_info['contact_name'] = $contact_name;
  80. $link_info['contact_mobile'] = $contact_mobile;
  81. $link_info['contact_telphone'] = $contact_telphone;
  82. $link_info['fax'] = $fax;
  83. $link_info['email'] = $email;
  84. $link_info['remark'] = $remark;
  85. $link_memcache[] = $link_info;
  86. $id_array = array_keys($link_memcache);
  87. $link_info['link_id'] = (string)end($id_array);//返回id
  88. $link_memcache[$link_info['link_id']] = $link_info;
  89. $this->set_memcache("ZHANGS_LINK" . $key,$link_memcache);
  90. $json['code'] = '0';
  91. $json['info'] = '保存成功';
  92. $json['list'] = $link_info;
  93. return $json;
  94. }
  95. //删
  96. private function deleteLink($id)
  97. {
  98. $key = $_COOKIE['memcache'];
  99. $link_memcache = $this->get_memcache('ZHANGS_LINK' . $key);
  100. unset($link_memcache[$id]);
  101. $this->set_memcache("ZHANGS_LINK" . $key,$link_memcache);
  102. $json['code'] = '0';
  103. $json['info'] = '删除成功';
  104. return $json;
  105. }
  106. //改
  107. private function updateLink($id, $link_name, $contact_name, $contact_mobile, $contact_telphone, $fax, $email, $remark)
  108. {
  109. $key = $_COOKIE['memcache'];
  110. $link_memcache = $this->get_memcache('ZHANGS_LINK' . $key);
  111. $link_info = $link_memcache[$id];
  112. $link_info['link_name'] = $link_name;
  113. $link_info['contact_name'] = $contact_name;
  114. $link_info['contact_mobile'] = $contact_mobile;
  115. $link_info['contact_telphone'] = $contact_telphone;
  116. $link_info['fax'] = $fax;
  117. $link_info['email'] = $email;
  118. $link_info['remark'] = $remark;
  119. $link_memcache[$id] = $link_info;
  120. $this->set_memcache("ZHANGS_LINK" . $key,$link_memcache);
  121. $json['code'] = '0';
  122. $json['info'] = '修改成功';
  123. $json['list'] = $link_info;
  124. return $json;
  125. }
  126. //查
  127. private function selectLink($id)
  128. {
  129. $key = $_COOKIE['memcache'];
  130. $link_memcache = $this->get_memcache('ZHANGS_LINK' . $key);
  131. $link_info = $link_memcache[$id];
  132. $json['code'] = '0';
  133. $json['info'] = '查询成功';
  134. $json['list'] = $link_info;
  135. return $json;
  136. }
  137. /**
  138. * 操作销售方式
  139. */
  140. public function execSale($param)
  141. {
  142. $operate = isset($param['operate']) ? trim($param['operate']) : '';
  143. $sale_id = isset($param['sale_id']) ? trim($param['sale_id']) : '';//id
  144. $prod_supplier_id = isset($param['prod_supplier_id']) ? trim($param['prod_supplier_id']) : '0';//供应商id
  145. $product_type = isset($param['product_type']) ? trim($param['product_type']) : '0';//产品子类(二级类)
  146. $parent_type = isset($param['parent_type']) ? trim($param['parent_type']) : '0';//产品父类(一级类)
  147. $sale_type = isset($param['sale_type']) ? trim($param['sale_type']) : '0';//销售方式
  148. $commision_flag = isset($param['commision_flag']) ? trim($param['commision_flag']) : '0';//是否有佣金规则,1:有,0:无
  149. $commision_type = isset($param['commision_type']) ? trim($param['commision_type']) : '0';//佣金类别
  150. $back_commision_type = isset($param['back_commision_type']) ? ($param['back_commision_type'] == '' ? '0' : trim($param['back_commision_type'])) : '0';//返佣类别
  151. $back_commision_method = isset($param['back_commision_method']) ? ($param['back_commision_method'] == '' ? '0' : trim($param['back_commision_method'])) : '0';//返佣方式
  152. $back_percent = isset($param['back_percent']) ? trim($param['back_percent']) : '0';//返佣比例
  153. $back_value = isset($param['back_value']) ? trim($param['back_value']) : '0';//返佣固定金额
  154. //$is_db 是否为数据库已存的
  155. if ($operate == 'insert') {
  156. $result = $this->insertSale($prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value);
  157. }
  158. if ($operate == 'delete') {
  159. $result = $this->deleteSale($sale_id);
  160. }
  161. if ($operate == 'update') {
  162. $result = $this->updateSale($sale_id, $prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value);
  163. }
  164. if ($operate == 'select') {
  165. $result = $this->selectSale($sale_id);
  166. }
  167. return $result;
  168. }
  169. //增
  170. private function insertSale($prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value)
  171. {
  172. if (!isset($_COOKIE['memcache'])) {
  173. $time = time();
  174. setcookie('memcache', $time, time() + 36000, "/");
  175. $_COOKIE['memcache'] = $time;
  176. }
  177. $key = $_COOKIE['memcache'];
  178. $sale_memcache = $this->get_memcache('ZHANGS_SALE' . $key);
  179. if (!$sale_memcache) {
  180. $sale_memcache = array();
  181. }
  182. if ($back_percent == '' || $back_value == '') {
  183. $json['code'] = '1';
  184. $json['info'] = '请完整填写佣金规则';
  185. echo json_encode($json);
  186. exit();
  187. }
  188. $sale_info = array();
  189. $sale_info['prod_supplier_id'] = $prod_supplier_id;
  190. $sale_info['product_type'] = $product_type;
  191. $sale_info['parent_type'] = $parent_type;
  192. $sale_info['sale_type'] = $sale_type;
  193. $sale_info['commision_flag'] = $commision_flag;
  194. $sale_info['commision_type'] = $commision_type;
  195. $sale_info['back_commision_type'] = $back_commision_type;
  196. $sale_info['back_commision_method'] = $back_commision_method;
  197. $sale_info['back_percent'] = $back_percent;
  198. $sale_info['back_value'] = $back_value;
  199. $sale_memcache[] = $sale_info;
  200. $id_array = array_keys($sale_memcache);
  201. $sale_info['sale_id'] = (string)end($id_array);
  202. $sale_memcache[$sale_info['sale_id']] = $sale_info;
  203. $this->set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
  204. $json['code'] = '0';
  205. $json['info'] = '保存成功';
  206. $json['list'] = $sale_info;
  207. return $json;
  208. }
  209. //删
  210. private function deleteSale($sale_id)
  211. {
  212. $key = $_COOKIE['memcache'];
  213. $sale_memcache = $this->get_memcache('ZHANGS_SALE' . $key);
  214. unset($sale_memcache[$sale_id]);
  215. $this->set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
  216. $json['code'] = '0';
  217. $json['info'] = '删除成功';
  218. return $json;
  219. }
  220. //改
  221. private function updateSale($sale_id, $prod_supplier_id, $product_type, $parent_type, $sale_type, $commision_flag, $commision_type, $back_commision_type, $back_commision_method, $back_percent, $back_value)
  222. {
  223. if ($back_percent == '' || $back_value == '') {
  224. $json['code'] = '1';
  225. $json['info'] = '请完整填写佣金规则';
  226. return $json;
  227. }
  228. $key = $_COOKIE['memcache'];
  229. $sale_memcache = $this->get_memcache('ZHANGS_SALE' . $key);
  230. $sale_info = $sale_memcache[$sale_id];
  231. $sale_info['prod_supplier_id'] = $prod_supplier_id;
  232. $sale_info['product_type'] = $product_type;
  233. $sale_info['parent_type'] = $parent_type;
  234. $sale_info['sale_type'] = $sale_type;
  235. $sale_info['commision_flag'] = $commision_flag;
  236. $sale_info['commision_type'] = $commision_type;
  237. $sale_info['back_commision_type'] = $back_commision_type;
  238. $sale_info['back_commision_method'] = $back_commision_method;
  239. $sale_info['back_percent'] = $back_percent;
  240. $sale_info['back_value'] = $back_value;
  241. $sale_memcache[$sale_id] = $sale_info;
  242. $this->set_memcache("ZHANGS_SALE" . $key, $sale_memcache);
  243. $json['code'] = '0';
  244. $json['info'] = '修改成功';
  245. $json['list'] = $sale_info;
  246. return $json;
  247. }
  248. //查
  249. private function selectSale($sale_id)
  250. {
  251. $key = $_COOKIE['memcache'];
  252. $sale_memcache = $this->get_memcache('ZHANGS_SALE' . $key);
  253. $sale_info = $sale_memcache[$sale_id];
  254. $json['code'] = '0';
  255. $json['info'] = '查询成功';
  256. $json['list'] = $sale_info;
  257. return $json;
  258. }
  259. /**
  260. * 检查供应商或渠道商名字
  261. * @param $param
  262. */
  263. public function checkSupplierName($param)
  264. {
  265. $supplier_type = isset($param['supplier_type'])?trim($param['supplier_type']):false;
  266. $supplier_name = isset($param['supplier_name'])?trim($param['supplier_name']):false;
  267. $supplier_id = empty($param['supplier_id'])?'':" and id != " . trim($param['supplier_id']);
  268. if(!$supplier_type || !$supplier_name){
  269. $json['code'] = '2';
  270. $json['info'] = '缺少必要参数';
  271. return $json;
  272. }
  273. $sql = "SELECT
  274. supplier_name
  275. FROM
  276. base_supplier
  277. WHERE
  278. cancel_flag = 0
  279. AND supplier_name = '" . $supplier_name . "' AND supplier_type={$supplier_type} " . $supplier_id;
  280. $check_name = $this->query($sql);
  281. if(count($check_name) > 0)
  282. {
  283. $json['code'] = '1';
  284. $json['info'] = '用户名已存在';
  285. }
  286. else
  287. {
  288. $json['code'] = '0';
  289. $json['info'] = '用户名可用';
  290. }
  291. return $json;
  292. }
  293. /**
  294. * 操作账户
  295. * @param $param
  296. */
  297. public function execUser($param)
  298. {
  299. $operate = isset($param['operate']) ? trim($param['operate']) : false;
  300. $supplier_id = isset($param['supplier_id']) ? trim($param['supplier_id']) : '';//供应商或渠道商id
  301. $user_name = isset($param['user_name']) ? trim($param['user_name']) : '';//用户名
  302. $true_name = isset($param['true_name']) ? trim($param['true_name']) : '';//真实姓名
  303. $phone_no = isset($param['phone_no']) ? trim($param['phone_no']) : '';//手机号
  304. $user_id = isset($param['user_id']) ? trim($param['user_id']) : '';//用户id
  305. if($operate == 'check')//获得账号列表
  306. {
  307. $result = $this -> checkUserName($user_id,$user_name,'check');
  308. }
  309. if($operate == 'insert')//新增数据
  310. {
  311. $result = $this -> insertUser($supplier_id,$user_name,$true_name,$phone_no);
  312. }
  313. if($operate == 'list')//获得账号列表
  314. {
  315. $result = $this -> getListUser($supplier_id);
  316. }
  317. if($operate == 'stop')//停用
  318. {
  319. $result = $this -> stopUser($user_id);
  320. }
  321. if($operate == 'start')//启用
  322. {
  323. $result = $this -> startUser($user_id);
  324. }
  325. if($operate == 'delete')//删除
  326. {
  327. $result = $this -> deleteUser($user_id);
  328. }
  329. if($operate == 'detail')//获取详情
  330. {
  331. $result = $this -> detailUser($user_id);
  332. }
  333. if($operate == 'update')//修改账号
  334. {
  335. $result = $this -> updateUser($user_id,$user_name,$true_name,$phone_no);
  336. }
  337. if($operate == 'update_password')//初始化密码
  338. {
  339. $result = $this -> updateUserPassword($user_id);
  340. }
  341. return $result;
  342. }
  343. //新增用户
  344. private function insertUser($supplier_id,$user_name,$true_name,$phone_no)
  345. {
  346. if(empty($supplier_id) || empty($user_name) || empty($true_name) || empty($phone_no))
  347. {
  348. $json['code'] = '1';
  349. $json['info'] = '必填项不可为空';
  350. return $json;
  351. }
  352. $check_result = $this -> checkUserName('',$user_name,'insert_check');
  353. if(isset($check_result['code']) && $check_result['code'] != '0')
  354. {
  355. return $check_result;
  356. }
  357. $user_id = $this->user_id;
  358. $time = date('Y-m-d H:i:s',time());
  359. $id_sql = "select max(id) as id from base_user";
  360. $id = $this->query($id_sql);
  361. $id = $id[0]['id'];
  362. $id = $id+1;
  363. $main_corp_id_sql = "select main_corp_id from base_supplier where id = " . $supplier_id . ' and cancel_flag = 0 limit 1';
  364. $main_corp_id = $this->query($main_corp_id_sql);
  365. $main_corp_id = $main_corp_id[0]['main_corp_id'];
  366. $password = md5('zzcx8888');
  367. $sql = "INSERT INTO base_user (
  368. create_user_id,
  369. create_time,
  370. id,
  371. user_name,
  372. org_id,
  373. top_org_id,
  374. user_password,
  375. true_name,
  376. phone_no,
  377. `status`,
  378. main_corp_id
  379. )
  380. VALUE
  381. (" . $user_id . ", '" . $time . "'," . $id . ",'" . $user_name . "', " . $supplier_id . ", " . $supplier_id . ", '" . $password . "', '" . $true_name . "', '" . $phone_no . "',0," . $main_corp_id . ")";
  382. $result = $this->exec($sql);
  383. if($result)
  384. {
  385. $json['code'] = '0';
  386. $json['info'] = '插入成功';
  387. }
  388. else
  389. {
  390. $json['code'] = '1';
  391. $json['info'] = '系统原因插入失败';
  392. }
  393. return $json;
  394. }
  395. //检验用户名
  396. private function checkUserName($user_id,$user_name,$check_type)
  397. {
  398. if(empty($user_id))
  399. {
  400. $sql = "SELECT
  401. user_name
  402. FROM
  403. base_user
  404. WHERE
  405. cancel_flag = 0
  406. AND user_name = '" . $user_name . "'";
  407. }
  408. else
  409. {
  410. $sql = "SELECT
  411. user_name
  412. FROM
  413. base_user
  414. WHERE
  415. cancel_flag = 0
  416. AND id != " . $user_id . "
  417. AND user_name = '" . $user_name . "'";
  418. }
  419. $res = $this->query($sql);
  420. if(count($res) > 0)
  421. {
  422. $json['code'] = '1';
  423. $json['info'] = '用户名已存在';
  424. return $json;
  425. }
  426. else
  427. {
  428. if($check_type == 'check')
  429. {
  430. $json['code'] = '0';
  431. $json['info'] = '用户名可用';
  432. return $json;
  433. }
  434. else
  435. {
  436. return true;
  437. }
  438. }
  439. }
  440. //获得账号列表
  441. private function getListUser($supplier_id)
  442. {
  443. $sql = "SELECT
  444. id,true_name,`status`
  445. FROM
  446. base_user
  447. WHERE
  448. cancel_flag = 0
  449. AND org_id = " . $supplier_id;
  450. $res = $this->query($sql);
  451. if(count($res) > 0)
  452. {
  453. foreach($res as $k => $v)
  454. {
  455. if($v['status'] == 0)
  456. {
  457. $res[$k]['status'] = '停用';
  458. }
  459. else
  460. {
  461. $res[$k]['status'] = '启用';
  462. }
  463. }
  464. }
  465. $json['code'] = '0';
  466. $json['info'] = '用户名可用';
  467. $json['list'] = $res;
  468. return $json;
  469. }
  470. //停用账号
  471. private function stopUser($user_id)
  472. {
  473. $userId = $this->user_id;
  474. $time = date('Y-m-d H:i:s',time());
  475. $sql = "UPDATE base_user
  476. SET `status` = 1,
  477. update_user_id = " . $userId . ",
  478. update_time = '" . $time . "'
  479. WHERE
  480. id = " .$user_id;
  481. $result = $this->exec($sql);
  482. if($result)
  483. {
  484. $json['code'] = '0';
  485. $json['info'] = '停用成功';
  486. }
  487. else {
  488. $json['code'] = '1';
  489. $json['info'] = '系统原因停用失败';
  490. }
  491. return $json;
  492. }
  493. //启用账号
  494. private function startUser($user_id)
  495. {
  496. $userId = $this->user_id;
  497. $time = date('Y-m-d H:i:s',time());
  498. $sql = "UPDATE base_user
  499. SET `status` = 0,
  500. update_user_id = " . $userId . ",
  501. update_time = '" . $time . "'
  502. WHERE
  503. id = " .$user_id;
  504. $result = $this->exec($sql);
  505. if($result)
  506. {
  507. $json['code'] = '0';
  508. $json['info'] = '启用成功';
  509. }
  510. else {
  511. $json['code'] = '1';
  512. $json['info'] = '系统原因启用失败';
  513. }
  514. return $json;
  515. }
  516. //删除账号
  517. private function deleteUser($user_id)
  518. {
  519. $userId = $this->user_id;
  520. $time = date('Y-m-d H:i:s',time());
  521. $sql = "UPDATE base_user
  522. SET cancel_flag = 1,
  523. update_user_id = " . $userId . ",
  524. update_time = '" . $time . "'
  525. WHERE
  526. id = " .$user_id;
  527. $result = $this->exec($sql);
  528. if($result)
  529. {
  530. $json['code'] = '0';
  531. $json['info'] = '删除成功';
  532. }
  533. else {
  534. $json['code'] = '1';
  535. $json['info'] = '系统原因删除失败';
  536. }
  537. return $json;
  538. }
  539. //获取详情
  540. private function detailUser($user_id)
  541. {
  542. $sql = "SELECT
  543. id,user_name,true_name,phone_no
  544. FROM
  545. base_user
  546. WHERE
  547. cancel_flag = 0
  548. AND id = " . $user_id;
  549. $res = $this->query($sql);
  550. if(count($res) > 0)
  551. {
  552. $json['code'] = '0';
  553. $json['info'] = '获取信息成功';
  554. $json['list'] = $res;
  555. }
  556. else
  557. {
  558. $json['code'] = '1';
  559. $json['info'] = '该数据已删除';
  560. }
  561. return $json;
  562. }
  563. //修改账号
  564. private function updateUser($user_id,$user_name,$true_name,$phone_no)
  565. {
  566. $userId = $this->user_id;
  567. $time = date('Y-m-d H:i:s',time());
  568. if(empty($user_id) || empty($user_name) || empty($true_name) || empty($phone_no))
  569. {
  570. $json['code'] = '1';
  571. $json['info'] = '必填项不可为空';
  572. return $json;
  573. }
  574. $check_result = $this -> checkUserName($user_id,$user_name,'update_check');
  575. if(isset($check_result['code']) && $check_result['code'] != '0')
  576. {
  577. return $check_result;
  578. }
  579. $sql = "UPDATE base_user
  580. SET user_name = '" . $user_name . "',
  581. true_name = '" . $true_name . "',
  582. phone_no = '" . $phone_no . "',
  583. update_user_id = " . $userId . ",
  584. update_time = '" . $time . "'
  585. WHERE
  586. id = " . $user_id;
  587. $result = $this->exec($sql);
  588. if($result)
  589. {
  590. $json['code'] = '0';
  591. $json['info'] = '修改成功';
  592. }
  593. else {
  594. $json['code'] = '1';
  595. $json['info'] = '系统原因修改失败';
  596. }
  597. return $json;
  598. }
  599. //重置密码
  600. private function updateUserPassword($user_id)
  601. {
  602. $userId = $this->user_id;
  603. $time = date('Y-m-d H:i:s',time());
  604. $sql = "UPDATE base_user
  605. SET user_password = '" . md5('Zzcx888') . "',
  606. update_user_id = " . $userId . ",
  607. update_time = '" . $time . "'
  608. WHERE
  609. id = " . $user_id;
  610. $result = $this->exec($sql);
  611. if($result)
  612. {
  613. $json['code'] = '0';
  614. $json['info'] = '初始化密码成功';
  615. }
  616. else {
  617. $json['code'] = '1';
  618. $json['info'] = '系统原因初始化密码失败';
  619. }
  620. return $json;
  621. }
  622. }
  623. ?>