优惠券订单及其他脚本

excel_third_orderv3.php 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'TBK.class.php';
  4. require_once 'confv2.class.php';
  5. require_once 'PHPExcel-1.8/Classes/PHPExcel.php';
  6. require_once 'PHPExcel-1.8/Classes/PHPExcel/IOFactory.php';
  7. require_once 'PHPExcel-1.8/Classes/PHPExcel/Reader/Excel5.php';
  8. # 定义下载订单时间段
  9. date_default_timezone_set('PRC');
  10. define("END_TIME", date('Y-m-d%20H:i:s', strtotime('2019-02-27 00:00:00')) );
  11. define("START_TIME", date('Y-m-d%20H:i:s', strtotime('2019-02-15 00:00:00')) );
  12. define("DETAILDEBUG", 0);//打印流程详细信息,如有需要,设为1
  13. define("LIMIT_NUM", 0);//限制导入条数,0不限制,方便测试,上线设为0
  14. //define("PUSH_URL",'http://yhq.quyaqu.com/api/v2/MessagePush/rebatepush');//push接口地址,测试
  15. define("PUSH_URL",'https://tbk.726p.com/api/v2/MessagePush/rebatepush');//push接口地址
  16. /**
  17. * 导入及更新 order/order_rebate数据
  18. */
  19. #设置时区
  20. set_time_limit(0);
  21. ini_set('memory_limit','1024M');
  22. error_reporting(E_ALL);
  23. function readDataFromDb(){
  24. # 1.下载excel
  25. $res = down_excel();
  26. if( !$res ){
  27. echo '下载excel文件失败';
  28. exit;
  29. }
  30. # 遍历订单
  31. # 统计
  32. $res_count = array(
  33. 'total_num' => 0,
  34. 'generalinsert_num' => 0,
  35. 'generalupdate_num' => 0,
  36. 'nouserinsert_num' => 0,
  37. 'nouserupdate_num' => 0,
  38. 'fail_insert_num' => 0,
  39. 'fail_insert_ids' => '',
  40. 'fail_insertno_num' => 0,
  41. 'fail_insertno_ids' => '',
  42. 'fail_update_num' => 0,
  43. //'fail_update_ids' => '',
  44. 'fail_updateno_num' => 0,
  45. //'fail_updateno_ids' => '',
  46. );
  47. #初始化pdo
  48. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  49. # 读取excel
  50. $templateName = $res;
  51. //实例化Excel读取类
  52. $objReader = new PHPExcel_Reader_Excel2007();
  53. if(!$objReader->canRead($templateName)){
  54. $objReader = new PHPExcel_Reader_Excel5();
  55. if(!$objReader->canRead($templateName)){
  56. echo "\n".'无法识别的Excel文件!';
  57. return false;
  58. }
  59. }
  60. $objPHPExcel=$objReader->load($templateName);
  61. $sheet=$objPHPExcel->getSheet(0);//获取第一个工作表
  62. $highestRow=$sheet->getHighestRow();//取得总行数
  63. $highestColumn=$sheet->getHighestColumn(); //取得总列数
  64. if( strlen($highestColumn) == 2 ){
  65. $highestColumn = 'Z';
  66. }
  67. $orderList = array();
  68. //循环读取excel文件,读取一条,插入一条
  69. for($j=2;$j<=$highestRow;$j++){//从第二行开始读取数据
  70. $str='';
  71. for($k='A';$k<=$highestColumn;$k++){ //从A列读取数据
  72. //这种方法简单,但有不妥,以'\\'合并为数组,再分割\\为字段值插入到数据库,实测在excel中,如果某单元格的值包含了\\导入的数据会为空
  73. $str.=$objPHPExcel->getActiveSheet()->getCell("$k$j")->getValue().'\\';//读取单元格
  74. if( $k=='AE' ){
  75. break;
  76. }
  77. }
  78. //explode:函数把字符串分割为数组。
  79. $orderDetail = explode('\\',trim($str,'\\') );
  80. //if( substr($orderDetail[29], 0, 4) != 'api_') continue;
  81. $res_count['total_num']++;
  82. echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
  83. if( DETAILDEBUG == 1){
  84. echo 'orderDetail:';
  85. var_dump($orderDetail);
  86. }
  87. //0创建时间 1点击时间 2商品信息 3商品ID 4掌柜旺旺 5所属店铺 6商品数 7商品单价 8订单状态 9订单类型 10收入比率 11分成比率 12付款金额 13效果预估 14结算金额 15预估收入 16结算时间 17佣金比率 18佣金金额 19补贴比率 20补贴金额 21补贴类型 22成交平台 23产品类型 24订单编号 25类目名称 26来源媒体ID 27来源媒体名称 28广告位ID 29广告位名称
  88. $order_id=$orderDetail[24];
  89. $update_time=date('Y-m-d H:i:s');
  90. $order_create_at=$orderDetail[0];
  91. $order_click_at=$orderDetail[1];
  92. $order_balance_at=$orderDetail[16];
  93. $goods_id=$orderDetail[3];
  94. $goods_name=$orderDetail[2];
  95. $goods_name=str_replace(['"',"'"],'',$goods_name);
  96. $num=$orderDetail[6];
  97. $price=intval($orderDetail[7]*100);
  98. $sum_price=intval($orderDetail[12]*100);
  99. $statusDesc=$orderDetail[8];
  100. $typeDesc=$orderDetail[9];
  101. $orderStatus = 1;
  102. $type=1;
  103. if($statusDesc=="订单付款"){
  104. $orderStatus=1;
  105. }
  106. elseif($statusDesc=="订单失效"){
  107. $orderStatus=0;
  108. }
  109. elseif($statusDesc=="订单结算"){
  110. $orderStatus=2;
  111. }
  112. if($typeDesc=="聚划算"){
  113. $type=0;
  114. }
  115. elseif($typeDesc=="淘宝"){
  116. $type=1;
  117. }
  118. elseif($typeDesc=="天猫"){
  119. $type=2;
  120. }
  121. $adzone_id=$orderDetail[28];
  122. $ceil_income=round($orderDetail[13], 2);
  123. $predict_income=$ceil_income*100;
  124. $predict_income=ceil($predict_income*conf::$RATE_CONF["globalzk"]);
  125. echo 'order_id:'.$order_id.'|| goods_id:'.$goods_id.'|| orderstatus:'.$orderStatus.'|| order_balance_at:'.$order_balance_at.'|| update_time:'.$update_time;
  126. echo '|| predict_income:'.$predict_income.'|| adzone_id:'.$adzone_id."\n";
  127. $resultone=UserInfo($adzone_id);
  128. if( DETAILDEBUG == 1){
  129. echo 'userinfo:';
  130. var_dump($resultone);
  131. echo "\n";
  132. }
  133. if($sum_price!=0){
  134. if($predict_income<5){
  135. $predict_income=5;
  136. }
  137. }
  138. if( !empty($resultone) ){
  139. echo "User:存在\n";
  140. $orderResult=orderMysql($order_id,$goods_id);
  141. if( empty($orderResult) || in_array($order_id,$orderList)){
  142. echo "action:插入操作\n";
  143. #获取层级规则信息
  144. $userAllInfo=userLevelandPrentInfo($resultone);
  145. echo "<pre>\nuserAllInfo";
  146. print_r($userAllInfo);
  147. if( DETAILDEBUG == 1){
  148. echo 'userallinfo:'."\n";
  149. var_dump($userAllInfo);
  150. }
  151. $userList = $userAllInfo['userList']; //4层 每层userId
  152. $userLevel = $userAllInfo['userLevel']; //4层 每层userlevel
  153. # 从数据库获取规则
  154. $rebateRuleInfo = getRebateRule($userAllInfo['levelRule']);
  155. echo "\nRuleInfo:";
  156. print_r($rebateRuleInfo);
  157. $RuleArr = explode(',',$rebateRuleInfo['rebate_rule']); //4层 每层分佣比例
  158. $TypeArr = explode(',',$rebateRuleInfo['rebate_type']); //4层 每层分佣级别
  159. #获取每一层返利
  160. $moneyInfo=orderMoney($predict_income, $RuleArr); //4层 每层分佣钱数
  161. echo "\nmoneyInfo:";
  162. print_r($moneyInfo);
  163. if( DETAILDEBUG == 1){
  164. echo 'rebateInfo'."\n";
  165. var_dump($moneyInfo);
  166. }
  167. $detail = TBK::tbkItemInfoGet( ['goods_id'=>$goods_id] );
  168. if( !empty($detail) ){
  169. $goods_img=$detail->pict_url;
  170. }
  171. else{
  172. $goods_img="";
  173. }
  174. try{
  175. $_PDO->beginTransaction();
  176. #订单表插入
  177. $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);
  178. if($res){
  179. $orderList[] = $order_id;
  180. $res_count['generalinsert_num']++;
  181. }else{
  182. $res_count['fail_insert_num']++;
  183. $res_count['fail_insert_ids'].=$order_id.'|';
  184. }
  185. echo 'orderinsert:'.$res;
  186. echo "\n";
  187. if($sum_price>0 and $orderStatus!=0){
  188. foreach($moneyInfo as $k=>$v){
  189. if($v>0){
  190. #order_rebate表插入父级佣金
  191. $rebaseType=$TypeArr[$k];
  192. $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);
  193. # 推送
  194. if($res){
  195. $params = array();
  196. $params['user_id'] = $userList[$k];
  197. $params['type'] = 2;
  198. $params['money'] = round($moneyInfo[$k]/100,2);
  199. //$push_res = curl_post( PUSH_URL, $params);
  200. }
  201. echo 'rebateinsert_'.$k.':'.$res;
  202. echo "\n";
  203. }
  204. }
  205. }
  206. //津贴单独计算
  207. # 获取顶级运营商-控制中心
  208. if($sum_price>0 and $orderStatus !=0){
  209. $YysManageInfo = YysManageInfo( $userList[0] );
  210. if( !empty($YysManageInfo) ){
  211. $rebaseType=4;
  212. $YysManageRabate = round($predict_income*conf::$RATE_CONF["YysManage"]);
  213. if($YysManageRabate < 1){
  214. $YysManageRabate = 1;
  215. }
  216. $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);
  217. echo 'rebateinsert_YysManage:'.$res;
  218. echo "\n";
  219. }
  220. }
  221. $_PDO->commit();
  222. }catch(PDOException $e){
  223. echo 'err_msg'.$e->getMessage()."\n";
  224. $_PDO->rollback();
  225. }
  226. //echo "-----------------insertEnd--------------------\n";
  227. }
  228. else{
  229. try{
  230. $_PDO->beginTransaction();
  231. //更新order/order_rebate表
  232. echo "action:更新操作\n";
  233. $res=generateSqlupdate($orderStatus,$order_balance_at,$order_id,$goods_id);
  234. $redOrderUpRes=redSqlupdate($orderStatus,$order_balance_at,$order_id,$goods_id);
  235. $redUpRes = updateRed( $order_id, $orderStatus );
  236. /*** 失效订单单独更新 Start ***/
  237. if($orderStatus == 0){
  238. //首先判断该订单是否已经失效
  239. //$order_old_status = $redOrderExists['status'];
  240. if($redOrderUpRes){
  241. if(!empty($redUpRes) && $redUpRes['red_open_money'] > 0){ //存在红包并且有拆除金额
  242. //1. 退红包的处理
  243. //更新流水表
  244. //获取用户最新balance
  245. echo "红包订单失效\n";
  246. echo "失效红包:".$redUpRes['id']."\n";
  247. $userAccount = getUserBalace($resultone['user_id']);
  248. $upAccount = redAccountRecord( $resultone['user_id'], 3, $redUpRes['red_open_money'], $redUpRes['id'], round(($userAccount['balance']*100 - $redUpRes['red_open_money']*100)/100, 2));
  249. echo "更新流水:".$upAccount."\n";
  250. }
  251. //判断是否该订单存在红包提现分单
  252. $redAccountInfo = insertLoseAccount($order_id);
  253. }
  254. }
  255. if($res){
  256. $res_count['generalupdate_num']++;
  257. }else{
  258. $res_count['fail_update_num']++;
  259. //$res_count['fail_update_ids'].=$order_id.'|';
  260. }
  261. echo "更新数据-> orderstatus:".$orderStatus." order_balance_at:".$order_balance_at;
  262. echo "\n";
  263. echo "order/reabte_update:".$res;
  264. echo "\n";
  265. //echo "-----------------updateEnd-----------------------\n";
  266. $_PDO->commit();
  267. }catch(PDOException $e){
  268. $_PDO->rollback();
  269. echo 'err_msg'.$e->getMessage()."\n";
  270. }
  271. }
  272. //echo "-----------------IssetUserEnd:--------------------\n";
  273. }
  274. else{
  275. $_PDO->beginTransaction();
  276. try{
  277. #user不存在的处理
  278. echo "User:不存在\n";
  279. $orderResult=orderMysql($order_id,$goods_id);
  280. if( empty($orderResult) ){
  281. $detail = TBK::tbkItemInfoGet( ['goods_id'=>$goods_id] );
  282. if( !empty($detail) ){
  283. $goods_img=$detail->pict_url;
  284. }
  285. else{
  286. $goods_img="";
  287. }
  288. $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);
  289. if($res){
  290. $res_count['nouserinsert_num']++;
  291. }else{
  292. $res_count['fail_insertno_num']++;
  293. $res_count['fail_insertno_ids'].=$order_id.'|';
  294. }
  295. echo "action:插入操作\n";
  296. echo "orderinsert:".$res;
  297. echo "\n";
  298. $_PDO->commit();
  299. }
  300. else{
  301. $res=generateSqlUpdateOther($orderStatus,$order_balance_at,$order_id,$goods_id);
  302. if($res){
  303. $res_count['nouserupdate_num']++;
  304. }else{
  305. $res_count['fail_updateno_num']++;
  306. //$res_count['fail_updateno_ids'].=$order_id.'|';
  307. }
  308. echo "action:更新操作\n";
  309. echo "orderupdate:".$res;
  310. echo "\n";
  311. $_PDO->commit();
  312. }
  313. //echo "-----------------EmptyUserEnd:--------------------\n";
  314. }catch(PDOException $e){
  315. $_PDO->rollback();
  316. echo 'err_msg'.$e->getMessage()."\n";
  317. }
  318. }
  319. echo "/ ** order{$res_count['total_num']}-End ** /";
  320. echo "\n\n\n";
  321. if(LIMIT_NUM >0 && $res_count['total_num'] == LIMIT_NUM) break;
  322. }
  323. print_r($res_count);
  324. }
  325. function YysManageInfo( $user_id ){
  326. $sql = "SELECT user_id,parent_user_id,level FROM user_level WHERE user_id=:user_id ";
  327. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  328. $stmt = $_PDO->prepare($sql);
  329. $stmt->execute(array(':user_id'=>$user_id));
  330. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  331. if( empty($result) ) return false;
  332. if($result['level'] == 4){
  333. return $result;
  334. }else{
  335. if( empty($result['parent_user_id']) ){
  336. return false;
  337. }
  338. return YysManageInfo( $result['parent_user_id']);
  339. }
  340. return false;
  341. }
  342. function YysInfo( $user_id ){
  343. $sql = "SELECT user_id,parent_user_id,level FROM user_level WHERE user_id=:user_id ";
  344. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  345. $stmt = $_PDO->prepare($sql);
  346. $stmt->execute(array(':user_id'=>$user_id));
  347. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  348. if( empty($result) ) return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  349. if($result['level'] >= 3){
  350. return $result;
  351. }else{
  352. if( empty($result['parent_user_id']) ){
  353. return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  354. }
  355. return YysInfo( $result['parent_user_id']);
  356. }
  357. return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  358. }
  359. function UserInfo($adzone_id){
  360. $sql = "SELECT * FROM user_adzone WHERE adzone_id = :adzone_id ";
  361. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  362. $stmt = $_PDO->prepare($sql);
  363. $stmt->execute(array(':adzone_id'=>$adzone_id));
  364. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  365. if($resultone){
  366. $sql="SELECT * FROM user_level WHERE user_id = :user_id";
  367. $stmt = $_PDO->prepare($sql);
  368. $stmt->execute(array(':user_id'=>$resultone['user_id']));
  369. $userResult = $stmt->fetch(PDO::FETCH_ASSOC);
  370. return $userResult;
  371. }
  372. else{
  373. return false;
  374. }
  375. }
  376. function userLevelInfo($user_id){
  377. $sql="SELECT * FROM user_level WHERE user_id = :user_id ";
  378. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  379. $stmt = $_PDO->prepare($sql);
  380. $stmt->execute(array(':user_id'=>$user_id));
  381. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  382. if($resultone){
  383. $myInfo=["user_id"=>$user_id,"level"=>$resultone['level'],"parent_user_id"=>$resultone['parent_user_id']];
  384. return $myInfo;
  385. }
  386. else{
  387. return false;
  388. }
  389. }
  390. function userMyInfo($user_id){
  391. $sql="SELECT * FROM users WHERE id = :user_id ";
  392. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  393. $stmt = $_PDO->prepare($sql);
  394. $stmt->execute(array(':user_id'=>$user_id));
  395. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  396. if($resultone){
  397. $myInfo['user_id'] = $user_id;
  398. $myInfo['origin'] = $resultone['origin'];
  399. return $myInfo;
  400. }
  401. else{
  402. return false;
  403. }
  404. }
  405. # 获取4层用户级别基础信息
  406. function userLevelandPrentInfo($resultone){
  407. $resultInfo = array();
  408. # self
  409. $userId=$resultone['user_id'];
  410. $userLevel=$resultone['level'];
  411. if($userLevel>=3){
  412. $resultInfo['userList'] = [$userId,0,0,0];
  413. $resultInfo['levelRule'] = 3000;
  414. $resultInfo['userLevel'] = [$userLevel,0,0,0];
  415. return $resultInfo;
  416. }
  417. $userParentId=$resultone['parent_user_id'];
  418. $userGrandId=$resultone['grand_father_id'];
  419. if($userParentId>0){
  420. $resulttwo=userLevelInfo($userParentId);
  421. if( !empty($resulttwo) ){
  422. # parent
  423. $userParentLevel=$resulttwo['level'];
  424. if($userParentLevel>=3){
  425. $resultInfo['userList'] = [$userId,$userParentId,0,0];
  426. $resultInfo['levelRule'] = intval($userLevel.'300');
  427. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,0,0];
  428. return $resultInfo;
  429. }
  430. if($userGrandId>0){
  431. $resultthree=userLevelInfo($userGrandId);
  432. if( !empty($resultthree) ){
  433. # grand
  434. $userGrandLevel=$resultthree['level'];
  435. if($userGrandLevel>=3){
  436. $resultInfo['userList'] = [$userId,$userParentId,$userGrandId,0];
  437. $resultInfo['levelRule'] = intval($userLevel.$userParentLevel.'30');
  438. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,$userGrandLevel,0];
  439. return $resultInfo;
  440. }
  441. }
  442. }
  443. }
  444. }
  445. if( !$userParentId ) $userParentId=0;
  446. if( !$userGrandId ) $userGrandId=0;
  447. if( !isset($userParentLevel) ) $userParentLevel=1;
  448. if( !isset($userGrandLevel) ) $userGrandLevel=1;
  449. #三级里面没有运营商,递归上级运营商
  450. $YysInfo = YysInfo($userGrandId);
  451. $userFourId = $YysInfo['user_id'];
  452. $userFourLevel = $YysInfo['level'];
  453. # 层级规则
  454. $levelRule = $userLevel.$userParentLevel.$userGrandLevel.'3';
  455. $resultInfo['userList']=[$userId,$userParentId,$userGrandId,$userFourId];
  456. $resultInfo['levelRule'] = (int)$levelRule;
  457. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,$userGrandLevel,$userFourLevel];
  458. return $resultInfo;
  459. }
  460. function orderMoney($predict_income, $RuleArr){
  461. $result = array();
  462. foreach($RuleArr as $k=>$v){
  463. if($v>0){
  464. $result[$k] = round($predict_income * $v / 100);
  465. }else{
  466. $result[$k] = 0;
  467. }
  468. }
  469. return $result;
  470. }
  471. function orderMysql($order_id,$goods_id){
  472. $sql="SELECT * from `order` where order_id=:order_id and goods_id=:goods_id";
  473. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  474. $stmt = $_PDO->prepare($sql);
  475. $stmt->execute(array(':order_id'=>$order_id,':goods_id'=>$goods_id));
  476. $orderResult = $stmt->fetch(PDO::FETCH_ASSOC);
  477. return $orderResult;
  478. }
  479. function orderType($adzone_id){
  480. $sql="SELECT * from `adzone` where adzone_id=:adzone_id";
  481. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  482. $stmt = $_PDO->prepare($sql);
  483. $stmt->execute(array(':adzone_id'=>$adzone_id));
  484. $userResult = $stmt->fetch(PDO::FETCH_ASSOC);
  485. return $userResult;
  486. }
  487. 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){
  488. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  489. if( empty($order_balance_at) ){
  490. $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)";
  491. $stmt = $_PDO->prepare($sql);
  492. $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));
  493. return $_PDO->lastinsertid();
  494. }
  495. else{
  496. $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)";
  497. $stmt = $_PDO->prepare($sql);
  498. $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));
  499. return $_PDO->lastinsertid();
  500. }
  501. }
  502. #order表订单插入脚本
  503. 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){
  504. $adzoneDetail=orderType($adzone_id);
  505. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  506. if( empty($order_balance_at) ){
  507. $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)";
  508. $stmt = $_PDO->prepare($sql);
  509. $stmt->execute(array(':company_type'=>$adzoneDetail["type"],':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));
  510. return $_PDO->lastinsertid();
  511. }
  512. else{
  513. $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)";
  514. $stmt = $_PDO->prepare($sql);
  515. $stmt->execute(array(':company_type'=>$adzoneDetail["type"],':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));
  516. return $_PDO->lastinsertid();
  517. }
  518. }
  519. #返利表订单插入脚本
  520. 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){
  521. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  522. if( !empty($order_balance_at) ){
  523. $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)";
  524. $stmt = $_PDO->prepare($sql);
  525. $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));
  526. return $_PDO->lastinsertid();
  527. }
  528. else{
  529. $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)";
  530. $stmt = $_PDO->prepare($sql);
  531. $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));
  532. return $_PDO->lastinsertid();
  533. }
  534. }
  535. #单独处理订单插运营商佣金
  536. 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){
  537. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  538. if( !empty($order_balance_at) ){
  539. $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)";
  540. $stmt = $_PDO->prepare($sql);
  541. $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));
  542. return $_PDO->lastinsertid();
  543. }
  544. else{
  545. $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)";
  546. $stmt = $_PDO->prepare($sql);
  547. $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));
  548. return $_PDO->lastinsertid();
  549. }
  550. }
  551. #返利表订单插入运营商津贴信息
  552. 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){
  553. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  554. if( !empty($order_balance_at) ){
  555. $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)";
  556. $stmt = $_PDO->prepare($sql);
  557. $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));
  558. return $_PDO->lastinsertid();
  559. }
  560. else{
  561. $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)";
  562. $stmt = $_PDO->prepare($sql);
  563. $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));
  564. return $_PDO->lastinsertid();
  565. }
  566. }
  567. #order订单表返利表同步更新
  568. function generateSqlupdate($status,$order_balance_at,$order_id,$goods_id){
  569. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  570. if( !empty($order_balance_at) ){
  571. $sql="update `order` set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  572. $stmt = $_PDO->prepare($sql);
  573. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  574. $res = $stmt->rowCount();
  575. //更新order_rebate
  576. $sql="update order_rebate set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  577. $stmt = $_PDO->prepare($sql);
  578. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  579. $res = $stmt->rowCount();
  580. //更新order_rebate_profit
  581. $sql="update order_rebate_profit set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  582. $stmt = $_PDO->prepare($sql);
  583. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  584. $res = $stmt->rowCount();
  585. }
  586. else{
  587. $sql="update `order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
  588. $stmt = $_PDO->prepare($sql);
  589. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  590. $res = $stmt->rowCount();
  591. $sql="update order_rebate set status=:status where order_id=:order_id and goods_id=:goods_id ";
  592. $stmt = $_PDO->prepare($sql);
  593. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  594. $res = $stmt->rowCount();
  595. //更新order_rebate_profit
  596. $sql="update order_rebate_profit set status=:status where order_id=:order_id and goods_id=:goods_id ";
  597. $stmt = $_PDO->prepare($sql);
  598. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  599. $res = $stmt->rowCount();
  600. }
  601. return $res;
  602. }
  603. #订单表单独更新
  604. function generateSqlUpdateOther($status,$order_balance_at,$order_id,$goods_id){
  605. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  606. if( !empty($order_balance_at) ){
  607. $sql="update `order` 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. }
  612. else{
  613. $sql="update `order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
  614. $stmt = $_PDO->prepare($sql);
  615. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  616. $res = $stmt->rowCount();
  617. }
  618. return $res;
  619. }
  620. # 获取rebateRule
  621. function getRebateRule($levelRule){
  622. $sql="SELECT * from `rebate_rule` where level_rule = :level_rule";
  623. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  624. $stmt = $_PDO->prepare($sql);
  625. $stmt->execute(array(':level_rule'=>$levelRule));
  626. $ruleResult = $stmt->fetch(PDO::FETCH_ASSOC);
  627. return $ruleResult;
  628. }
  629. #redorder订单表返利表同步更新
  630. function redSqlupdate($status,$order_balance_at,$order_id,$goods_id){
  631. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  632. if( !empty($order_balance_at) ){
  633. $sql="update `red_order` set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  634. $stmt = $_PDO->prepare($sql);
  635. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  636. $res = $stmt->rowCount();
  637. }
  638. else{
  639. $sql="update `red_order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
  640. $stmt = $_PDO->prepare($sql);
  641. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  642. $res = $stmt->rowCount();
  643. }
  644. return $res;
  645. }
  646. function updateRed($order_id, $status ){
  647. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  648. $sql="update `red_user_info` set order_status=:status where order_id=:order_id";
  649. $stmt = $_PDO->prepare($sql);
  650. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id));
  651. $res = $stmt->rowCount();
  652. if($res){
  653. $sql = "select * from `red_user_info` where order_id = '{$order_id}'";
  654. $stmt = $_PDO->prepare($sql);
  655. $stmt->execute();
  656. $redinfo = $stmt->fetch(PDO::FETCH_ASSOC);
  657. return $redinfo;
  658. }
  659. return $res;
  660. }
  661. function getUserBalace($user_id){
  662. $table = "red_account_record_".($user_id%10);
  663. $sql = "SELECT balance from {$table} where user_id={$user_id} order by id desc limit 1";
  664. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  665. $stmt = $_PDO->prepare($sql);
  666. $stmt->execute();
  667. $res = $stmt->fetch(PDO::FETCH_ASSOC);
  668. return $res;
  669. }
  670. function redAccountRecord($user_id, $type, $money, $oh_id, $balance){
  671. $table = "red_account_record_".($user_id%10);
  672. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  673. $sql = "insert into `{$table}` (user_id, type, money, oh_id, balance) values ({$user_id},{$type},{$money},'{$oh_id}', {$balance})";
  674. $stmt = $_PDO->prepare($sql);
  675. $stmt->execute();
  676. return $_PDO->lastinsertid();
  677. }
  678. function insertLoseAccount($order_id){
  679. //判断是否已经处理
  680. // 查出哪些人分到了红包提现
  681. $sql = "SELECT distinct user_id from `order_rebate` where order_id='{$order_id}' and type=7 ";
  682. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  683. $stmt = $_PDO->prepare($sql);
  684. $stmt->execute();
  685. $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
  686. if(empty($res)){
  687. return false;
  688. }
  689. echo "退红包提现,返还流水balance:\n";
  690. foreach($res as $k=>$v){
  691. $table = "red_account_record_".($v['user_id']%10);
  692. //若已经处理跳过
  693. $sql = "SELECT id from {$table} where user_id={$v['user_id']} and oh_id='{$order_id}' and type=4";
  694. $stmt = $_PDO->prepare($sql);
  695. $stmt->execute();
  696. $ifExists = $stmt->fetch(PDO::FETCH_ASSOC);
  697. if(!empty($ifExists)){
  698. continue;
  699. }
  700. $sql = "SELECT sum(money) as money from {$table} where user_id={$v['user_id']} and oh_id='{$order_id}' and type=2";
  701. $stmt = $_PDO->prepare($sql);
  702. $stmt->execute();
  703. $record = $stmt->fetch(PDO::FETCH_ASSOC);
  704. $account = getUserBalace($v['user_id']);
  705. $insertLose = redAccountRecord($v['user_id'], 4, $record['money'], $order_id, round(($account['balance']*100 + $record['money']*100)/100, 2));
  706. echo "用户".$v['user_id'].":返还".$record['money']." | 处理结果:".$insertLose."\n";
  707. }
  708. return $insertLose;
  709. }
  710. # curl调用接口push
  711. function curl_post($url, $params){
  712. $ch = curl_init();
  713. curl_setopt($ch, CURLOPT_URL, $url);
  714. curl_setopt($ch, CURLOPT_HEADER, 0);
  715. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  716. curl_setopt($ch, CURLOPT_POST, 1);
  717. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  718. $response = curl_exec($ch);
  719. curl_close($ch);
  720. return $response;
  721. }
  722. # 下载excel订单文件
  723. function down_excel(){
  724. $str_cookie ='cna=gGnDEwQLQAACATqEyYplpj5I; account-path-guide-s1=true; 209580064_yxjh-filter-1=true; undefined_yxjh-filter-1=true; t=8c549c3cedcac7891a2c3c7f36ca91f4; cookie2=1b6238ea20168e295d5bd7dacb9d285d; v=0; _tb_token_=f813b4de14be3; alimamapwag=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzY5LjAuMzQ5Ny4xMDAgU2FmYXJpLzUzNy4zNg%3D%3D; cookie32=2d2dbd51714bd91fa4e604f2e1050dd6; alimamapw=FnABFCAlFCZcQ3dVHXF2FncCFnF5FCAlFCFWQ3YjHXBxFnAEFnF7FCEgFCFXQ3BRHXFxFnd3FnEB%0AFCIhFCYmQ3YkMQICVwcEUgQPAQFWBlxWBVJRWwEAAABQAgQJV1dSVQAG; cookie31=OTk1MDYxNzMsJUU0JUI4JThBJUU5JUE1JUI2JUU1JUI4JTgyJUU1JTkwJTg4JUU0JUI4JTgwJUU3JUE3JTkxJUU2JThBJTgwJUU2JTlDJTg5JUU5JTk5JTkwJUU1JTg1JUFDJUU1JThGJUI4LGppYW5nbmFuQGZhbnRvdXRpYW8uY29tLFRC; login=WqG3DMC9VAQiUQ%3D%3D; JSESSIONID=BB0014635CAE3BC9A4CB4C3EB3BB1179; apush848645ac0bf07b717f88c18a7e296d1e=%7B%22ts%22%3A1551161803920%2C%22parentId%22%3A1551161793707%7D; l=bBEoP2SHvN8ixqP6XOfwiuIJckbtnIOfhsPzw4TZDICP9a1X5yJhWZaRASTWC3GVa6CpR3Wc5ILQBkLK0yznh; isg=BOHhz5mFGcQ2frL4yOZ9ppnA8K07JkFjkShWTkO32-hHqgd8i972UcusDJ6JYu24';
  725. $nowTime = END_TIME;
  726. $pastTime = START_TIME;
  727. $url = "https://pub.alimama.com/report/getTbkThirdPaymentDetails.json?DownloadID=DOWNLOAD_REPORT_TK3_PUB&queryType=2&payStatus=&startTime=".$pastTime."&endTime=".$nowTime;
  728. echo $url."\n";
  729. $ch = curl_init($url);
  730. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  731. curl_setopt($ch, CURLOPT_COOKIE, $str_cookie); //使用上面获取的cookies
  732. $response = curl_exec($ch);
  733. curl_close($ch);
  734. if( $response ){
  735. $file = fopen("./third_order_excel.csv", "w+");
  736. $a = fputs($file, $response);
  737. fclose($file);
  738. return './third_order_excel.csv';
  739. }
  740. else{
  741. return false;
  742. }
  743. }
  744. readDataFromDb();