• 电商中设置满包邮,满减等促销搞活动;电商平台同步到第三方,日志记录


    1.添加同步:

    if($import_shop_activity ['base_info'] ['status'] == 1 )
    {
    foreach ( $r as $v ) {
    if ($v ['code'] == 0) {
    // 批量插入信息之后,获取到每个的id,再写入详情
    foreach ( $import_shop_activity ['detail'] as $vt ) {
    //以前只有reduce_price 现在添加 free_delivery(包快递) 、free_logistics (包物流) 、free_service (免服务费 ) 、discount_server (服务费打折)
    /*
    * 1.插入满减
    * 2.插入满包邮
    * 3.插入免服务和折服务 201510211113 梁大光
    */
    //满减-
    if(!empty($vt['input_arrive']) && ($vt['input_arrive'] > 0))
    {
    switch($vt['type'])
    {
    case 'add_discount':
    $all_insert_item [] = array (
    'item_parent_id' => $v ['generateKey'],
    'item_type' => 'reduce_price',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2' => (float)$vt ['item_action'] <= 0 ? 0 : $vt ['item_action']
    );
    break;

    case 'logistics':
    $all_insert_item [] = array (
    'item_parent_id' => $v ['generateKey'],
    'item_type' => 'free_logistics',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2' => 1
    );
    break;

    case 'express':
    $all_insert_item [] = array (
    'item_parent_id' => $v ['generateKey'],
    'item_type' => 'free_delivery',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2' => 1
    );
    break;

    case 'service_free':
    $all_insert_item [] = array (
    'item_parent_id' => $v ['generateKey'],
    'item_type' => 'free_server',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2' =>(float) $vt ['item_action']
    );
    break;

    case 'service_discount':
    $all_insert_item [] = array (
    'item_parent_id' => $v ['generateKey'],
    'item_type' => 'discount_server',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2' => (float)$vt ['item_action'] <= 0 ? 100 : $vt ['item_action']
    );
    break;
    default:
    break;
    }
    }
    }
    }
    }
    $log_pid = array();
    foreach($all_insert_item as $key => $value)
    {
    $log_pid[] = $value['item_parent_id'];
    }
    //去掉log_pid 中重复部分
    $log_pid = array_unique($log_pid);
    $item_status = write_autoExecute ( "XXX", $all_insert_item, 'batch_insert' );
    if(!empty($item_status))
    { //只有真正的有满减活动规则存在的候时我才写日志
    $insert_data_array = array();
    $note = '系统,新建:'.$import_shop_activity ['base_info'] ['subject'];
    foreach($log_pid as $key => $val)
    {
    $insert_data_array[] = array (
    'user_id' => '0',
    'note' => $note,
    'pid' => $val,
    'type' => 'reduce_price_log',
    'add_time' => time (),
    'platform' => $platform
    );
    }


    2.编辑同步:

    $activity_log = '';
    foreach($old_activity as $key => $val)
    {
    switch ($key)
    {
    case 'subject':
    if(!empty($val) && ($val != $import_shop_activity ['base_info'] ['subject']))
    $activity_log .= '编辑[活动名称]:'.$val.'-->'.$import_shop_activity ['base_info'] ['subject'].'; ';
    if(empty($val) && ($val != $import_shop_activity ['base_info'] ['subject']))
    $activity_log .= '新增[活动名称]:'.$import_shop_activity ['base_info'] ['subject'].'; ';
    break;
    case 'link_url':
    if(!empty($val) && ($val!= $import_shop_activity ['base_info'] ['link_url']))
    $activity_log .= '编辑[活动链接]:'.$val.'-->'.$import_shop_activity ['base_info'] ['link_url'].'; ';
    if(empty($val) && ($val != $import_shop_activity ['base_info'] ['link_url']))
    $activity_log .= '新增[活动链接]:'.$import_shop_activity ['base_info'] ['link_url'].'; ';
    break;
    case 'starttime':
    if(!empty($val) && ($val != $import_shop_activity ['base_info'] ['starttime']))
    $activity_log .= '编辑[开始时间]:'.date('Y-m-d H:i:s',$val).'-->'.date('Y-m-d H:i:s',$import_shop_activity ['base_info'] ['starttime']).'; ';
    break;
    case 'endtime':
    if(!empty($val) && ($val != $import_shop_activity ['base_info'] ['endtime']))
    $activity_log .= '编辑[结束时间]:'.date('Y-m-d H:i:s',$val).'-->'.date('Y-m-d H:i:s',$import_shop_activity ['base_info'] ['endtime']).'; ';
    break;
    default :
    break;
    }
    if($key == 'status' && ($val != $import_shop_activity ['base_info'] ['status']))
    {
    $status_log_old = $val == 1 ? '开启' : '关闭';
    $status_log_now = $val == 1 ? '关闭' : '开启';
    $sts = $val == 0 ? 1 : '';
    ($val == 0 && empty($result_item)) ? $activity_log .= '复制:'.$import_shop_activity ['base_info'] ['subject'].'; ' : $activity_log .= '编辑[活动状态]:'.$status_log_old.'-->'.$status_log_now.'; ';
    }
    }

    // 第三方没关闭的活动,要同步状态 目的是关闭活动 20151026 梁大光
    if ($import_shop_activity ['base_info'] ['status'] == 0)
    {
    //如果是从复制到复制 那么就直接结束
    if(!empty($result_item))
    {
    $where = array (array ('key' => 'from_mll_act_id', 'op' => '=','value' => $import_shop_activity ['base_info'] ['id']) , array ('key' => 'pro_status','op' => '=','value' => 1 )); //只关闭没有没停用的用户
    $status = write_autoExecute ( "XXX", array ('pro_status' => 0), 'update' ,$where );
    }
    else
    {
    header("Location: /admin/new_promotion_activity.php?act=list");
    exit;
    }

    }elseif($import_shop_activity ['base_info'] ['status'] == 1 )
    {
    //现在就用2种情况了 1.原来的status = 有 0 系统自己停用的 :禁用 1 开启 状态 2 用户停用的 :停用
    $where = array (array ('key' => 'from_mll_act_id','op' => '=', 'value' => $import_shop_activity ['base_info'] ['id']),array ('key' => 'pro_status','op'=> '=','value' => 0));
    //1.原来的status = 0
    $status_new = write_autoExecute ( "XXX", array ('pro_status' => 1), 'update',$where);
    }else{}
    $result = mainUniRE ( 'Third_BUV1_Shoppromotion', array (
    'from_mll_act_id' => $import_shop_activity ['base_info'] ['id']
    ) );
    if ($result ['error'] != 0) {
    sys_msg ( "同步活动到第三方失败,规则别名:Third_BUV1_Shoppromotion 返回失败" );
    }
    $old_item = array();
    foreach($old_activity_item as $key => $val)
    {
    if($val['is_valid'] == 1)
    {
    $old_item[$val['type']] = array(
    'input_arrive' => $val['input_arrive'],
    'item_action' => $val['item_action'],
    );
    }
    $old_item_arr[] = $old_item;
    }

    $all_insert_data = array ();
    $all_shop_ids = array ();
    $result = shop_unique($result);
    $pro_id_log = array();
    foreach ( $result ['msg'] as $v ) {
    $pro_id = $v ['pro_id'];
    $pro_id_log []= $v ['pro_id'];
    $all_shop_ids [] = $v ['pro_shop'];
    //取出status == 2 的活动id 然后再重新插入一条相同的活动
    if($v['pro_status'] == 2 && ($old_activity['status'] ==0) )
    {
    $all_update_new []= array (
    'pro_name' => $import_shop_activity ['base_info'] ['subject'],
    'pro_time_start' => $import_shop_activity ['base_info'] ['starttime'],
    'pro_time_end' => $import_shop_activity ['base_info'] ['endtime'],
    'pro_desc' => $import_shop_activity ['base_info'] ['subject'],
    'pro_link' => $import_shop_activity ['base_info'] ['link_url'],
    'pro_type' => 'reduce_price',
    'pro_is_all' =>1,
    'pro_genre' =>1,
    'pro_save_time' =>time(),
    'pro_shop' =>$v['pro_shop'],
    'pro_status' =>1,
    'pro_is_delete' =>0,
    'pro_shop' =>$v['pro_shop'],
    'from_mll_act_id' =>$import_shop_activity ['base_info'] ['id']
    );
    }
    // 删除之前的满减活动
    write_autoExecute ( "XXX", $all_update_data, 'delete', array (
    array (
    'key' => 'item_parent_id',
    'op' => '=',
    'value' => $pro_id
    )
    ) );
    $new_pro_item = array();
    /*var_dump($old_item);exit;*/
    $pro_type_arr = array();
    foreach ( $import_shop_activity ['detail'] as $k => $vt ) {
    //以前只有reduce_price 现在添加 free_delivery(包快递) 、free_logistics (包物流) 、free_service (免服务费 ) 、discount_server (服务费打折) 20151027 梁大光
    //满减
    $pro_type_arr[$k] = $vt['type'];

    if(!empty($vt['input_arrive']) && ($vt['input_arrive'] > 0))
    {
    switch($vt['type'])
    {
    case 'add_discount':
    $all_insert_item [] = array (
    'item_parent_id' => $pro_id,
    'item_type' => 'reduce_price',
    'item_value_1' => (float)$vt ['input_arrive'] ,
    'item_value_2' => (float)$vt ['item_action'] <= 0 ? 0 :$vt ['item_action']
    );
    $new_pro_item[] = array(
    'item_type' => 'reduce_price',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2'=> (float)$vt ['item_action']
    );
    break;

    case 'logistics':
    $all_insert_item [] = array (
    'item_parent_id' => $pro_id,
    'item_type' => 'free_logistics',
    'item_value_1' => $vt ['input_arrive'] ,
    'item_value_2' => '1'
    );
    $new_pro_item[] = array(
    'item_type' => 'free_logistics',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2'=> (float)$vt ['item_action']
    );
    break;

    case 'express':
    $all_insert_item [] = array (
    'item_parent_id' => $pro_id,
    'item_type' => 'free_delivery',
    'item_value_1' => (float)$vt ['input_arrive'] ,
    'item_value_2' => '1'
    );
    $new_pro_item[] = array(
    'item_type' => 'free_delivery',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2'=> '1'
    );
    break;

    case 'service_free':
    $all_insert_item [] = array (
    'item_parent_id' => $pro_id,
    'item_type' => 'free_server',
    'item_value_1' => (float)$vt ['input_arrive'] ,
    'item_value_2' => (float)$vt ['item_action'],
    );
    $new_pro_item[] = array(
    'item_type' => 'free_server',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2'=> (float)$vt ['item_action']
    );
    break;

    case 'service_discount':
    $all_insert_item [] = array (
    'item_parent_id' => $pro_id,
    'item_type' => 'discount_server',
    'item_value_1' => (float)$vt ['input_arrive'] ,
    'item_value_2' => (float)$vt ['item_action'] <= 0 ? 100 : $vt ['item_action']
    );
    $new_pro_item[] = array(
    'item_type' => 'discount_server',
    'item_value_1' => (float)$vt ['input_arrive'],
    'item_value_2'=> (float)$vt ['item_action']
    );
    break;
    default:
    break;
    }
    }
    }
    }
    // $now_item , $old_activity_item
    if(!empty($old_activity_item) && !empty($now_item))
    {
    $note_3 = $note_4 = $note_5 = '';
    $pro_now_id = $pro_old_id =$pro_now_arr = array();
    foreach($now_item as $key => $val)
    {
    if(empty($val['rec_id']))
    {
    switch ($val['type'])
    {
    case 'add_discount':
    $note_3 .= '新增[满减活动]满'.$val['input_arrive'].'元-->'.$val['item_action'].'元;' ;
    break;
    case 'logistics':
    $note_3 .= '新增[包物流活动]满'.$val['input_arrive'].'元-->包物流' ;
    break;
    case 'express':
    $note_3 .= '新增[包快递活动]满'.$val['input_arrive'].'元-->包快递;';
    break;
    case 'service_free':
    $within = ((float)$val['item_action']) ? '订单金额'.((float) $val['item_action']).'%以内;' : ';';
    $note_3 .=' 新增[免服务费活动]满'.$val['input_arrive'].'元-->免服务费,'.$within;
    break;
    case 'service_discount':
    $discount = ((float)$val['item_action']) ? '服务费打'.((float) $val['item_action']).'折;' : '服务费打折;';
    $note_3 .= '新增[服务费打折活动]满'.$val['input_arrive'].'-->'.$discount;
    break;
    default:
    break;
    }
    }
    else
    {
    $pro_now_id[]=intval($val['rec_id']);
    $id=intval($val['rec_id']);
    $pro_now_arr[$id]=$val;
    }
    }
    //删除和编辑活动项目
    foreach($old_activity_item as $key => $val)
    {
    if(!empty($val['is_valid']))
    {
    if(!in_array($val['rec_id'],$pro_now_id))
    {
    $input = (float)$val['input_arrive'];
    $item_action = (float)$val['item_action'];
    switch ($val['type'])
    {
    case 'add_discount':
    $note_4 .= '编辑[满减活动]取消满'.$input.'-->减'.$item_action.'元活动;' ;
    break;
    case 'logistics':
    $note_4 .= '编辑[包物流活动]取消满'.$input.'包物流活动;' ;
    break;
    case 'express':
    $note_4 .= '编辑[包快递活动]取消满'.$input.'包快递活动;';
    break;
    case 'service_free':
    $note_4 .='编辑[免服务费活动]取消满'.$input.'勉服务费活动;';
    break;
    case 'service_discount':
    $note_4 .= '编辑[服务费打折活动]取消满'.$input.'服务费打折活动;';
    break;
    default:
    break;
    }
    }
    elseif(in_array($val['rec_id'],$pro_now_id))
    {
    if(((float)$val['input_arrive']) != ((float)$pro_now_arr[$val['rec_id']]['input_arrive']) || (((float)$val['item_action']) != ((float)$pro_now_arr[$val['rec_id']]['item_action'])))
    {
    switch ($val['type'])
    {
    case 'add_discount':
    $note_5 .= '编辑[满减活动]满'. ((float)$val['input_arrive']).'元减'.((float)$val['item_action']).'元-->满'.((float)$pro_now_arr[$val['rec_id']]['input_arrive']).'元减'. ((float)$pro_now_arr[$val['rec_id']]['item_action']).'元; ';
    break;
    case 'logistics':
    $note_5 .= '编辑[包物流活动]满'.((float)$val['input_arrive']).'包物流-->满'.(float)$pro_now_arr[$val['rec_id']]['input_arrive'].'包物流; ';
    break;
    case 'express':
    $note_5 .= '编辑[包快递活动]满'.((float)$val['input_arrive']).'包快递-->满'.(float)$pro_now_arr[$val['rec_id']]['input_arrive'].'包快递; ';
    break;
    case 'service_free':
    $service_free_old = (float)$val['item_action'] !=0 ? '订单金额'.((float)$val['item_action']).'%以内' : '免服务费';
    $service_free_new = (float)$pro_now_arr[$val['rec_id']]['item_action'] !=0 ? '订单金额'.(float)$pro_now_arr[$val['rec_id']]['item_action'].'%以内' : '免服务费';
    $note_5 .='编辑[免服务费活动]满'.((float)$val['input_arrive']).$service_free_old.'-->满'.(float)$pro_now_arr[$val['rec_id']]['input_arrive'].$service_free_new.'; ';
    break;
    case 'service_discount':
    $service_discount_old = (float)$val['item_action'] != 0 ? '服务费打'.((float)$val['item_action']).'折' : '服务费打折';
    $service_discount_new = (float)$pro_now_arr[$val['rec_id']]['item_action'] !=0 ? '服务费打'.(float)$pro_now_arr[$val['rec_id']]['item_action'].'折' : '服务费打折';
    $note_5 .= '编辑[服务费打折活动]满'.((float)$val['input_arrive']).$service_discount_old.'-->满'.(float)$pro_now_arr[$val['rec_id']]['input_arrive'].$service_discount_new.'; ';
    break;
    default:
    break;
    }
    }
    }else{}
    }
    }
    }


    3.在一个多维数组中去掉底层数组中某一个重复的值
    function shop_unique ($a)
    {
    $b=array();
    $result=array();
    foreach($a as $e){
    if(!empty($e) && is_array($e))
    {
    foreach($e as $v)
    {
    $id=intval($v['pro_shop']);
    $b[$id]=isset($b[$id]) ? $v['pro_save_time']> $b[$id]['pro_save_time'] ? $v:$b[$id] : $v;
    $result = array(
    'error' =>0,
    'msg' => array_values($b)
    );
    }
    }
    }
    return $result;
    }


     
  • 相关阅读:
    classloader加载类原理
    要学的东西
    ArcGIS 10 帮助
    ArcGIS Server发布移动地图服务(mobile data access)时的问题
    SDE的性能取决于
    用oracle trace 来跟踪session
    ArcSDE10升级sp1后服务无法启动的解决办法
    ArcSDE 发布 WMS 服务出错
    ArcSDE10升级sp1后服务无法启动的解决办法
    ArcGIS Server发布移动地图服务(mobile data access)时的问题
  • 原文地址:https://www.cnblogs.com/da-guang/p/4933558.html
Copyright © 2020-2023  润新知