优惠券订单及其他脚本

scan_orderv3.php 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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",'http://yhq.quyaqu.com/api/v2/MessagePush/rebatepush');//push接口地址,测试
  8. define("PUSH_URL",'https://tbk.726p.com/api/v2/MessagePush/rebatepush');//push接口地址
  9. /**
  10. * 导入及更新 order/order_rebate数据
  11. */
  12. #设置时区
  13. date_default_timezone_set('PRC');
  14. set_time_limit(0);
  15. ini_set('memory_limit','1024M');
  16. function readDataFromDb(){
  17. # 1.获取8分钟内订单
  18. $stime = date('Y-m-d H:i:s', time()-360);
  19. //$stime = date('Y-m-d H:i:s',strtotime('2018-08-07'));
  20. $etime = date('Y-m-d H:i:s');
  21. $sql = "SELECT * from ftxia_taoke_detail2 where update_time > :stime";
  22. $dumpsql = str_replace(':stime', "'".$stime."'", $sql);
  23. echo "\n\n".$dumpsql."\n";
  24. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  25. $stmt = $_PDO->prepare($sql);
  26. $stmt->execute(array(':stime'=>$stime));
  27. $orderResult = $stmt->fetchAll(PDO::FETCH_ASSOC);
  28. # 遍历订单
  29. # 统计
  30. $res_count = array(
  31. 'total_num' => 0,
  32. 'generalinsert_num' => 0,
  33. 'generalupdate_num' => 0,
  34. 'nouserinsert_num' => 0,
  35. 'nouserupdate_num' => 0,
  36. 'fail_insert_num' => 0,
  37. 'fail_insert_ids' => '',
  38. 'fail_insertno_num' => 0,
  39. 'fail_insertno_ids' => '',
  40. 'fail_update_num' => 0,
  41. //'fail_update_ids' => '',
  42. 'fail_updateno_num' => 0,
  43. //'fail_updateno_ids' => '',
  44. );
  45. $orderList = array();
  46. foreach( $orderResult as $k=>$orderDetail ){
  47. $res_count['total_num']++;
  48. echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
  49. if( DETAILDEBUG == 1){
  50. echo 'orderDetail:';
  51. var_dump($orderDetail);
  52. }
  53. $order_id=$orderDetail["order_sn"];
  54. $update_time=$orderDetail["update_time"];
  55. $order_create_at=$orderDetail["create_time"];
  56. $order_click_at=$orderDetail["click_time"];
  57. $order_balance_at=$orderDetail["balance_time"];
  58. $goods_id=$orderDetail["goods_id"];
  59. $goods_name=$orderDetail["goods_name"];
  60. $goods_name=str_replace(['"',"'"],'',$goods_name);
  61. $num=$orderDetail["goods_number"];
  62. $price=intval($orderDetail["goods_price"]*100);
  63. $sum_price=intval($orderDetail["order_amount"]*100);
  64. $statusDesc=$orderDetail["order_status"];
  65. $typeDesc=$orderDetail["order_type"];
  66. $orderStatus = 1;
  67. $type=1;
  68. if($statusDesc=="订单付款"){
  69. $orderStatus=1;
  70. }
  71. elseif($statusDesc=="订单失效"){
  72. $orderStatus=0;
  73. }
  74. elseif($statusDesc=="订单结算"){
  75. $orderStatus=2;
  76. }
  77. if($typeDesc=="聚划算"){
  78. $type=0;
  79. }
  80. elseif($typeDesc=="淘宝"){
  81. $type=1;
  82. }
  83. elseif($typeDesc=="天猫"){
  84. $type=2;
  85. }
  86. $adzone_id=$orderDetail["adv_id"];
  87. $ceil_income=round($orderDetail["effect_prediction"], 2);
  88. $predict_income=$ceil_income*100;
  89. $predict_income=ceil($predict_income*conf::$RATE_CONF["globalzk"]);
  90. echo 'order_id:'.$order_id.'|| goods_id:'.$goods_id.'|| orderstatus:'.$orderStatus.'|| order_balance_at:'.$order_balance_at.'|| update_time:'.$update_time;
  91. echo '|| predict_income:'.$predict_income.'|| adzone_id:'.$adzone_id."\n";
  92. $resultone=UserInfo($adzone_id);
  93. if( DETAILDEBUG == 1){
  94. echo 'userinfo:';
  95. var_dump($resultone);
  96. echo "\n";
  97. }
  98. if($sum_price!=0){
  99. if($predict_income<5){
  100. $predict_income=5;
  101. }
  102. }
  103. if( !empty($resultone) ){
  104. echo "User:存在\n";
  105. $orderResult=orderMysql($order_id,$goods_id);
  106. if( empty($orderResult) || in_array($order_id,$orderList)){
  107. echo "action:插入操作\n";
  108. #获取层级规则信息
  109. $userAllInfo=userLevelandPrentInfo($resultone);
  110. echo "<pre>\nuserAllInfo";
  111. print_r($userAllInfo);
  112. if( DETAILDEBUG == 1){
  113. echo 'userallinfo:'."\n";
  114. var_dump($userAllInfo);
  115. }
  116. $userList = $userAllInfo['userList']; //4层 每层userId
  117. $userLevel = $userAllInfo['userLevel']; //4层 每层userlevel
  118. # 从数据库获取规则
  119. $rebateRuleInfo = getRebateRule($userAllInfo['levelRule']);
  120. echo "\nRuleInfo:";
  121. print_r($rebateRuleInfo);
  122. $RuleArr = explode(',',$rebateRuleInfo['rebate_rule']); //4层 每层分佣比例
  123. $TypeArr = explode(',',$rebateRuleInfo['rebate_type']); //4层 每层分佣级别
  124. #获取每一层返利
  125. $moneyInfo=orderMoney($predict_income, $RuleArr); //4层 每层分佣钱数
  126. echo "\nmoneyInfo:";
  127. print_r($moneyInfo);
  128. if( DETAILDEBUG == 1){
  129. echo 'rebateInfo'."\n";
  130. var_dump($moneyInfo);
  131. }
  132. $detail = TBK::tbkItemInfoGet( ['goods_id'=>$goods_id] );
  133. if( !empty($detail) ){
  134. $goods_img=$detail->pict_url;
  135. }
  136. else{
  137. $goods_img="";
  138. }
  139. try{
  140. $_PDO->beginTransaction();
  141. #订单表插入
  142. $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);
  143. if($res){
  144. $orderList[] = $order_id;
  145. $res_count['generalinsert_num']++;
  146. }else{
  147. $res_count['fail_insert_num']++;
  148. $res_count['fail_insert_ids'].=$order_id.'|';
  149. }
  150. echo 'orderinsert:'.$res;
  151. echo "\n";
  152. if($sum_price>0 and $orderStatus!=0){
  153. foreach($moneyInfo as $k=>$v){
  154. if($v>0){
  155. #order_rebate表插入父级佣金
  156. $rebaseType=$TypeArr[$k];
  157. $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);
  158. # 推送
  159. if($res){
  160. $params = array();
  161. $params['user_id'] = $userList[$k];
  162. $params['type'] = 2;
  163. $params['money'] = round($moneyInfo[$k]/100,2);
  164. $push_res = curl_post( PUSH_URL, $params);
  165. }
  166. echo 'rebateinsert_'.$k.':'.$res;
  167. echo "\n";
  168. }
  169. }
  170. }
  171. //津贴单独计算
  172. # 获取顶级运营商-控制中心
  173. if($sum_price>0 and $orderStatus !=0){
  174. $YysManageInfo = YysManageInfo( $userList[0] );
  175. if( !empty($YysManageInfo) ){
  176. $rebaseType=4;
  177. $YysManageRabate = round($predict_income*conf::$RATE_CONF["YysManage"]);
  178. if($YysManageRabate < 1){
  179. $YysManageRabate = 1;
  180. }
  181. $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);
  182. echo 'rebateinsert_YysManage:'.$res;
  183. echo "\n";
  184. }
  185. }
  186. $_PDO->commit();
  187. }catch(PDOException $e){
  188. echo 'err_msg'.$e->getMessage()."\n";
  189. $_PDO->rollback();
  190. }
  191. //echo "-----------------insertEnd--------------------\n";
  192. }
  193. else{
  194. try{
  195. $_PDO->beginTransaction();
  196. //更新order/order_rebate表
  197. echo "action:更新操作\n";
  198. $res=generateSqlupdate($orderStatus,$order_balance_at,$order_id,$goods_id);
  199. if($res){
  200. $res_count['generalupdate_num']++;
  201. }else{
  202. $res_count['fail_update_num']++;
  203. //$res_count['fail_update_ids'].=$order_id.'|';
  204. }
  205. echo "更新数据-> orderstatus:".$orderStatus." order_balance_at:".$order_balance_at;
  206. echo "\n";
  207. echo "order/reabte_update:".$res;
  208. echo "\n";
  209. //echo "-----------------updateEnd-----------------------\n";
  210. $_PDO->commit();
  211. }catch(PDOException $e){
  212. echo 'err_msg'.$e->getMessage()."\n";
  213. $_PDO->rollback();
  214. }
  215. }
  216. //echo "-----------------IssetUserEnd:--------------------\n";
  217. }
  218. else{
  219. $_PDO->beginTransaction();
  220. try{
  221. #user不存在的处理
  222. echo "User:不存在\n";
  223. $orderResult=orderMysql($order_id,$goods_id);
  224. if( empty($orderResult) ){
  225. $detail = TBK::tbkItemInfoGet( ['goods_id'=>$goods_id] );
  226. if( !empty($detail) ){
  227. $goods_img=$detail->pict_url;
  228. }
  229. else{
  230. $goods_img="";
  231. }
  232. $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);
  233. if($res){
  234. $res_count['nouserinsert_num']++;
  235. }else{
  236. $res_count['fail_insertno_num']++;
  237. $res_count['fail_insertno_ids'].=$order_id.'|';
  238. }
  239. echo "action:插入操作\n";
  240. echo "orderinsert:".$res;
  241. echo "\n";
  242. $_PDO->commit();
  243. }
  244. else{
  245. $res=generateSqlUpdateOther($orderStatus,$order_balance_at,$order_id,$goods_id);
  246. if($res){
  247. $res_count['nouserupdate_num']++;
  248. }else{
  249. $res_count['fail_updateno_num']++;
  250. //$res_count['fail_updateno_ids'].=$order_id.'|';
  251. }
  252. echo "action:更新操作\n";
  253. echo "orderupdate:".$res;
  254. echo "\n";
  255. $_PDO->commit();
  256. }
  257. //echo "-----------------EmptyUserEnd:--------------------\n";
  258. }catch(PDOException $e){
  259. echo 'err_msg'.$e->getMessage()."\n";
  260. $_PDO->rollback();
  261. }
  262. }
  263. echo "/ ** order{$res_count['total_num']}-End ** /";
  264. echo "\n\n\n";
  265. if(LIMIT_NUM >0 && $res_count['total_num'] == LIMIT_NUM) break;
  266. }
  267. print_r($res_count);
  268. }
  269. function YysManageInfo( $user_id ){
  270. $sql = "SELECT user_id,parent_user_id,level FROM user_level WHERE user_id=:user_id ";
  271. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  272. $stmt = $_PDO->prepare($sql);
  273. $stmt->execute(array(':user_id'=>$user_id));
  274. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  275. if( empty($result) ) return false;
  276. if($result['level'] == 4){
  277. return $result;
  278. }else{
  279. if( empty($result['parent_user_id']) ){
  280. return false;
  281. }
  282. return YysManageInfo( $result['parent_user_id']);
  283. }
  284. return false;
  285. }
  286. function YysInfo( $user_id ){
  287. $sql = "SELECT user_id,parent_user_id,level FROM user_level WHERE user_id=:user_id ";
  288. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  289. $stmt = $_PDO->prepare($sql);
  290. $stmt->execute(array(':user_id'=>$user_id));
  291. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  292. if( empty($result) ) return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  293. if($result['level'] >= 3){
  294. return $result;
  295. }else{
  296. if( empty($result['parent_user_id']) ){
  297. return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  298. }
  299. return YysInfo( $result['parent_user_id']);
  300. }
  301. return ['user_id'=>438999,'level'=>4,'parent_user_id'=>'-1'];
  302. }
  303. function UserInfo($adzone_id){
  304. $sql = "SELECT * FROM user_adzone WHERE adzone_id = :adzone_id ";
  305. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  306. $stmt = $_PDO->prepare($sql);
  307. $stmt->execute(array(':adzone_id'=>$adzone_id));
  308. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  309. if($resultone){
  310. $sql="SELECT * FROM user_level WHERE user_id = :user_id";
  311. $stmt = $_PDO->prepare($sql);
  312. $stmt->execute(array(':user_id'=>$resultone['user_id']));
  313. $userResult = $stmt->fetch(PDO::FETCH_ASSOC);
  314. return $userResult;
  315. }
  316. else{
  317. return false;
  318. }
  319. }
  320. function userLevelInfo($user_id){
  321. $sql="SELECT * FROM user_level WHERE user_id = :user_id ";
  322. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  323. $stmt = $_PDO->prepare($sql);
  324. $stmt->execute(array(':user_id'=>$user_id));
  325. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  326. if($resultone){
  327. $myInfo=["user_id"=>$user_id,"level"=>$resultone['level'],"parent_user_id"=>$resultone['parent_user_id']];
  328. return $myInfo;
  329. }
  330. else{
  331. return false;
  332. }
  333. }
  334. function userMyInfo($user_id){
  335. $sql="SELECT * FROM users WHERE id = :user_id ";
  336. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  337. $stmt = $_PDO->prepare($sql);
  338. $stmt->execute(array(':user_id'=>$user_id));
  339. $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
  340. if($resultone){
  341. $myInfo['user_id'] = $user_id;
  342. $myInfo['origin'] = $resultone['origin'];
  343. return $myInfo;
  344. }
  345. else{
  346. return false;
  347. }
  348. }
  349. # 获取4层用户级别基础信息
  350. function userLevelandPrentInfo($resultone){
  351. $resultInfo = array();
  352. # self
  353. $userId=$resultone['user_id'];
  354. $userLevel=$resultone['level'];
  355. if($userLevel>=3){
  356. $resultInfo['userList'] = [$userId,0,0,0];
  357. $resultInfo['levelRule'] = 3000;
  358. $resultInfo['userLevel'] = [$userLevel,0,0,0];
  359. return $resultInfo;
  360. }
  361. $userParentId=$resultone['parent_user_id'];
  362. $userGrandId=$resultone['grand_father_id'];
  363. if($userParentId>0){
  364. $resulttwo=userLevelInfo($userParentId);
  365. if( !empty($resulttwo) ){
  366. # parent
  367. $userParentLevel=$resulttwo['level'];
  368. if($userParentLevel>=3){
  369. $resultInfo['userList'] = [$userId,$userParentId,0,0];
  370. $resultInfo['levelRule'] = intval($userLevel.'300');
  371. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,0,0];
  372. return $resultInfo;
  373. }
  374. if($userGrandId>0){
  375. $resultthree=userLevelInfo($userGrandId);
  376. if( !empty($resultthree) ){
  377. # grand
  378. $userGrandLevel=$resultthree['level'];
  379. if($userGrandLevel>=3){
  380. $resultInfo['userList'] = [$userId,$userParentId,$userGrandId,0];
  381. $resultInfo['levelRule'] = intval($userLevel.$userParentLevel.'30');
  382. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,$userGrandLevel,0];
  383. return $resultInfo;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. if( !$userParentId ) $userParentId=0;
  390. if( !$userGrandId ) $userGrandId=0;
  391. if( !isset($userParentLevel) ) $userParentLevel=1;
  392. if( !isset($userGrandLevel) ) $userGrandLevel=1;
  393. #三级里面没有运营商,递归上级运营商
  394. $YysInfo = YysInfo($userGrandId);
  395. $userFourId = $YysInfo['user_id'];
  396. $userFourLevel = $YysInfo['level'];
  397. # 层级规则
  398. $levelRule = $userLevel.$userParentLevel.$userGrandLevel.'3';
  399. $resultInfo['userList']=[$userId,$userParentId,$userGrandId,$userFourId];
  400. $resultInfo['levelRule'] = (int)$levelRule;
  401. $resultInfo['userLevel'] = [$userLevel,$userParentLevel,$userGrandLevel,$userFourLevel];
  402. return $resultInfo;
  403. }
  404. function orderMoney($predict_income, $RuleArr){
  405. $result = array();
  406. foreach($RuleArr as $k=>$v){
  407. if($v>0){
  408. $result[$k] = round($predict_income * $v / 100);
  409. }else{
  410. $result[$k] = 0;
  411. }
  412. }
  413. return $result;
  414. }
  415. function orderMysql($order_id,$goods_id){
  416. $sql="SELECT * from `order` where order_id=:order_id and goods_id=:goods_id";
  417. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  418. $stmt = $_PDO->prepare($sql);
  419. $stmt->execute(array(':order_id'=>$order_id,':goods_id'=>$goods_id));
  420. $orderResult = $stmt->fetch(PDO::FETCH_ASSOC);
  421. return $orderResult;
  422. }
  423. function orderType($adzone_id){
  424. $sql="SELECT * from `adzone` where adzone_id=:adzone_id";
  425. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  426. $stmt = $_PDO->prepare($sql);
  427. $stmt->execute(array(':adzone_id'=>$adzone_id));
  428. $userResult = $stmt->fetch(PDO::FETCH_ASSOC);
  429. return $userResult;
  430. }
  431. 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){
  432. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  433. if( empty($order_balance_at) ){
  434. $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)";
  435. $stmt = $_PDO->prepare($sql);
  436. $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));
  437. return $_PDO->lastinsertid();
  438. }
  439. else{
  440. $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)";
  441. $stmt = $_PDO->prepare($sql);
  442. $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));
  443. return $_PDO->lastinsertid();
  444. }
  445. }
  446. #order表订单插入脚本
  447. 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){
  448. $adzoneDetail=orderType($adzone_id);
  449. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  450. if( empty($order_balance_at) ){
  451. $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)";
  452. $stmt = $_PDO->prepare($sql);
  453. $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));
  454. return $_PDO->lastinsertid();
  455. }
  456. else{
  457. $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)";
  458. $stmt = $_PDO->prepare($sql);
  459. $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));
  460. return $_PDO->lastinsertid();
  461. }
  462. }
  463. #返利表订单插入脚本
  464. 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){
  465. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  466. if( !empty($order_balance_at) ){
  467. $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)";
  468. $stmt = $_PDO->prepare($sql);
  469. $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));
  470. return $_PDO->lastinsertid();
  471. }
  472. else{
  473. $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)";
  474. $stmt = $_PDO->prepare($sql);
  475. $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));
  476. return $_PDO->lastinsertid();
  477. }
  478. }
  479. #单独处理订单插运营商佣金
  480. 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){
  481. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  482. if( !empty($order_balance_at) ){
  483. $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)";
  484. $stmt = $_PDO->prepare($sql);
  485. $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));
  486. return $_PDO->lastinsertid();
  487. }
  488. else{
  489. $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)";
  490. $stmt = $_PDO->prepare($sql);
  491. $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));
  492. return $_PDO->lastinsertid();
  493. }
  494. }
  495. #返利表订单插入运营商津贴信息
  496. 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){
  497. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  498. if( !empty($order_balance_at) ){
  499. $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)";
  500. $stmt = $_PDO->prepare($sql);
  501. $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));
  502. return $_PDO->lastinsertid();
  503. }
  504. else{
  505. $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)";
  506. $stmt = $_PDO->prepare($sql);
  507. $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));
  508. return $_PDO->lastinsertid();
  509. }
  510. }
  511. #order订单表返利表同步更新
  512. function generateSqlupdate($status,$order_balance_at,$order_id,$goods_id){
  513. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  514. if( !empty($order_balance_at) ){
  515. $sql="update `order` set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  516. $stmt = $_PDO->prepare($sql);
  517. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  518. $res = $stmt->rowCount();
  519. //更新order_rebate
  520. $sql="update order_rebate set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  521. $stmt = $_PDO->prepare($sql);
  522. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  523. $res = $stmt->rowCount();
  524. //更新order_rebate_profit
  525. $sql="update order_rebate_profit set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  526. $stmt = $_PDO->prepare($sql);
  527. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  528. $res = $stmt->rowCount();
  529. }
  530. else{
  531. $sql="update `order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
  532. $stmt = $_PDO->prepare($sql);
  533. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  534. $res = $stmt->rowCount();
  535. $sql="update order_rebate set status=:status where order_id=:order_id and goods_id=:goods_id ";
  536. $stmt = $_PDO->prepare($sql);
  537. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  538. $res = $stmt->rowCount();
  539. //更新order_rebate_profit
  540. $sql="update order_rebate_profit set status=:status where order_id=:order_id and goods_id=:goods_id ";
  541. $stmt = $_PDO->prepare($sql);
  542. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  543. $res = $stmt->rowCount();
  544. }
  545. return $res;
  546. }
  547. #订单表单独更新
  548. function generateSqlUpdateOther($status,$order_balance_at,$order_id,$goods_id){
  549. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  550. if( !empty($order_balance_at) ){
  551. $sql="update `order` set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
  552. $stmt = $_PDO->prepare($sql);
  553. $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
  554. $res = $stmt->rowCount();
  555. }
  556. else{
  557. $sql="update `order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
  558. $stmt = $_PDO->prepare($sql);
  559. $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
  560. $res = $stmt->rowCount();
  561. }
  562. return $res;
  563. }
  564. # 获取rebateRule
  565. function getRebateRule($levelRule){
  566. $sql="SELECT * from `rebate_rule` where level_rule = :level_rule";
  567. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  568. $stmt = $_PDO->prepare($sql);
  569. $stmt->execute(array(':level_rule'=>$levelRule));
  570. $ruleResult = $stmt->fetch(PDO::FETCH_ASSOC);
  571. return $ruleResult;
  572. }
  573. # curl调用接口push
  574. function curl_post($url, $params){
  575. $ch = curl_init();
  576. curl_setopt($ch, CURLOPT_URL, $url);
  577. curl_setopt($ch, CURLOPT_HEADER, 0);
  578. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  579. curl_setopt($ch, CURLOPT_POST, 1);
  580. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  581. $response = curl_exec($ch);
  582. curl_close($ch);
  583. return $response;
  584. }
  585. readDataFromDb();