Пример #1
0
 function action_do_register($captcha, $mobile, $redirect, $password)
 {
     PtApp::session_start();
     $reg_captcha = empty($_SESSION['reg_captcha_' . $mobile]) ? "" : $_SESSION['reg_captcha_' . $mobile];
     if (!$reg_captcha) {
         throw new Exception("验证码不能为空", 8001);
     }
     $is_register = self::_db()->select_row('select id from et_user where mobile = ? ', $mobile);
     //var_dump($mobile);exit;
     if ($is_register) {
         throw new Exception("当前号码已经注册过");
     }
     $password = md5($password);
     if ($captcha != "0000" && $captcha != $reg_captcha) {
         throw new Exception("验证码不正确");
     }
     $uid = self::_db()->insert("et_user", array('nick_name' => $mobile, 'mobile' => $mobile, 'password' => $password, 'add_time' => date_time_now()));
     self::_db()->insert("et_user_finance", array('uid' => $uid));
     $user_info = array("uid" => $uid, "nick_name" => $mobile);
     Model_User_Auth::set_login($user_info);
     unset($_SESSION['reg_captcha_' . $mobile]);
     setcookie("invite_id_cookie", "", time() - 3600, "/");
     $res = array("message" => "注册成功");
     if ($redirect) {
         $res['redirect'] = $redirect;
     }
     return $res;
 }
Пример #2
0
 function action_create($app_id, $uid, $mobile, $time, $return_url, $extra_price, $extra_percent, $sign)
 {
     $app = self::_db()->select_row("select id,app_secret from et_application where app_id = ?", $app_id);
     if (!$app) {
         throw new Exception("app 不存在");
     }
     $request = array("model" => "open/activity", "action" => "create", "app_id" => $app_id, "uid" => $uid, "extra_price" => $extra_price, "extra_percent" => $extra_percent, "mobile" => $mobile, "time" => $time, "return_url" => $return_url);
     $_sign = md5(http_build_query($request) . $app['app_secret']);
     if (!$mobile) {
         throw new Exception("手机号不合法");
     }
     if ($_sign != $sign) {
         throw new Exception("签名不正确");
     }
     $app_user = self::_db()->select_row("select * from et_app_user where app_uid = ? and app_id = ?", $uid, $app["id"]);
     if (!$app_user) {
         $et_uid = self::_db()->insert("et_user", array("mobile" => $mobile, "nick_name" => $mobile, "add_time" => date_time_now(), "password" => md5(time())));
         self::_db()->insert("et_app_user", array("app_id" => $app['id'], "uid" => $et_uid, "app_uid" => $uid, "add_time" => date_time_now()));
     } else {
         $et_uid = $app_user['uid'];
     }
     $info = self::init($et_uid);
     $act_id = $info['activity_id'];
     self::_db()->insert("et_app_activity", array("id" => $act_id, "app_id" => $app['id'], "app_uid" => $uid, "extra_price" => $extra_price, "extra_percent" => $extra_percent, "return_url" => $return_url));
     switch (PtApp::$ENV) {
         case "develop":
             $url = "http://11.dev.jzw.com";
             break;
         case "local":
             $url = "http://11.dev.jzw.com";
             break;
         default:
             $url = "http://www.easytee.me";
             break;
     }
     $url .= '/design/?app_uid=' . $et_uid . '&DesignID=' . $info['design_id'] . '&ActivityID=' . $info['activity_id'];
     //return self::get_app_return_url($app['id'],$uid,$info['activity_id']);
     self::_location($url);
 }
Пример #3
0
 function action_finish_product($id)
 {
     self::_db()->update("et_activity_info", array("production_status" => 2), array("id" => $id));
     self::_db()->update("et_activity_produce", array("finish_time" => date_time_now()), array("id" => $id));
 }
Пример #4
0
 static function do_close($commit)
 {
     //进行中的 结束时间小于当前时间的 活动
     $activities = self::_db()->select_rows("select i.*,u.nick_name,u.mobile,a.name\n                    from et_activity_info as i\n                    left join activities as a on a.id = i.id\n                    left join et_user as u on u.id = i.uid\n                    where i.status = 1 and i.production_status = 0 and i.end_time < now()");
     PtLib\log("=======");
     if (!$activities) {
         PtLib\log("没有活动要结束");
     }
     foreach ($activities as $activity) {
         PtLib\log("------");
         //print_r($activity);exit;
         try {
             self::_db()->bt();
             $colors = intval($activity['colors']);
             $sale_count = intval($activity['sale_count']);
             $sale_profit = floatval($activity['sale_profit']);
             $sale_target = intval($activity['sale_target']);
             $act_id = $activity['id'];
             $uid = $activity['uid'];
             $mobile = $activity['mobile'];
             if (PtApp::$ENV == 'develop') {
                 $mobile = TEST_SMS_MOBILE;
             }
             $act_name = $activity['name'];
             $nick_name = $activity['nick_name'];
             //销售数量小于10 直接结束,并处理订单退款
             if ($sale_count < 10) {
                 PtLib\log("[活动] id:%s 销售数量:%s 小于 10 结束活动,处理订单退款", $act_id, $sale_count);
                 self::close_activity($act_id);
                 self::do_refund($act_id, $act_name, $sale_count, $nick_name);
                 //给卖家发送活动失败短信
                 $option = json_encode(array('salesNum' => $sale_count, 'activity' => $act_name, 'username' => $nick_name));
                 PtLib\log("[活动短信] id:%s 失败,给卖家:%s 发送短信,project:%s,option:%s", $act_id, $mobile, "oWwG62", $option);
                 self::_db()->insert("et_sms_activity", array("project" => "oWwG62", "activity_id" => $act_id, "mobile" => $mobile, "option" => $option, "add_time" => date_time_now()));
             } elseif ($sale_count >= 10 and $sale_count < $sale_target) {
                 //大于起订量10件 并小于销售目标
                 if ($sale_profit <= 0) {
                     $sale_profit = self::get_activity_profit($act_id, $colors, $sale_count, $sale_target);
                 }
                 PtLib\log("[活动] id:%s 销售数量:%s 大于起订量10件 并小于销售目标:%s 利润:%s", $act_id, $sale_count, $sale_target, $sale_profit);
                 //var_dump($sale_profit);exit;
                 if ($sale_profit > 0) {
                     //有利润进入生产
                     self::close_activity_success($act_id);
                     //结算利润给卖家
                     self::clearing_profit($act_id, $uid, $sale_profit);
                     //给卖家发送活动成功进入生产短信
                     $option = json_encode(array('username' => $nick_name, 'activity' => $act_name, 'salesNum' => $sale_count, 'money' => $sale_profit));
                     PtLib\log("[活动短信] id:%s 成功,给卖家:%s 发送短信,project:%s,option:%s", $act_id, $mobile, "fyiCw2", $option);
                     self::_db()->insert("et_sms_activity", array("project" => "fyiCw2", "activity_id" => $act_id, "mobile" => $mobile, "option" => $option, "add_time" => date_time_now()));
                     //发送短信给生产负责人
                     $option = json_encode(array('activityId' => $act_id, 'activityTitle' => $act_name));
                     PtLib\log("[活动短信] id:%s 成功,给生产负责人:%s 发送短信,project:%s,option:%s", $act_id, PRODUCTION_NOTICE, "4NOd3", $option);
                     self::_db()->insert("et_sms_activity", array("project" => "4NOd3", "activity_id" => $act_id, "mobile" => PRODUCTION_NOTICE, "option" => $option, "add_time" => date_time_now()));
                 } else {
                     //没有利润 直接结束 处理订单退款
                     self::close_activity($act_id);
                     self::do_refund($act_id, $act_name, $sale_count, $nick_name);
                     //给卖家发送活动失败短信
                     $option = json_encode(array('salesNum' => $sale_count, 'activity' => $act_name, 'username' => $nick_name));
                     PtLib\log("[活动短信] id:%s 失败,给卖家:%s 发送短信,project:%s,option:%s", $act_id, $mobile, "oWwG62", $option);
                     self::_db()->insert("et_sms_activity", array("project" => "oWwG62", "activity_id" => $act_id, "mobile" => $mobile, "option" => $option, "add_time" => date_time_now()));
                 }
             } else {
                 //完成销售目标,有可能超销售目标 ==> 进入生产
                 if ($sale_profit <= 0) {
                     $sale_profit = self::get_activity_profit($act_id, $colors, $sale_count, $sale_target);
                 }
                 PtLib\log("[活动] id:%s 完成销售目标 销售数量:%s 销售目标:%s 利润:%s", $act_id, $sale_count, $sale_target, $sale_profit);
                 self::close_activity_success($act_id);
                 //结算利润给卖家
                 self::clearing_profit($act_id, $uid, $sale_profit);
                 //给卖家发送活动成功进入生产短信
                 $option = json_encode(array('username' => $nick_name, 'activity' => $act_name, 'salesNum' => $sale_count, 'money' => $sale_profit));
                 PtLib\log("[活动短信] id:%s 成功,给卖家:%s 发送短信,project:%s,option:%s", $act_id, $mobile, "fyiCw2", $option);
                 self::_db()->insert("et_sms_activity", array("project" => "fyiCw2", "activity_id" => $act_id, "mobile" => $mobile, "option" => $option, "add_time" => date_time_now()));
                 //发送短信给生产负责人
                 $option = json_encode(array('activityId' => $act_id, 'activityTitle' => $act_name));
                 PtLib\log("[活动短信] id:%s 成功,给生产负责人:%s 发送短信,project:%s,option:%s", $act_id, PRODUCTION_NOTICE, "4NOd3", $option);
                 self::_db()->insert("et_sms_activity", array("project" => "4NOd3", "activity_id" => $act_id, "mobile" => PRODUCTION_NOTICE, "option" => $option, "add_time" => date_time_now()));
             }
             if ($commit == 1) {
                 self::_db()->commit();
             } else {
                 //PtLib\log(self::_db()->get_run_stack());
             }
         } catch (Exception $e) {
             PtLib\log($e->getMessage());
             self::_db()->rollback();
         }
     }
 }
Пример #5
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 "保存成功";
 }
Пример #6
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);
 }
Пример #7
0
 function action_audit($id, $status)
 {
     try {
         $userDatas = self::_db()->select_row('select c.id,c.uid,c.real_name,i.invite_id ,u.mobile
               from et_user_campus as c
               left join et_user_invite as i on i.uid = c.uid
               left join et_user as u on u.id = c.uid
               where c.id =  ? ', $id);
         self::_db()->update('et_user_campus', array('status' => $status, "up_time" => date_time_now()), array('id' => $id));
         $mobile = $userDatas['mobile'];
         $name = $userDatas['real_name'];
         //$mobile = '18601628937';
         if ($status == 1) {
             //通过
             self::_db()->bt();
             $add_money = $GLOBALS['setting']['campus']['add_money'];
             self::_db()->run_sql("update et_user_finance set balance_ntx = balance_ntx + " . $add_money . " where uid = ?", $userDatas['uid']);
             self::_db()->insert("et_user_finance_log", array("uid" => $userDatas['uid'], "amount" => $add_money, "type" => 11, "note" => "校园达人参与活动奖励", "add_time" => date_time_now()));
             $invite_user = self::_db()->select_row('select invite_id from et_user_invite  where uid =  ? ', $userDatas['uid']);
             if (!empty($invite_user['invite_id'])) {
                 $_invite_campus = self::_db()->select_row('select c.status from et_user_campus as c where c.uid =  ? ', $invite_user['invite_id']);
                 if ($_invite_campus && $_invite_campus['status'] == 1) {
                     $invite_money = $GLOBALS['setting']['campus']['invite_money'];
                     self::_db()->run_sql("update et_user_finance set balance_ntx = balance_ntx + " . $invite_money . " where uid = ?", $invite_user['invite_id']);
                     self::_db()->insert("et_user_finance_log", array("uid" => $invite_user['invite_id'], "amount" => $invite_money, "type" => 12, "note" => "校园达人邀请奖励", "add_time" => date_time_now()));
                 }
             }
             self::_db()->commit();
             if ($mobile) {
                 $res = Model_Tools_Sms::sendsms($mobile, "oV3NQ3", array("name" => $name));
                 //print_r($res);exit;
             }
         } else {
             //拒绝
             if ($mobile) {
                 $res = Model_Tools_Sms::sendsms($mobile, "flACZ1", array("name" => $name));
                 self::_db()->delete("et_user_campus", array("id" => $userDatas['id']));
                 //print_r($res);exit;
             }
         }
         return array("ok");
     } catch (Exception $e) {
         self::_db()->rollback();
         throw new Exception($e->getMessage());
     }
 }