예제 #1
0
 static function handle_result($rest)
 {
     $status = @$rest->status;
     \PtLib\log("status:" . $status);
     if ($status != 200) {
         $body = simplexml_load_string($rest->body);
         //\PtLib\log($body);
         throw new Exception($body->Message);
     }
     $url = empty($rest->header['x-oss-request-url']) ? "" : $rest->header['x-oss-request-url'];
     \PtLib\log("上传成功:{$url}");
     return $url;
 }
예제 #2
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();
         }
     }
 }
예제 #3
0
 static function print_env()
 {
     PtLib\log(self::$ENV);
     exit;
 }