优惠券订单及其他脚本

scan_orderv3_pullNew.php 43KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'TBK.class.php';
  4. require_once 'confv2.class.php';
  5. define("DETAILDEBUG", 0);//打印流程详细信息,如有需要,设为1
  6. define("LIMIT_NUM", 0);//限制导入条数,0不限制,方便测试,上线设为0
  7. define("PUSH_URL",'https://tbk.726p.com/api/v2/MessagePush/rebatepush');//push接口地址
  8. define("ACT_PUSH_URL",'https://tbk.726p.com/api/v2/MessagePush/pullnew_push');//拉新push接口地址
  9. define("ACT_START", '2018-12-25 00:00:00');//
  10. define("ACT_END", '2018-12-31 23:59:59');//
  11. define("ACT_GOODS_IMG", 'http://imgs.726p.com/tbk/upload/advImg2018-12-24/135037/kx-5c2073adbe478.png');//
  12. /**
  13. * 导入及更新 order/order_rebate数据 + 淘宝拉新活动
  14. */
  15. #设置时区
  16. date_default_timezone_set('PRC');
  17. set_time_limit(0);
  18. ini_set('memory_limit','1024M');
  19. function readDataFromDb(){
  20. # 记录脚本开始时间
  21. $scriptStart = date("Y-m-d H:i:s");
  22. # 1.获取8分钟内订单
  23. //$stime = date('Y-m-d H:i:s',strtotime('2018-08-07'));
  24. $stime = date('Y-m-d H:i:s', time()-360);
  25. $sql = "SELECT * from ftxia_taoke_detail2 where update_time > :stime and adv_name like 'api_%' order by create_time asc,order_sn asc";
  26. $dumpsql = str_replace(':stime', "'".$stime."'", $sql);
  27. echo "\n\n".$dumpsql."\n";
  28. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  29. $stmt = $_PDO->prepare($sql);
  30. $stmt->execute(array(':stime'=>$stime));
  31. $orderResult = $stmt->fetchAll(PDO::FETCH_ASSOC);
  32. # 遍历订单
  33. # 统计
  34. $res_count = array(
  35. 'total_num' => 0,
  36. 'generalinsert_num' => 0,
  37. 'generalupdate_num' => 0,
  38. 'nouserinsert_num' => 0,
  39. 'nouserupdate_num' => 0,
  40. 'fail_insert_num' => 0,
  41. 'fail_insert_ids' => '',
  42. 'fail_insertno_num' => 0,
  43. 'fail_insertno_ids' => '',
  44. 'fail_update_num' => 0,
  45. //'fail_update_ids' => '',
  46. 'fail_updateno_num' => 0,
  47. //'fail_updateno_ids' => '',
  48. );
  49. $orderList = array();
  50. $rewardOrder = array(); //拉新订单记录
  51. $nums = 0;
  52. foreach( $orderResult as $key=>$orderDetail ){
  53. $nums++;
  54. $res_count['total_num']++;
  55. echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
  56. if( DETAILDEBUG == 1){
  57. echo 'orderDetail:';
  58. }
  59. $order_id=$orderDetail["order_sn"];
  60. $update_time=$orderDetail["update_time"];
  61. $order_create_at=$orderDetail["create_time"];
  62. $order_click_at=$orderDetail["click_time"];
  63. $order_balance_at=$orderDetail["balance_time"];
  64. $goods_id=$orderDetail["goods_id"];
  65. $goods_name=$orderDetail["goods_name"];
  66. $goods_name=str_replace(['"',"'"],'',$goods_name);
  67. $num=$orderDetail["goods_number"];
  68. $price=intval($orderDetail["goods_price"]*100);
  69. $sum_price=intval($orderDetail["order_amount"]*100);
  70. $statusDesc=$orderDetail["order_status"];
  71. $typeDesc=$orderDetail["order_type"];
  72. $orderStatus = 1;
  73. $type=1;
  74. if($statusDesc=="订单付款"){
  75. $orderStatus=1;
  76. }
  77. elseif($statusDesc=="订单失效"){
  78. $orderStatus=0;
  79. }
  80. elseif($statusDesc=="订单结算"){
  81. $orderStatus=2;
  82. }
  83. if($typeDesc=="聚划算"){
  84. $type=0;
  85. }
  86. elseif($typeDesc=="淘宝"){
  87. $type=1;
  88. }
  89. elseif($typeDesc=="天猫"){
  90. $type=2;
  91. }
  92. $adzone_id=$orderDetail["adv_id"];
  93. $ceil_income=round($orderDetail["effect_prediction"], 2);
  94. $predict_income=$ceil_income*100;
  95. $predict_income=ceil($predict_income*conf::$RATE_CONF["globalzk"]);
  96. echo 'order_id:'.$order_id.'|| goods_id:'.$goods_id.'|| orderstatus:'.$orderStatus.'|| order_balance_at:'.$order_balance_at.'|| update_time:'.$update_time;
  97. echo '|| predict_income:'.$predict_income.'|| adzone_id:'.$adzone_id."\n";
  98. $resultone=UserInfo($adzone_id);
  99. if( DETAILDEBUG == 1){
  100. echo 'userinfo:';
  101. var_dump($resultone);
  102. echo "\n";
  103. }
  104. if($sum_price!=0){
  105. if($predict_income<5){
  106. $predict_income=5;
  107. }
  108. }
  109. if( !empty($resultone) ){
  110. echo "User:存在\n";
  111. $orderExists=orderMysql($order_id,$goods_id);
  112. if( empty($orderExists) || in_array($order_id,$orderList)){
  113. echo "action:插入操作\n";
  114. #获取层级规则信息
  115. $userAllInfo=userLevelandPrentInfo($resultone);
  116. echo "<pre>\nuserAllInfo";
  117. print_r($userAllInfo);
  118. if( DETAILDEBUG == 1){
  119. echo 'userallinfo:'."\n";
  120. var_dump($userAllInfo);
  121. }
  122. $userList = $userAllInfo['userList']; //4层 每层userId
  123. $userLevel = $userAllInfo['userLevel']; //4层 每层userlevel
  124. # 从数据库获取规则
  125. $rebateRuleInfo = getRebateRule($userAllInfo['levelRule']);
  126. echo "\nRuleInfo:";
  127. print_r($rebateRuleInfo);
  128. $RuleArr = explode(',',$rebateRuleInfo['rebate_rule']); //4层 每层分佣比例
  129. $TypeArr = explode(',',$rebateRuleInfo['rebate_type']); //4层 每层分佣级别
  130. #获取每一层返利
  131. $moneyInfo=orderMoney($predict_income, $RuleArr); //4层 每层分佣钱数
  132. echo "\nmoneyInfo:";
  133. print_r($moneyInfo);
  134. if( DETAILDEBUG == 1){
  135. echo 'rebateInfo'."\n";
  136. var_dump($moneyInfo);
  137. }
  138. $detail = TBK::tbkItemInfoGet( ['goods_id'=>$goods_id] );
  139. if( !empty($detail) ){
  140. $goods_img=$detail->pict_url;
  141. }
  142. else{
  143. $goods_img="";
  144. }
  145. try{
  146. $_PDO->beginTransaction();
  147. #订单表插入
  148. $res=generateSqlInsertOrder($goods_img,$goods_name,$userList[0],$order_id,$adzone_id,$goods_id,$num,$price,$sum_price,$predict_income,$moneyInfo[0],$orderStatus,$type,$userLevel[0],$order_create_at,$order_click_at,$order_balance_at);
  149. if($res){
  150. $orderList[] = $order_id;
  151. $res_count['generalinsert_num']++;
  152. }else{
  153. $res_count['fail_insert_num']++;
  154. $res_count['fail_insert_ids'].=$order_id.'|';
  155. }
  156. echo 'orderinsert:'.$res;
  157. echo "\n";
  158. if($sum_price>=0 and $orderStatus!=0){
  159. foreach($moneyInfo as $k=>$v){
  160. if($v>0){
  161. #order_rebate表插入父级佣金
  162. $rebaseType=$TypeArr[$k];
  163. $res=generateSqlInsertRebateSelf($userLevel[$k],$order_balance_at,$order_create_at,$goods_img,$goods_name,$order_id,$userList[$k],$rebaseType,$moneyInfo[$k],$sum_price,$orderStatus,$goods_id,$predict_income);
  164. # 推送
  165. if($res){
  166. $params = array();
  167. $params['user_id'] = $userList[$k];
  168. $params['type'] = 2;
  169. $params['money'] = round($moneyInfo[$k]/100,2);
  170. $push_res = curl_post( PUSH_URL, $params);
  171. }
  172. echo 'rebateinsert_'.$k.':'.$res;
  173. echo "\n";
  174. }
  175. }
  176. if($order_create_at >= ACT_START && $order_create_at <= ACT_END){
  177. # 判断是否是拉新首单
  178. $isNew = 0;
  179. $isTooNew = 0;
  180. if(array_key_exists($order_id, $rewardOrder)){
  181. $isTooNew = 1;
  182. }else{
  183. $isNew = isNewUser($userList[0]);
  184. }
  185. if($isTooNew || $isNew){
  186. //记录拉新订单分佣情况
  187. if($isNew){
  188. $rewardOrder[$order_id] = $moneyInfo;
  189. }else{
  190. $rewardOrder[$order_id] = arraySums($rewardOrder[$order_id],$moneyInfo);
  191. }
  192. //获取下一个分佣的订单
  193. $nkey = $nums;
  194. //若当前订单和下一笔订单号一样,继续循环,直到本拉新订单分佣rewardOrder[$order_id]统计完毕
  195. if(isset($orderResult[$nkey]['order_sn']) && $order_id == $orderResult[$nkey]['order_sn']){
  196. }else{
  197. // 分奖励佣金 < --------- Start --------- >
  198. $reward_n = 0; // 记录奖励层数 最多两层
  199. $rewardInfo = $rewardOrder[$order_id]; //本订单实际分佣情况
  200. foreach($rewardInfo as $k=>$v){
  201. if($v>0 && $reward_n<2){
  202. # 插入奖励
  203. $rebaseType=6; //奖励佣金
  204. # 计算奖励佣金
  205. $reward = getReward($rewardInfo[$k]);
  206. $goods_name_new = $k==0 ? '恭喜您获得新用户首单奖励' : '恭喜您获得拉新首单奖励';
  207. $goods_img_new = ACT_GOODS_IMG;
  208. $res=rewardOrderInsert($userLevel[$k],$order_balance_at,$order_create_at,$goods_img_new,$goods_name_new,$order_id,$userList[$k],$rebaseType,$reward,$sum_price,$orderStatus,$goods_id,$predict_income);
  209. # 奖励推送
  210. if($res){
  211. $params = array();
  212. $params['user_id'] = $userList[$k];
  213. $params['type'] = $k==0 ? 3 : 4; //奖励推送 3新人 4上级
  214. $params['money'] = round($reward/100,2);
  215. $push_res = curl_post( ACT_PUSH_URL, $params);
  216. }
  217. echo 'rewardinsert_'.$reward_n.':'.$res;
  218. echo "\n";
  219. # 记录奖励层数
  220. $reward_n++;
  221. }
  222. }
  223. # 记录新人首单信息
  224. if($res){
  225. //获取运营商
  226. $m = strpos($userAllInfo['levelRule'], '3');
  227. $operate_id = $userList[$m];
  228. $res2 = pullNewInsert($userList[0],$operate_id,$order_id,$order_create_at,$orderStatus);
  229. //获取当前运营商拉新人数
  230. $pullCount = getPullNew($operate_id);
  231. if($pullCount==10 || $pullCount==20 || $pullCount==30){
  232. //符合推送条件
  233. $params = array();
  234. $params['user_id'] = $operate_id;
  235. $params['type'] = 5; //运营商拉新人数推送
  236. $params['count'] = $pullCount;
  237. $push_res = curl_post( ACT_PUSH_URL, $params);
  238. }
  239. }
  240. }
  241. }
  242. }
  243. }
  244. //津贴单独计算
  245. # 获取顶级运营商-控制中心
  246. if($sum_price>0 and $orderStatus !=0){
  247. $mks = strpos($userAllInfo['levelRule'], '3');
  248. if($mks !== false){
  249. $YysManageInfo = YysManageInfo( $userList[$mks] );
  250. if( !empty($YysManageInfo) ){
  251. $rebaseType=$TypeArr[$mks];
  252. $YysManageRabate = round($predict_income*conf::$RATE_CONF["YysManage"]);
  253. if($YysManageRabate < 1){
  254. $YysManageRabate = 1;
  255. }
  256. $res = YysManageInsertRebate(4,$order_balance_at,$order_create_at,$goods_img,$goods_name,$order_id,$YysManageInfo['user_id'],$rebaseType,$YysManageRabate,$sum_price,$orderStatus,$goods_id,$predict_income);
  257. echo 'rebateinsert_YysManage:'.$res;
  258. echo "\n";
  259. }
  260. }
  261. }
  262. $_PDO->commit();
  263. }catch(PDOException $e){
  264. echo 'err_msg'.$e->getMessage()."\n";
  265. $_PDO->rollback();
  266. }
  267. //echo "-----------------insertEnd--------------------\n";
  268. }
  269. else{
  270. try{
  271. $_PDO->beginTransaction();
  272. //更新order/order_rebate表
  273. echo "action:更新操作\n";
  274. $res=generateSqlupdate($orderStatus,$order_balance_at,$order_id,$goods_id);
  275. /*** 增加拉新更新 Start ***/
  276. if($order_create_at >= ACT_START && $order_create_at <= ACT_END){
  277. $isUpOk = pullNewIsUpOk($orderStatus, $order_id, $resultone['user_id']);
  278. echo 'isUpOk:'.$isUpOk."\n";
  279. if($isUpOk) $pull_up = pullNewUpdate($orderStatus, $order_id);
  280. }
  281. /*** 增加拉新更新 End ***/
  282. if($res){
  283. $res_count['generalupdate_num']++;
  284. }else{
  285. $res_count['fail_update_num']++;
  286. //$res_count['fail_update_ids'].=$order_id.'|';
  287. }
  288. echo "更新数据-> orderstatus:".$orderStatus." order_balance_at:".$order_balance_at;
  289. echo "\n";
  290. echo "order/reabte_update:".$res;
  291. echo "\n";
  292. //echo "-----------------updateEnd-----------------------\n";
  293. $_PDO->commit();
  294. }catch(PDOException $e){
  295. echo 'err_msg'.$e->getMessage()."\n";
  296. $_PDO->rollback();
  297. }
  298. }
  299. //echo "-----------------IssetUserEnd:--------------------\n";
  300. }
  301. else{
  302. $_PDO->beginTransaction();
  303. try{
  304. #user不存在的处理
  305. echo "User:不存在\n";
  306. $ordernoExists=orderMysql($order_id,$goods_id);
  307. if( empty($ordernoExists) ){
  308. $detail = TBK::tbkItemInfoGet( ['goods_id'=>$goods_id] );
  309. if( !empty($detail) ){
  310. $goods_img=$detail->pict_url;
  311. }
  312. else{
  313. $goods_img="";
  314. }
  315. $res=generateSqlInsertOrderOther($goods_img,$goods_name,$order_id,$adzone_id,$goods_id,$num,$price,$sum_price,$predict_income,0,$orderStatus,$type,$order_create_at,$order_click_at,$order_balance_at);
  316. if($res){
  317. $res_count['nouserinsert_num']++;
  318. }else{
  319. $res_count['fail_insertno_num']++;
  320. $res_count['fail_insertno_ids'].=$order_id.'|';
  321. }
  322. echo "action:插入操作\n";
  323. echo "orderinsert:".$res;
  324. echo "\n";
  325. $_PDO->commit();
  326. }
  327. else{
  328. $res=generateSqlUpdateOther($orderStatus,$order_balance_at,$order_id,$goods_id);
  329. if($res){
  330. $res_count['nouserupdate_num']++;
  331. }else{
  332. $res_count['fail_updateno_num']++;
  333. //$res_count['fail_updateno_ids'].=$order_id.'|';
  334. }
  335. echo "action:更新操作\n";
  336. echo "orderupdate:".$res;
  337. echo "\n";
  338. $_PDO->commit();
  339. }
  340. //echo "-----------------EmptyUserEnd:--------------------\n";
  341. }catch(PDOException $e){
  342. echo 'err_msg'.$e->getMessage()."\n";
  343. $_PDO->rollback();
  344. }
  345. }
  346. echo "/ ** order{$res_count['total_num']}-End ** /";
  347. echo "\n\n\n";
  348. if(LIMIT_NUM >0 && $res_count['total_num'] == LIMIT_NUM) break;
  349. }
  350. print_r($res_count);
  351. echo "\n拉新订单:\n";
  352. print_r($rewardOrder);
  353. echo "\n本次脚本开始时间:". $scriptStart;
  354. echo "\n本次脚本结束时间:". date("Y-m-d H:i:s");
  355. }
  356. function YysManageInfo( $user_id ){
  357. $sql = "SELECT user_id,parent_user_id,level FROM user_level WHERE user_id=:user_id ";
  358. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  359. $stmt = $_PDO->prepare($sql);
  360. $stmt->execute(array(':user_id'=>$user_id));
  361. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  362. if( empty($result) ) return false;
  363. if($result['level'] == 4){
  364. return $result;
  365. }else{
  366. if( empty($result['parent_user_id']) ){
  367. return false;
  368. }
  369. return YysManageInfo( $result['parent_user_id']);
  370. }
  371. return false;
  372. }
  373. function YysInfo( $user_id ){
  374. $sql = "SELECT user_id,parent_user_id,level FROM user_level WHERE user_id=:user_id ";
  375. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  376. $stmt = $_PDO->prepare($sql);
  377. $stmt->execute(array(':user_id'=>$user_id));
  378. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  379. if( empty($result) ) return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  380. if($result['level'] >= 3){
  381. return $result;
  382. }else{
  383. if( empty($result['parent_user_id']) ){
  384. return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  385. }
  386. return YysInfo( $result['parent_user_id']);
  387. }
  388. return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  389. }
  390. function UserInfo($adzone_id){
  391. $sql = "SELECT * FROM user_adzone WHERE adzone_id = :adzone_id ";
  392. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  393. $stmt = $_PDO->prepare($sql);
  394. $stmt->execute(array(':adzone_id'=>$adzone_id));
  395. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  396. if($resultone){
  397. $sql="SELECT * FROM user_level WHERE user_id = :user_id";
  398. $stmt = $_PDO->prepare($sql);
  399. $stmt->execute(array(':user_id'=>$resultone['user_id']));
  400. $userResult = $stmt->fetch(PDO::FETCH_ASSOC);
  401. return $userResult;
  402. }
  403. else{
  404. return false;
  405. }
  406. }
  407. function userLevelInfo($user_id){
  408. $sql="SELECT * FROM user_level WHERE user_id = :user_id ";
  409. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  410. $stmt = $_PDO->prepare($sql);
  411. $stmt->execute(array(':user_id'=>$user_id));
  412. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  413. if($resultone){
  414. $myInfo=["user_id"=>$user_id,"level"=>$resultone['level'],"parent_user_id"=>$resultone['parent_user_id']];
  415. return $myInfo;
  416. }
  417. else{
  418. return false;
  419. }
  420. }
  421. function userMyInfo($user_id){
  422. $sql="SELECT * FROM users WHERE id = :user_id ";
  423. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  424. $stmt = $_PDO->prepare($sql);
  425. $stmt->execute(array(':user_id'=>$user_id));
  426. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  427. if($resultone){
  428. $myInfo['user_id'] = $user_id;
  429. $myInfo['origin'] = $resultone['origin'];
  430. return $myInfo;
  431. }
  432. else{
  433. return false;
  434. }
  435. }
  436. # 获取4层用户级别基础信息
  437. function userLevelandPrentInfo($resultone){
  438. $resultInfo = array();
  439. # self
  440. $userId=$resultone['user_id'];
  441. $userLevel=$resultone['level'];
  442. if($userLevel>=3){
  443. $resultInfo['userList'] = [$userId,0,0,0];
  444. $resultInfo['levelRule'] = 3000;
  445. $resultInfo['userLevel'] = [$userLevel,0,0,0];
  446. return $resultInfo;
  447. }
  448. $userParentId=$resultone['parent_user_id'];
  449. $userGrandId=$resultone['grand_father_id'];
  450. if($userParentId>0){
  451. $resulttwo=userLevelInfo($userParentId);
  452. if( !empty($resulttwo) ){
  453. # parent
  454. $userParentLevel=$resulttwo['level'];
  455. if($userParentLevel>=3){
  456. $resultInfo['userList'] = [$userId,$userParentId,0,0];
  457. $resultInfo['levelRule'] = intval($userLevel.'300');
  458. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,0,0];
  459. return $resultInfo;
  460. }
  461. if($userGrandId>0){
  462. $resultthree=userLevelInfo($userGrandId);
  463. if( !empty($resultthree) ){
  464. # grand
  465. $userGrandLevel=$resultthree['level'];
  466. if($userGrandLevel>=3){
  467. $resultInfo['userList'] = [$userId,$userParentId,$userGrandId,0];
  468. $resultInfo['levelRule'] = intval($userLevel.$userParentLevel.'30');
  469. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,$userGrandLevel,0];
  470. return $resultInfo;
  471. }
  472. }
  473. }
  474. }
  475. }
  476. if( !$userParentId ) $userParentId=0;
  477. if( !$userGrandId ) $userGrandId=0;
  478. if( !isset($userParentLevel) ) $userParentLevel=1;
  479. if( !isset($userGrandLevel) ) $userGrandLevel=1;
  480. #三级里面没有运营商,递归上级运营商
  481. $YysInfo = YysInfo($userGrandId);
  482. $userFourId = $YysInfo['user_id'];
  483. $userFourLevel = $YysInfo['level'];
  484. # 层级规则
  485. $levelRule = $userLevel.$userParentLevel.$userGrandLevel.'3';
  486. $resultInfo['userList']=[$userId,$userParentId,$userGrandId,$userFourId];
  487. $resultInfo['levelRule'] = (int)$levelRule;
  488. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,$userGrandLevel,$userFourLevel];
  489. return $resultInfo;
  490. }
  491. function orderMoney($predict_income, $RuleArr){
  492. $result = array();
  493. foreach($RuleArr as $k=>$v){
  494. if($v>0){
  495. $result[$k] = round($predict_income * $v / 100);
  496. }else{
  497. $result[$k] = 0;
  498. }
  499. }
  500. return $result;
  501. }
  502. function orderMysql($order_id,$goods_id){
  503. $sql="SELECT * from `order` where order_id=:order_id and goods_id=:goods_id";
  504. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  505. $stmt = $_PDO->prepare($sql);
  506. $stmt->execute(array(':order_id'=>$order_id,':goods_id'=>$goods_id));
  507. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  508. return $result;
  509. }
  510. function orderType($adzone_id){
  511. $sql="SELECT * from `adzone` where adzone_id=:adzone_id";
  512. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  513. $stmt = $_PDO->prepare($sql);
  514. $stmt->execute(array(':adzone_id'=>$adzone_id));
  515. $userResult = $stmt->fetch(PDO::FETCH_ASSOC);
  516. return $userResult;
  517. }
  518. function generateSqlInsertOrderOther($goods_img,$goods_name,$order_id,$adzone_id,$goods_id,$num,$price,$sum_price,$predict_income,$self_income,$orderStatus,$type,$order_create_at,$order_click_at,$order_balance_at){
  519. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  520. if( empty($order_balance_at) ){
  521. $sql="insert into `order` (company_type,goods_img_url,goods_name,order_id,adzone_id,goods_id,num,price,sum_price,predict_income,income,status,type,order_create_at,order_click_at) VALUES (:company_type,:goods_img,:goods_name,:order_id,:adzone_id,:goods_id,:num,:price,:sum_price,:predict_income,:self_income,:orderStatus,:type,:order_create_at,:order_click_at)";
  522. $stmt = $_PDO->prepare($sql);
  523. $stmt->execute(array(':company_type'=>2,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':adzone_id'=>$adzone_id,':goods_id'=>$goods_id,':num'=>$num,':price'=>$price,':sum_price'=>$sum_price,':predict_income'=>$predict_income,':self_income'=>$self_income,':orderStatus'=>$orderStatus,':type'=>$type,':order_create_at'=>$order_create_at,':order_click_at'=>$order_click_at));
  524. return $_PDO->lastinsertid();
  525. }
  526. else{
  527. $sql="insert into `order` (company_type,goods_img_url,goods_name,order_id,adzone_id,goods_id,num,price,sum_price,predict_income,income,status,type,order_create_at,order_click_at,order_balance_at) VALUES (:company_type,:goods_img,:goods_name,:order_id,:adzone_id,:goods_id,:num,:price,:sum_price,:predict_income,:self_income,:orderStatus,:type,:order_create_at,:order_click_at,:order_balance_at)";
  528. $stmt = $_PDO->prepare($sql);
  529. $stmt->execute(array(':company_type'=>2,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':adzone_id'=>$adzone_id,':goods_id'=>$goods_id,':num'=>$num,':price'=>$price,':sum_price'=>$sum_price,':predict_income'=>$predict_income,':self_income'=>$self_income,':orderStatus'=>$orderStatus,':type'=>$type,':order_create_at'=>$order_create_at,':order_click_at'=>$order_click_at,':order_balance_at'=>$order_balance_at));
  530. return $_PDO->lastinsertid();
  531. }
  532. }
  533. #order表订单插入脚本
  534. function generateSqlInsertOrder($goods_img,$goods_name,$userId,$order_id,$adzone_id,$goods_id,$num,$price,$sum_price,$predict_income,$self_income,$orderStatus,$type,$userLevel,$order_create_at,$order_click_at,$order_balance_at){
  535. //$adzoneDetail=orderType($adzone_id);
  536. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  537. if( empty($order_balance_at) ){
  538. $sql="insert into `order` (company_type,goods_img_url,goods_name,user_id,order_id,adzone_id,goods_id,num,price,sum_price,predict_income,income,status,type,user_level,order_create_at,order_click_at) VALUES (:company_type,:goods_img,:goods_name,:userId,:order_id,:adzone_id,:goods_id,:num,:price,:sum_price,:predict_income,:self_income,:orderStatus,:type,:userLevel,:order_create_at,:order_click_at)";
  539. $stmt = $_PDO->prepare($sql);
  540. $stmt->execute(array(':company_type'=>0,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':userId'=>$userId,':order_id'=>$order_id,':adzone_id'=>$adzone_id,':goods_id'=>$goods_id,':num'=>$num,':price'=>$price,':sum_price'=>$sum_price,':predict_income'=>$predict_income,':self_income'=>$self_income,':orderStatus'=>$orderStatus,':type'=>$type,':userLevel'=>$userLevel,':order_create_at'=>$order_create_at,':order_click_at'=>$order_click_at));
  541. return $_PDO->lastinsertid();
  542. }
  543. else{
  544. $sql="insert into `order` (company_type,goods_img_url,goods_name,user_id,order_id,adzone_id,goods_id,num,price,sum_price,predict_income,income,status,type,user_level,order_create_at,order_click_at,order_balance_at) VALUES (:company_type,:goods_img,:goods_name,:userId,:order_id,:adzone_id,:goods_id,:num,:price,:sum_price,:predict_income,:self_income,:orderStatus,:type,:userLevel,:order_create_at,:order_click_at,:order_balance_at)";
  545. $stmt = $_PDO->prepare($sql);
  546. $stmt->execute(array(':company_type'=>0,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':userId'=>$userId,':order_id'=>$order_id,':adzone_id'=>$adzone_id,':goods_id'=>$goods_id,':num'=>$num,':price'=>$price,':sum_price'=>$sum_price,':predict_income'=>$predict_income,':self_income'=>$self_income,':orderStatus'=>$orderStatus,':type'=>$type,':userLevel'=>$userLevel,':order_create_at'=>$order_create_at,':order_click_at'=>$order_click_at,':order_balance_at'=>$order_balance_at));
  547. return $_PDO->lastinsertid();
  548. }
  549. }
  550. #返利表订单插入脚本
  551. function generateSqlInsertRebateSelf($user_level,$order_balance_at,$order_create_at,$goods_img,$goods_name,$order_id,$userId,$rebaseType,$last_orderSelfRebaseRebase,$sum_price,$orderStatus,$goods_id,$pre_income){
  552. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  553. if( !empty($order_balance_at) ){
  554. $sql="insert into order_rebate (user_level,order_balance_at,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income) VALUES (:user_level,:order_balance_at,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income)";
  555. $stmt = $_PDO->prepare($sql);
  556. $stmt->execute(array(':user_level'=>$user_level,':order_balance_at'=>$order_balance_at,':order_create_at'=>$order_create_at,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':userId'=>$userId,':rebaseType'=>$rebaseType,':last_orderSelfRebaseRebase'=>$last_orderSelfRebaseRebase,':sum_price'=>$sum_price,':orderStatus'=>$orderStatus,':goods_id'=>$goods_id,':pre_income'=>$pre_income));
  557. return $_PDO->lastinsertid();
  558. }
  559. else{
  560. $sql="insert into order_rebate (user_level,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income) VALUES (:user_level,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income)";
  561. $stmt = $_PDO->prepare($sql);
  562. $stmt->execute(array(':user_level'=>$user_level,':order_create_at'=>$order_create_at,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':userId'=>$userId,':rebaseType'=>$rebaseType,':last_orderSelfRebaseRebase'=>$last_orderSelfRebaseRebase,':sum_price'=>$sum_price,':orderStatus'=>$orderStatus,':goods_id'=>$goods_id,':pre_income'=>$pre_income));
  563. return $_PDO->lastinsertid();
  564. }
  565. }
  566. #单独处理订单插运营商佣金
  567. function YysInsertRebate($user_level,$order_balance_at,$order_create_at,$goods_img,$goods_name,$order_id,$userId,$rebaseType,$last_orderSelfRebaseRebase,$sum_price,$orderStatus,$goods_id,$pre_income){
  568. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  569. if( !empty($order_balance_at) ){
  570. $sql="insert into order_rebate (user_level,order_balance_at,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income) VALUES (:user_level,:order_balance_at,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income)";
  571. $stmt = $_PDO->prepare($sql);
  572. $stmt->execute(array(':user_level'=>$user_level,':order_balance_at'=>$order_balance_at,':order_create_at'=>$order_create_at,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':userId'=>$userId,':rebaseType'=>$rebaseType,':last_orderSelfRebaseRebase'=>$last_orderSelfRebaseRebase,':sum_price'=>$sum_price,':orderStatus'=>$orderStatus,':goods_id'=>$goods_id,':pre_income'=>$pre_income));
  573. return $_PDO->lastinsertid();
  574. }
  575. else{
  576. $sql="insert into order_rebate (user_level,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income) VALUES (:user_level,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income)";
  577. $stmt = $_PDO->prepare($sql);
  578. $stmt->execute(array(':user_level'=>$user_level,':order_create_at'=>$order_create_at,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':userId'=>$userId,':rebaseType'=>$rebaseType,':last_orderSelfRebaseRebase'=>$last_orderSelfRebaseRebase,':sum_price'=>$sum_price,':orderStatus'=>$orderStatus,':goods_id'=>$goods_id,':pre_income'=>$pre_income));
  579. return $_PDO->lastinsertid();
  580. }
  581. }
  582. #返利表订单插入运营商津贴信息
  583. function YysManageInsertRebate($user_level,$order_balance_at,$order_create_at,$goods_img,$goods_name,$order_id,$userId,$rebaseType,$last_orderSelfRebaseRebase,$sum_price,$orderStatus,$goods_id,$pre_income){
  584. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  585. if( !empty($order_balance_at) ){
  586. $sql="insert into order_rebate_profit (user_level,order_balance_at,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income) VALUES (:user_level,:order_balance_at,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income)";
  587. $stmt = $_PDO->prepare($sql);
  588. $stmt->execute(array(':user_level'=>$user_level,':order_balance_at'=>$order_balance_at,':order_create_at'=>$order_create_at,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':userId'=>$userId,':rebaseType'=>$rebaseType,':last_orderSelfRebaseRebase'=>$last_orderSelfRebaseRebase,':sum_price'=>$sum_price,':orderStatus'=>$orderStatus,':goods_id'=>$goods_id,':pre_income'=>$pre_income));
  589. return $_PDO->lastinsertid();
  590. }
  591. else{
  592. $sql="insert into order_rebate_profit (user_level,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income) VALUES (:user_level,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income)";
  593. $stmt = $_PDO->prepare($sql);
  594. $stmt->execute(array(':user_level'=>$user_level,':order_create_at'=>$order_create_at,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':userId'=>$userId,':rebaseType'=>$rebaseType,':last_orderSelfRebaseRebase'=>$last_orderSelfRebaseRebase,':sum_price'=>$sum_price,':orderStatus'=>$orderStatus,':goods_id'=>$goods_id,':pre_income'=>$pre_income));
  595. return $_PDO->lastinsertid();
  596. }
  597. }
  598. #order订单表返利表同步更新
  599. function generateSqlupdate($status,$order_balance_at,$order_id,$goods_id){
  600. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  601. if( !empty($order_balance_at) ){
  602. $sql="update `order` set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  603. $stmt = $_PDO->prepare($sql);
  604. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  605. $res = $stmt->rowCount();
  606. //更新order_rebate
  607. $sql="update order_rebate set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  608. $stmt = $_PDO->prepare($sql);
  609. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  610. $res = $stmt->rowCount();
  611. //更新order_rebate_profit
  612. $sql="update order_rebate_profit set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  613. $stmt = $_PDO->prepare($sql);
  614. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  615. $res = $stmt->rowCount();
  616. }
  617. else{
  618. $sql="update `order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
  619. $stmt = $_PDO->prepare($sql);
  620. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  621. $res = $stmt->rowCount();
  622. $sql="update order_rebate set status=:status where order_id=:order_id and goods_id=:goods_id ";
  623. $stmt = $_PDO->prepare($sql);
  624. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  625. $res = $stmt->rowCount();
  626. //更新order_rebate_profit
  627. $sql="update order_rebate_profit set status=:status where order_id=:order_id and goods_id=:goods_id ";
  628. $stmt = $_PDO->prepare($sql);
  629. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  630. $res = $stmt->rowCount();
  631. }
  632. return $res;
  633. }
  634. #订单表单独更新
  635. function generateSqlUpdateOther($status,$order_balance_at,$order_id,$goods_id){
  636. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  637. if( !empty($order_balance_at) ){
  638. $sql="update `order` set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  639. $stmt = $_PDO->prepare($sql);
  640. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  641. $res = $stmt->rowCount();
  642. }
  643. else{
  644. $sql="update `order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
  645. $stmt = $_PDO->prepare($sql);
  646. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  647. $res = $stmt->rowCount();
  648. }
  649. return $res;
  650. }
  651. # 获取rebateRule
  652. function getRebateRule($levelRule){
  653. $sql="SELECT * from `rebate_rule` where level_rule = :level_rule";
  654. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  655. $stmt = $_PDO->prepare($sql);
  656. $stmt->execute(array(':level_rule'=>$levelRule));
  657. $ruleResult = $stmt->fetch(PDO::FETCH_ASSOC);
  658. return $ruleResult;
  659. }
  660. # 判断是否是新用户第一单
  661. function isNewUser($user_id){
  662. $start = ACT_START;
  663. $end = ACT_END;
  664. $sql = "SELECT id FROM `user_level` where regist_at>'{$start}' and regist_at<= '{$end}' and user_id = {$user_id} limit 1";
  665. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  666. $stmt = $_PDO->prepare($sql);
  667. $stmt->execute();
  668. $res = $stmt->fetch(PDO::FETCH_ASSOC);
  669. if(!empty($res)){
  670. $sql = "SELECT id FROM `user_pullnew` where user_id={$user_id} and status>0 limit 1";
  671. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  672. $stmt = $_PDO->prepare($sql);
  673. $stmt->execute();
  674. $res = $stmt->fetch(PDO::FETCH_ASSOC);
  675. if(empty($res)){
  676. return true;
  677. }
  678. }
  679. return false;
  680. }
  681. # 计算奖励佣金
  682. function getReward($money){
  683. if($money <= 0){
  684. return 0;
  685. }
  686. if($money > 300){
  687. $reward = 300;
  688. }else{
  689. $reward = $money;
  690. }
  691. return $reward;
  692. }
  693. # 同订单多分佣累加
  694. function arraySums($arr1, $arr2){
  695. $res = array();
  696. foreach($arr1 as $k=>$v){
  697. $res[$k] = $arr1[$k] + $arr2[$k];
  698. }
  699. return $res;
  700. }
  701. #拉新奖励订单插入
  702. function rewardOrderInsert($user_level,$order_balance_at,$order_create_at,$goods_img,$goods_name,$order_id,$userId,$rebaseType,$last_orderSelfRebaseRebase,$sum_price,$orderStatus,$goods_id,$pre_income){
  703. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  704. if( !empty($order_balance_at) ){
  705. $sql="insert into order_rebate (user_level,order_balance_at,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income) VALUES (:user_level,:order_balance_at,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income)";
  706. $stmt = $_PDO->prepare($sql);
  707. $stmt->execute(array(':user_level'=>$user_level,':order_balance_at'=>$order_balance_at,':order_create_at'=>$order_create_at,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':userId'=>$userId,':rebaseType'=>$rebaseType,':last_orderSelfRebaseRebase'=>$last_orderSelfRebaseRebase,':sum_price'=>$sum_price,':orderStatus'=>$orderStatus,':goods_id'=>$goods_id,':pre_income'=>$pre_income));
  708. return $_PDO->lastinsertid();
  709. }
  710. else{
  711. $sql="insert into order_rebate (user_level,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income) VALUES (:user_level,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income)";
  712. $stmt = $_PDO->prepare($sql);
  713. $stmt->execute(array(':user_level'=>$user_level,':order_create_at'=>$order_create_at,':goods_img'=>$goods_img,':goods_name'=>$goods_name,':order_id'=>$order_id,':userId'=>$userId,':rebaseType'=>$rebaseType,':last_orderSelfRebaseRebase'=>$last_orderSelfRebaseRebase,':sum_price'=>$sum_price,':orderStatus'=>$orderStatus,':goods_id'=>$goods_id,':pre_income'=>$pre_income));
  714. return $_PDO->lastinsertid();
  715. }
  716. }
  717. # 记录拉新首单表
  718. function pullNewInsert($user_id,$operate_id,$first_order_id,$order_create_at,$status){
  719. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  720. $sql = "insert into `user_pullnew` (user_id, operate_id, first_order_id, order_create_at, status) values ({$user_id},{$operate_id},'{$first_order_id}','{$order_create_at}', {$status})";
  721. $stmt = $_PDO->prepare($sql);
  722. $stmt->execute();
  723. return $_PDO->lastinsertid();
  724. }
  725. #更新拉新首单表状态
  726. function pullNewUpdate($status, $order_id){
  727. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  728. $sql="update `user_pullnew` set status=:status where first_order_id=:order_id";
  729. $stmt = $_PDO->prepare($sql);
  730. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id));
  731. $res = $stmt->rowCount();
  732. return $res;
  733. }
  734. # 获取当前运营商拉新状态
  735. function getPullNew($operate_id){
  736. $sql="SELECT count(id) as records from `user_pullnew` where status>0 and operate_id = :operate_id";
  737. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  738. $stmt = $_PDO->prepare($sql);
  739. $stmt->execute(array(':operate_id'=>$operate_id));
  740. $result = $stmt->fetch(PDO::FETCH_OBJ)->records;
  741. return $result;
  742. }
  743. # 是否更新拉新表
  744. function pullNewIsUpOk($status, $order_id, $user_id){
  745. $sql = "SELECT id from user_pullnew where first_order_id = '{$order_id}'";
  746. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  747. $stmt = $_PDO->prepare($sql);
  748. $stmt->execute();
  749. $res = $stmt->fetch(PDO::FETCH_ASSOC);
  750. if(empty($res)){
  751. return false;
  752. }
  753. if($status == 0){
  754. $sql="SELECT id from `order` where user_id={$user_id} and status>0 limit 1";
  755. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  756. $stmt = $_PDO->prepare($sql);
  757. $stmt->execute();
  758. $res = $stmt->fetch(PDO::FETCH_ASSOC);
  759. if(!empty($res)){
  760. return false;
  761. }
  762. }
  763. return true;
  764. }
  765. # curl调用接口push
  766. function curl_post($url, $params){
  767. $ch = curl_init();
  768. curl_setopt($ch, CURLOPT_URL, $url);
  769. curl_setopt($ch, CURLOPT_HEADER, 0);
  770. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  771. curl_setopt($ch, CURLOPT_POST, 1);
  772. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  773. $response = curl_exec($ch);
  774. curl_close($ch);
  775. return $response;
  776. }
  777. readDataFromDb();