예제 #1
0
 function action_product_pricing($sale_count, $color_count, $style_id)
 {
     $sale_count = intval($sale_count);
     $color_count = intval($color_count);
     $style_id = intval($style_id);
     if (!$sale_count) {
         throw new Exception("sale_count 不能为空");
     }
     if ($sale_count > 1000 || $sale_count < 10) {
         throw new Exception("sale_count 不能大于1000件 且不能小于10件");
     }
     if (!$color_count) {
         throw new Exception("颜色数量不能为空");
     }
     if ($color_count > 10) {
         throw new Exception("颜色数量不能大于10种");
     }
     if (!$style_id) {
         throw new Exception("款式ID不能为空");
     }
     $style = self::_db()->select_row("select * from et_product_style where id = ?", $style_id);
     if (!$style) {
         throw new Exception("款式不存在");
     }
     $print_cost = Model_Cost::calculate_cost($color_count, $sale_count);
     return array("print_cost" => $print_cost, "selling_price" => $style['selling_price']);
 }
예제 #2
0
 /**
  * @param $id           活动ID
  * @param $colors       颜色数量
  * @param $sale_count   销售总量
  * @param $sale_target  销售目标
  * @return float
  * @throws Exception
  */
 static function get_activity_profit($id, $colors, $sale_count, $sale_target)
 {
     //单件印花成本
     if ($sale_count > $sale_target) {
         $_sale_count = $sale_target;
     } else {
         $_sale_count = $sale_count;
     }
     PtLib\log("[印花成本] 活动:%s 当前销量:%s 目标销量:%s 成本计算销量:%s 颜色数:%s", $id, $sale_count, $sale_target, $_sale_count, $colors);
     //单件印花成本
     $cost_print_one = Model_Cost::calculate_cost($colors, $_sale_count);
     //印花总成本
     $cost_print = $cost_print_one * $sale_count;
     PtLib\log("[印花成本] 活动:%s 单件印花成本:%s 印花总成本:%s", $id, $cost_print_one, $cost_print);
     $total = self::_db()->select_row("select sum(g.quantity * (g.sell_price - g.cost_price)) as profit_all from et_order_goods as g\n                    left join et_order_pay as p on p.order_id = g.order_id  where p.pay_status = 1 and g.activity_id = ? ", $id);
     //不包含印花利润
     $profit_all = $total['profit_all'] ? $total['profit_all'] : "0";
     $profit = round($profit_all - $cost_print, 2);
     PtLib\log("[印刷成本] 活动:%s 不包含印花利润:%s - 印花总成本:%s = 利润:%s", $id, $profit_all, $cost_print, $profit);
     //todo check need
     self::_db()->update("et_activity_info", array("sale_profit" => $profit), array("id" => $id));
     return $profit;
 }