weizong song 3 years ago
parent a52a6cf40f
commit 991ae5844b

@ -126,6 +126,7 @@ class OrdersController extends CommonController
public function getItem($id)
{
$order_item = OrderItems::with("order")->find($id);
$order_item = $order_item->calculateFee();
return $this->ajaxResponse($order_item);
}
}

@ -42,6 +42,10 @@ class StatisticsController extends CommonController
public function _getMonths()
{
$months = [];
for ($i = 1; $i <= 12; $i++) {
$mm = $i < 10 ? "0" . $i : $i;
$months[] = (date("Y") - 2) . "-" . $mm;
}
for ($i = 1; $i <= 12; $i++) {
$mm = $i < 10 ? "0" . $i : $i;
$months[] = (date("Y") - 1) . "-" . $mm;

@ -0,0 +1,8 @@
<?php
namespace App\Models;
class Holiday extends SoftDeletesModel
{
protected $table = "holiday";
}

@ -10,7 +10,7 @@ use Illuminate\Support\Facades\Log;
class OrderItems extends SoftDeletesModel
{
protected $table = "order_items";
CONST PREV_MONTH = "往月服务单";
const PREV_MONTH = "往月服务单";
protected $appends = ["paid_status"];
@ -31,8 +31,9 @@ class OrderItems extends SoftDeletesModel
return $this->belongsTo(Orders::class);
}
public function siblings() {
return $this->hasManyThrough(OrderItems::class,Orders::class,"id","order_id","order_id","id");
public function siblings()
{
return $this->hasManyThrough(OrderItems::class, Orders::class, "id", "order_id", "order_id", "id");
}
public function customer()
@ -190,7 +191,18 @@ class OrderItems extends SoftDeletesModel
->first();
}
$fee = $factor->fee_percent * $this->total / 100 + $factor->fee - $this->fee_free;
//todo:考虑不同项目的情况,目前是全部统一
$holidays = cache("holidays_" . $this->order->project_id);
if (!$holidays) {
$holidays = Holiday::where("project_id", $this->order->project_id)->get()->keyBy("date")->toArray();
cache(['holidays' . $this->order->project_id => $holidays], now()->addSeconds(90)); //只保存较短时间,省却了更新节假日时的缓存更新机制
}
if (in_array($this->service_date, array_keys($holidays))) {
$fee = $factor->fee_percent * ($this->total / $holidays[$this->service_date]["price_ratio"]) / 100 + $factor->fee - $this->fee_free;
} else {
$fee = $factor->fee_percent * $this->total / 100 + $factor->fee - $this->fee_free;
}
$paramedic_total = $this->total - $fee;
$this->paramedic_total = $paramedic_total;
$this->fee = $fee;

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateHoliday extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('holiday', function (Blueprint $table) {
$table->id();
$table->integer("project_id")->nullable();
$table->string("date")->nullable();
$table->string("remark")->nullable();
$table->decimal("price_ratio", 2, 1)->nullable()->default(1);
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('holiday');
}
}

@ -118,6 +118,7 @@
<form class="pl-3 pr-3" action="#">
@csrf
<input type="hidden" name="item_id">
<input type="hidden" name="fee">
<div class="form-group">
<label for="serial">订单编号</label>
<input class="form-control" type="text" name="serial" disabled>
@ -172,6 +173,7 @@
$.get(url, function (res) {
$("#modal-box").modal("show");
$("#modal-box form input[name=item_id]").val(item_id);
$("#modal-box form input[name=fee]").val(res.fee);
$("#modal-box form input[name=serial]").val(res.order.serial);
$("#modal-box form input[name=service_date]").val(res.service_date);
$("#modal-box form input[name=total]").val(res.total).prop("disabled", false);
@ -215,9 +217,8 @@
function calculateSalary() {
if (!$("#modal-box form").find("input[name=salary]").length) return;
var total = $("#modal-box form input[name=total]").val();
var fee_percent = $("#modal-box form input[name$='[fee_percent]']").val();
var fee = $("#modal-box form input[name$='[fee]']").val();
var salary = total - (fee_percent * total / 100 + parseFloat(fee));
var fee = $("#modal-box form input[name=fee]").val();
var salary = total - fee;
$("#modal-box form").find("input[name=salary]").val(salary);
}

Loading…
Cancel
Save