123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485 |
- <?php
- require_once 'DB_PDO.class.php';
- require_once 'TBK.class.php';
- require_once 'conf.class.php';
- define("DETAILDEBUG", 0);//打印流程详细信息,如有需要,设为1
- define("LIMIT_NUM", 0);//限制导入条数,0不限制,方便测试,上线设为0
- //define("TBK_PID_STR", 'mm_250470096_196250254_');
- define("TBK_PID_STR", 'mm_299550010_328900301_');
- //define("PUSH_URL",'https://tbk.726p.com/api/v2/MessagePush/rebatepush');//push接口地址
- /**
- * 导入及更新 order/order_rebate数据 + 淘宝拉新活动
- */
- #设置时区
- date_default_timezone_set('PRC');
- set_time_limit(0);
- ini_set('memory_limit','1024M');
- function readDataFromDb(){
- # 记录脚本开始时间
- $scriptStart = date("Y-m-d H:i:s");
- # 1.获取6分钟内订单
- //$stime = date('Y-m-d H:i:s',strtotime('2018-08-07'));
- $stime = date('Y-m-d H:i:s', time()-150);
- $sql = "SELECT * from zbds_taoke_orders where update_time > :stime ";
- $dumpsql = str_replace(':stime', "'".$stime."'", $sql);
- echo "\n\n".$dumpsql."\n";
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':stime'=>$stime));
- $orderResult = $stmt->fetchAll(PDO::FETCH_ASSOC);
- # 遍历订单
- # 统计
- $res_count = array(
- 'total_num' => 0,
- 'generalinsert_num' => 0,
- 'generalupdate_num' => 0,
- 'nouserinsert_num' => 0,
- 'nouserupdate_num' => 0,
- 'fail_insert_num' => 0,
- 'fail_insert_ids' => '',
- 'fail_insertno_num' => 0,
- 'fail_insertno_ids' => '',
- 'fail_update_num' => 0,
- //'fail_update_ids' => '',
- 'fail_updateno_num' => 0,
- //'fail_updateno_ids' => '',
- );
- foreach( $orderResult as $key=>$orderDetail ){
- $res_count['total_num']++;
- echo "/ ************************ order{$res_count['total_num']}-Start ************************* / \n";
- if( DETAILDEBUG == 1){
- echo 'orderDetail:';
- }
- //create_time,click_time,item_title,num_iid,seller_nick,seller_shop_title,item_num,price,tk_status,order_type,income_rate,commission_rate,pay_price,pub_share_pre_fee,alipay_total_price,commission,earning_time,total_commission_rate,total_commission_fee,subsidy_rate,subsidy_fee,subsidy_type,terminal_type,tk3rd_type,trade_parent_id,trade_id,auction_category,site_id,site_name,adzone_id,adzone_name,relation_id,special_id
- $order_id=$orderDetail["trade_id"];
- $update_time=$orderDetail["update_time"];
- $order_create_at=$orderDetail["create_time"];
- $order_click_at=$orderDetail["click_time"];
- $order_balance_at=$orderDetail["earning_time"];
- $goods_id=$orderDetail["num_iid"];
- $goods_name=$orderDetail["item_title"];
- $goods_name=str_replace(['"',"'"],'',$goods_name);
- $num=$orderDetail["item_num"];
- $price=intval($orderDetail["price"]*100);
- $sum_price=intval($orderDetail["alipay_total_price"]*100);
- $statusDesc=$orderDetail["tk_status"];
- $typeDesc=$orderDetail["order_type"];
- $orderStatus = 1;
- $type=1;
- if($statusDesc=="12"){
- $orderStatus=1;
- }
- elseif($statusDesc=="13"){
- $orderStatus=0;
- }
- elseif($statusDesc=="3"){
- $orderStatus=2;
- }
- if($typeDesc=="聚划算"){
- $type=0;
- }
- elseif($typeDesc=="淘宝"){
- $type=1;
- }
- elseif($typeDesc=="天猫"){
- $type=2;
- }
- $adzone_id=$orderDetail["adzone_id"];
- $relation_id = $orderDetail["relation_id"];
- $special_id = $orderDetail["special_id"];
- $ceil_income=round($orderDetail["pub_share_pre_fee"], 2);
- $predict_income=$ceil_income*100;
- $predict_income=ceil($predict_income*conf::$RATE_CONF["globalzk"]);
- echo 'order_id:'.$order_id.'|| goods_id:'.$goods_id.'|| orderstatus:'.$orderStatus.'|| order_balance_at:'.$order_balance_at;
- echo '|| predict_income:'.$predict_income.'|| adzone_id:'.$adzone_id.'|| special_id:'.$special_id.'|| relation_id:'.$relation_id."\n";
- $resultone=UserInfo($adzone_id);
- if( DETAILDEBUG == 1){
- echo 'userinfo:';
- var_dump($resultone);
- echo "\n";
- }
- if($sum_price!=0){
- if($predict_income<5){
- $predict_income=5;
- }
- }
- if( !empty($resultone) ){
- echo "User:存在\n";
- $user_id = $resultone['id'];
- $rate = $resultone['rate'];
- $orderExists=orderMysql($order_id,$goods_id);
- if( empty($orderExists) ){
- echo "action:插入操作\n";
- #获取返利
- $moneyInfo=orderMoney($predict_income, $rate); //分佣钱数
- $detail = TBK::tbkItemInfoGet( ['goods_id'=>$goods_id] );
- if( !empty($detail) ){
- $goods_img=$detail->pict_url;
- }
- else{
- $goods_img="";
- }
- try{
- $_PDO->beginTransaction();
- #订单表插入
- $res=generateSqlInsertOrder($goods_img,$goods_name,$user_id,$order_id,$adzone_id,$goods_id,$num,$price,$sum_price,$predict_income,$moneyInfo,$orderStatus,$type,3,$order_create_at,$order_click_at,$order_balance_at);
- if($res){
- $res_count['generalinsert_num']++;
- }else{
- $res_count['fail_insert_num']++;
- $res_count['fail_insert_ids'].=$order_id.'|';
- }
- echo 'orderinsert:'.$res;
- echo "\n";
- #检查sale_goods表是否有该条数据,无则插入
- $sale_goods_insert = sale_goods_insert($goods_id);
- echo 'sale_goods_insert:'.$sale_goods_insert;
- echo "\n";
-
- if($sum_price>0){
- #order_rebate表插入父级佣金
- $rebaseType=1;
- $res=generateSqlInsertRebateSelf(3,$order_balance_at,$order_create_at,$goods_img,$goods_name,$order_id,$user_id,$rebaseType,$moneyInfo,$sum_price,$orderStatus,$goods_id,$predict_income,$num);
- # 推送
- /*$flag_time = time() - strtotime($order_create_at);
- if($res && $flag_time<3600){
- $params = array();
- $params['user_id'] = $user_id;
- $params['type'] = 2;
- $params['money'] = round($moneyInfo/100,2);
- $push_res = curl_post( PUSH_URL, $params);
- }*/
- echo 'rebateinsert:'.$res;
- echo "\n";
-
- }
- $_PDO->commit();
- }catch(PDOException $e){
- echo 'err_msg'.$e->getMessage()."\n";
- $_PDO->rollback();
- }
- //echo "-----------------insertEnd--------------------\n";
- }
- else{
- try{
- $_PDO->beginTransaction();
- //更新order/order_rebate表
- echo "action:更新操作\n";
- $res=generateSqlupdate($orderStatus,$order_balance_at,$order_id,$goods_id);
- if($res){
- $res_count['generalupdate_num']++;
- }else{
- $res_count['fail_update_num']++;
- //$res_count['fail_update_ids'].=$order_id.'|';
- }
- echo "更新数据-> orderstatus:".$orderStatus." order_balance_at:".$order_balance_at;
- echo "\n";
- echo "order/reabte_update:".$res;
- echo "\n";
- //echo "-----------------updateEnd-----------------------\n";
- $_PDO->commit();
- }catch(PDOException $e){
- echo 'err_msg'.$e->getMessage()."\n";
- $_PDO->rollback();
- }
- }
- //echo "-----------------IssetUserEnd:--------------------\n";
- }
- else{
- $_PDO->beginTransaction();
- try{
- #user不存在的处理
- echo "User:不存在\n";
- $ordernoExists=orderMysql($order_id,$goods_id);
-
- if( empty($ordernoExists) ){
- $detail = TBK::tbkItemInfoGet( ['goods_id'=>$goods_id] );
- if( !empty($detail) ){
- $goods_img=$detail->pict_url;
- }
- else{
- $goods_img="";
- }
- $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);
- if($res){
- $res_count['nouserinsert_num']++;
- }else{
- $res_count['fail_insertno_num']++;
- $res_count['fail_insertno_ids'].=$order_id.'|';
- }
- echo "action:插入操作\n";
- echo "orderinsert:".$res;
- echo "\n";
-
- $_PDO->commit();
- }
- else{
- $res=generateSqlUpdateOther($orderStatus,$order_balance_at,$order_id,$goods_id);
- if($res){
- $res_count['nouserupdate_num']++;
- }else{
- $res_count['fail_updateno_num']++;
- //$res_count['fail_updateno_ids'].=$order_id.'|';
- }
- echo "action:更新操作\n";
- echo "orderupdate:".$res;
- echo "\n";
- $_PDO->commit();
- }
- //echo "-----------------EmptyUserEnd:--------------------\n";
-
- }catch(PDOException $e){
- echo 'err_msg'.$e->getMessage()."\n";
- $_PDO->rollback();
- }
- }
- echo "/ ** order{$res_count['total_num']}-End ** /";
- echo "\n\n\n";
- if(LIMIT_NUM >0 && $res_count['total_num'] == LIMIT_NUM) break;
- }
- print_r($res_count);
- echo "\n本次脚本开始时间:". $scriptStart;
- echo "\n本次脚本结束时间:". date("Y-m-d H:i:s");
- }
- function UserInfo($adzone_id){
- $sql = "SELECT id,rate FROM users WHERE adzone_id = :adzone_id ";
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':adzone_id'=>$adzone_id));
- $resultone = $stmt->fetch(PDO::FETCH_ASSOC);
- if(!empty($resultone)){
- return $resultone;
- }
- else{
- return false;
- }
- }
- function orderMoney($predict_income, $rate){
- $result = round($predict_income * $rate / 100);
- return $result;
- }
- function orderMysql($order_id,$goods_id){
- $sql="SELECT * from `order` where order_id=:order_id and goods_id=:goods_id";
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':order_id'=>$order_id,':goods_id'=>$goods_id));
- $result = $stmt->fetch(PDO::FETCH_ASSOC);
- return $result;
- }
- 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){
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- if( empty($order_balance_at) ){
- $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)";
-
- $stmt = $_PDO->prepare($sql);
- $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));
-
- return $_PDO->lastinsertid();
- }
- else{
- $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)";
-
- $stmt = $_PDO->prepare($sql);
- $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));
-
- return $_PDO->lastinsertid();
- }
- }
- #order表订单插入脚本
- 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){
- //$adzoneDetail=orderType($adzone_id);
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- if( empty($order_balance_at) ){
- $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)";
-
- $stmt = $_PDO->prepare($sql);
- $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));
-
- return $_PDO->lastinsertid();
- }
- else{
- $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)";
- $stmt = $_PDO->prepare($sql);
- $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));
- return $_PDO->lastinsertid();
- }
- }
- #返利表订单插入脚本
- 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,$num){
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- if( !empty($order_balance_at) ){
- $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,num) 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,:num)";
- $stmt = $_PDO->prepare($sql);
- $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,':num'=>$num));
- return $_PDO->lastinsertid();
- }
- else{
- $sql="insert into order_rebate (user_level,order_create_at,img,name,order_id,user_id,type,rebate,money,status,goods_id,pre_income,num) VALUES (:user_level,:order_create_at,:goods_img,:goods_name,:order_id,:userId,:rebaseType,:last_orderSelfRebaseRebase,:sum_price,:orderStatus,:goods_id,:pre_income,:num)";
- $stmt = $_PDO->prepare($sql);
- $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,':num'=>$num));
- return $_PDO->lastinsertid();
- }
- }
- #order订单表返利表同步更新
- function generateSqlupdate($status,$order_balance_at,$order_id,$goods_id){
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- if( !empty($order_balance_at) ){
- $sql="update `order` set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
- $res = $stmt->rowCount();
- //更新order_rebate
- $sql="update order_rebate set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
- $res = $stmt->rowCount();
- }
- else{
- $sql="update `order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
- $res = $stmt->rowCount();
- $sql="update order_rebate set status=:status where order_id=:order_id and goods_id=:goods_id ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
- $res = $stmt->rowCount();
- }
- return $res;
- }
- #订单表单独更新
- function generateSqlUpdateOther($status,$order_balance_at,$order_id,$goods_id){
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- if( !empty($order_balance_at) ){
- $sql="update `order` set status=:status,order_balance_at=:order_balance_at where order_id=:order_id and goods_id=:goods_id ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':status'=>$status,':order_balance_at'=>$order_balance_at,':order_id'=>$order_id,':goods_id'=>$goods_id));
- $res = $stmt->rowCount();
- }
- else{
- $sql="update `order` set status=:status where order_id=:order_id and goods_id=:goods_id ";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':status'=>$status,':order_id'=>$order_id,':goods_id'=>$goods_id));
- $res = $stmt->rowCount();
- }
- return $res;
- }
- function sale_goods_insert($goods_id){
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $sql = "select id from sale_goods where num_iid = :goods_id limit 1";
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':goods_id'=>$goods_id));
- $res = $stmt->fetch(PDO::FETCH_ASSOC);
- $ins = 0;
- if(empty($res)){
- $keyword = "https://item.taobao.com/item.htm?id=".$goods_id;
- $goodsInfo = TBK::search($keyword);
- if(!isset($goodsInfo->num_iid)) return false;
- if(isset($goodsInfo->coupon_id) && !empty($goodsInfo->coupon_id)){
- preg_match_all('/[\d]+/',$goodsInfo->coupon_info,$d);
- $coupon_price = isset($d[0][2]) ? $d[0][2] : $d[0][1];
- } else {
- $coupon_price = "0";
- }
- $discount_price = changeGoodsBranchToElement(isset($goodsInfo->coupon_id) && !empty($goodsInfo->coupon_id) ? $goodsInfo->zk_final_price - $coupon_price : $goodsInfo->zk_final_price);
- $commission_price = changeGoodsBranchToElement($discount_price * $goodsInfo->commission_rate/10000);
- $data = array();
- $data['num_iid'] = $goodsInfo->num_iid;
- $data['coupon_id'] = isset($goodsInfo->coupon_id) ? $goodsInfo->coupon_id : '';
- $data['pict_url'] = $goodsInfo->pict_url;
- $data['white_image'] = isset($goodsInfo->white_image) ? $goodsInfo->white_image : '';
- $data['small_images'] = isset($goodsInfo->small_images->string) ? serialize(json_decode(json_encode($goodsInfo->small_images->string),true)) : '';
- $data['seller_id'] = $goodsInfo->seller_id;
- $data['shop_title'] = $goodsInfo->shop_title;
- $data['short_title'] = isset($goodsInfo->short_title) ? $goodsInfo->short_title : $goodsInfo->title;
- $data['coupon_total_count'] = $goodsInfo->coupon_total_count;
- $data['user_type'] = $goodsInfo->user_type;
- $data['coupon_info'] = $goodsInfo->coupon_info;
- $data['coupon_price'] = $coupon_price;
- $data['coupon_start_time'] = $goodsInfo->coupon_start_time;
- $data['coupon_end_time'] = $goodsInfo->coupon_end_time;
- $data['zk_final_price'] = $goodsInfo->zk_final_price;
- $data['reserve_price'] = $goodsInfo->reserve_price;
- $data['commission_rate'] = $goodsInfo->commission_rate;
- $data['commission_price'] = $commission_price;
- $data['coupon_remain_count'] = $goodsInfo->coupon_remain_count;
- $data['tk_total_sales'] = $goodsInfo->tk_total_sales;
- $data['live_price'] = $discount_price;
- $data['volume'] = $goodsInfo->volume;
- $data['url'] = isset($goodsInfo->coupon_share_url) && !empty($goodsInfo->coupon_share_url) ? $goodsInfo->coupon_share_url : $goodsInfo->url;
- $data['status'] = 1;
- $sql = getinsertSql($data, 'sale_goods');
- $stmt = $_PDO->prepare($sql);
- $stmt->execute();
- $ins = $_PDO->lastinsertid();
- }
- return $ins;
- }
- function changeGoodsBranchToElement($num){
- return Number_format($num,2, '.','');
- }
- function getinsertSql($data,$table){
- $columns = '';
- $values = '';
- foreach($data as $k=>$v){
- $columns .= $k.',';
- $values .= "'".$v."',";
- }
- $sql = " insert into {$table}(".trim($columns,',').") values(".trim($values,',').")";
- return $sql;
- }
- # curl调用接口push
- function curl_post($url, $params){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- $response = curl_exec($ch);
- curl_close($ch);
- return $response;
- }
- readDataFromDb();
|