Exemplo n.º 1
0
 function action_activity_save($name, $content, $period, $sale_target, $delivery_type, $ship_name, $ship_tel, $default_side, $url_path, $ship_province, $ship_city, $ship_county, $ship_addr, $styles, $svg_front, $svg_back, $svg_third, $svg_fourth)
 {
     try {
         self::_db()->bt();
         $period = intval($period);
         $sale_target = intval($sale_target);
         if (!$name) {
             throw new Exception("活动名称不能为空");
         }
         if (!$content) {
             throw new Exception("活动描述不能为空");
         }
         if (!$period) {
             throw new Exception("活动期限不能为空");
         }
         if (!$sale_target) {
             throw new Exception("活动目标不能为空");
         }
         if (!$url_path) {
             throw new Exception("活动网址后缀不能为空");
         }
         if (!$default_side) {
             throw new Exception("默认面不能为空");
         }
         PtApp::session_start();
         $session_id = session_id();
         $_design_info = self::_redis()->get("user_design_info_" . $session_id);
         if (!$_design_info) {
             throw new Exception("设计不存在");
         }
         $design_info = json_decode($_design_info, 1);
         $url_res = self::_db()->select_row("select id from et_activity_info where url_path = ?", $url_path);
         if ($url_res) {
             throw new Exception("活动网址后缀已存在");
         }
         if (!$styles) {
             throw new Exception("款式不能为空");
         }
         //todo
         $uid = 0;
         $styles = json_decode($styles, 1);
         $start_time = date_time_now();
         $end_time = date('Y-m-d H:i:s', strtotime('+' . $period . ' day'));
         $design_row = array('app_id' => 1, 'uid' => $uid, 'info' => $_design_info, 'colors' => $design_info['color_count']);
         $design_id = self::_db()->insert("designs", $design_row);
         $bucket_root = PtApp::$setting['aliyun_oss']['bucket_root'];
         $design_svg_side_row = array();
         if ($svg_front) {
             $svg_front_image = Model_Aliyun_Oss::upload_content($svg_front, $bucket_root . "/design/svg/" . $design_id . "/front.svg");
             $design_svg_side_row[] = array('svg_url' => $svg_front_image, 'design_id' => $design_id, 'side' => "front", 'create_time' => date("Y-m-d H:i:s"));
         }
         if ($svg_back) {
             $svg_back_image = Model_Aliyun_Oss::upload_content($svg_back, $bucket_root . "/design/svg/" . $design_id . "/back.svg");
             $design_svg_side_row[] = array('svg_url' => $svg_back_image, 'design_id' => $design_id, 'side' => "back", 'create_time' => date("Y-m-d H:i:s"));
         }
         if ($svg_third) {
             $svg_third_image = Model_Aliyun_Oss::upload_content($svg_third, $bucket_root . "/design/svg/" . $design_id . "/third.svg");
             $design_svg_side_row[] = array('svg_url' => $svg_third_image, 'design_id' => $design_id, 'side' => "third", 'create_time' => date("Y-m-d H:i:s"));
         }
         if ($svg_fourth) {
             $svg_fourth_image = Model_Aliyun_Oss::upload_content($svg_fourth, $bucket_root . "/design/svg/" . $design_id . "/fourth.svg");
             $design_svg_side_row[] = array('svg_url' => $svg_fourth_image, 'design_id' => $design_id, 'side' => "fourth", 'create_time' => date("Y-m-d H:i:s"));
         }
         //return $design_svg_side_row;
         if (empty($design_svg_side_row)) {
             throw new Exception("设计不能为空");
         }
         self::_db()->insert("design_svg_side", $design_svg_side_row);
         $row_old = array("deadline" => $period, "start_time" => $start_time, "end_time" => $end_time, "real_end_time" => $end_time, "name" => $name, "description" => $content, "abstract" => mb_substr($content, 0, 200), "delivery_type" => $delivery_type, "status" => "ongoing", "default_product_style_id" => $design_info['style_id'], "sales_target" => $sale_target, "thumb_img_url" => "", "thumb_svg_url" => "", "design_id" => $design_id);
         $id = self::_db()->insert("activities", $row_old);
         $row = array("id" => $id, "name" => $name, "content" => $content, "uid" => $uid, "period" => $period, "sale_target" => $sale_target, "url_path" => $url_path, "default_side" => $default_side, "delivery_type" => $delivery_type, "status" => 1, "colors" => $design_info['color_count'], "start_time" => $start_time, "end_time" => $end_time, "thumb_img_url" => "", "thumb_svg_url" => "", "default_style_id" => $design_info['style_id']);
         self::_db()->insert("et_activity_info", $row);
         if ($delivery_type == 'unity') {
             if (!$ship_name) {
                 throw new Exception("收货人姓名不能为空");
             }
             if (!$ship_tel) {
                 throw new Exception("收货人电话不能为空");
             }
             if (!$ship_province) {
                 throw new Exception("收货人省不能为空");
             }
             if (!$ship_city) {
                 throw new Exception("收货人市不能为空");
             }
             if (!$ship_county) {
                 throw new Exception("收货人区不能为空");
             }
             if (!$ship_addr) {
                 throw new Exception("收货人详细地址不能为空");
             }
             self::_db()->insert("et_activity_ship", array("id" => $id, "name" => $ship_name, "tel" => $ship_tel, "province" => $ship_province, "city" => $ship_city, "county" => $ship_county, "addr" => $ship_addr));
         }
         $row_styles = array();
         foreach ($styles as $style_id => $style) {
             $row_styles[] = array("activity_id" => $id, "product_style_id" => $style_id, "product_id" => $style['product_id'], "sell_price" => $style['price']);
         }
         self::_db()->insert("activity_product_styles", $row_styles);
         self::_redis()->delete("user_design_info_" . $session_id);
         //self::_db()->commit();
     } catch (Exception $e) {
         self::_db()->rollback();
         throw new Exception($e->getMessage());
     }
     return "保存成功";
 }
Exemplo n.º 2
0
 function action_png1()
 {
     $id = 3281;
     $env = PtApp::$ENV;
     $path_pro = PATH_PRO;
     $act = self::_db()->select_row("select default_product_style_id,design_id from activities where id = ?", $id);
     $_styles = self::_db()->select_rows("select aps.sell_price,aps.product_id,aps.product_style_id,\n                s.color_name,s.color,s.is_default\n                from activity_product_styles as aps\n                left join et_product_style as s on s.id = aps.product_style_id\n                where activity_id = ? order by aps.id asc", $id);
     $product_ids = array();
     $product_style_ids = array();
     foreach ($_styles as $style) {
         $product_ids[] = $style['product_id'];
         $product_style_ids[] = $style['product_style_id'];
     }
     $product_ids = array_unique($product_ids);
     $product_style_ids = array_unique($product_style_ids);
     $_products = self::_db()->select_rows("select content,name,id from et_product where id in (" . implode(",", $product_ids) . ")");
     $_product_designs = self::_db()->select_rows("select * from et_product_design where product_id in (" . implode(",", $product_ids) . ")");
     foreach ($_products as $_product) {
         $_product['content'] = replace_cdn($_product['content']);
         $products[$_product['id']] = $_product;
     }
     $product_designs = array();
     foreach ($_product_designs as $_product_design) {
         $product_designs[$_product_design['product_id']][$_product_design['side']] = $_product_design;
     }
     $_act_product_designs = self::_db()->select_rows("select * from et_activity_product where activity_id = ?", $id);
     $_sides = array("front", "back", "third", "fourth");
     $__act_designs = array();
     if (!$_act_product_designs) {
         $_act_designs = self::_db()->select_rows("select svg_url,side from design_svg_side where design_id = ?", $act['design_id']);
         //print_r($_act_designs);exit;
         //return $_act_designs;
         foreach ($_act_designs as $_act_design) {
             $svg_url = $_act_design['svg_url'];
             //pt_debug($svg_url);
             $_svg_content = file_get_contents($svg_url);
             $side = $_act_design['side'];
             foreach ($product_ids as $product_id) {
                 $design_info = $product_designs[$product_id][$side];
                 //return $design_info;
                 $x = $design_info['x'];
                 $y = $design_info['y'];
                 $img_url = $design_info['img_url'];
                 $img_content = file_get_contents($img_url);
                 //echo $img_content;
                 $img_content = "data:image/png;base64," . base64_encode($img_content);
                 $svg_content = "<svg x='" . $x / 2 . "' y='" . $y / 2 . "'" . substr($_svg_content, 4);
                 $tpl_content = '<svg height="500" width="500" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"  style="overflow: hidden; position: relative;" viewBox="0 0 500 500" preserveAspectRatio="xMidYMid meet"><image x="0" y="0" width="500" height="500" preserveAspectRatio="none" xlink:href="' . $img_content . '" transform="matrix(1,0,0,1,0,0)"></image>' . $svg_content . '</svg>';
                 $name = "{$env}_{$id}_{$product_id}_{$side}";
                 $local_svg = "/tmp/activity_pic_{$name}.svg";
                 $local_png = "/tmp/activity_pic_test_{$name}.png";
                 $remote_png = "{$env}/activity/pic/{$name}.png";
                 file_put_contents($local_svg, $tpl_content);
                 $cmd = "python {$path_pro}/bin/svg/convert.py {$local_svg} {$local_png}";
                 //pt_debug($cmd);
                 shell_exec($cmd);
                 //continue;
                 Model_Aliyun_Oss::upload_file($local_png, $remote_png);
                 $url = "http://cdn.open.easytee.me/" . $remote_png;
                 pt_debug($url);
                 @unlink($local_png);
                 @unlink($local_svg);
                 $_act_product_designs[] = array("activity_id" => $id, "product_id" => $product_id, "side" => $side, "img_url" => $url, "add_time" => date_time_now());
                 //echo $url.PHP_EOL;
             }
         }
     }
     foreach ($_act_product_designs as $_act_product_design) {
         $act_designs[$_act_product_design['product_id']][$_act_product_design['side']] = $_act_product_design['img_url'];
     }
     $default_product_style_id = $act['default_product_style_id'];
     $styles = array();
     foreach ($_styles as $style) {
         if ($style["product_style_id"] == $default_product_style_id) {
             $default_style = $style;
         }
         $styles[$style['product_id']]["style_" . $style["product_style_id"]] = $style;
     }
     $inventorys = self::_db()->select_rows("select * from et_product_inventory where style_id in (" . implode(",", $product_style_ids) . ")");
     $sizes = array();
     foreach ($inventorys as $inventory) {
         $sizes[$inventory['product_id']][$inventory['style_id']][] = $inventory;
     }
     return array("products" => $products, "product_designs" => $product_designs, "act_designs" => $act_designs, "styles" => $styles, "sizes" => $sizes, "default_style" => $default_style);
 }