select($columns)->with($withs)->get(); } public function paginate($id = null,array $withs = []) { $query = OwnerStoragePriceModel::query()->orderByDesc('id')->with($withs); if ($id)$query->where("id",$id); return $query->paginate($params["paginate"] ?? 50); } public function create(array $params) { $params["operation"] = "C"; return OwnerStoragePriceModel::query()->create($params); } /** * 拷贝目标数据 * * @param object|int $model * @param array $values * @param array|null $owners * * @return object|null */ public function copy($model, $values = [], $owners = null) { if (is_integer($model))$model = OwnerStoragePriceModel::query()->find($model); if (!$model)return null; $values["operation"] = "U"; $values["target_id"] = $model->id; foreach ($model->getFillable() as $column){ if (!array_key_exists($column,$values))$values[$column] = $model[$column]; } if ($owners===null){ $query = DB::raw("SELECT * FROM owner_storage_price_model_owner WHERE owner_storage_price_model_id = {$model->id}"); $owners = array_column(DB::select($query),"owner_id"); } /** @var OwnerStoragePriceModel $model */ $model = OwnerStoragePriceModel::query()->create($values); $model->owners()->sync($owners); return $model; } /** * 审核或恢复目标集 * * @param bool $isAudit * @param integer|null|array $ownerId * @param integer|null|array $ids */ public function auditOrRecover($isAudit = true, $ownerId = null, $ids = null) { if (!$ownerId && !$ids)return; $result = app(QueryService::class)->priceModelAuditOrRecoverQuery($isAudit,OwnerStoragePriceModel::query(),$ownerId,$ids); if ($result["delete"])$this->destroy($result["delete"]); if ($result["update"])OwnerStoragePriceModel::query()->whereIn("id",$result["update"])->update(["operation"=>null,"target_id"=>null]); } public function update(array $params, array $values) { $query = OwnerStoragePriceModel::query(); foreach ($params as $column => $value){ $query->where($column,$value); } return $query->update($values); } public function find($id, $withs = []) { return OwnerStoragePriceModel::query()->with($withs)->find($id); } public function destroy($id) { if (is_array($id)){ $query = "IN ("; for ($i=0;$ioperation) return array(0,null); if ($area < $model->minimum_area) $area = $model->minimum_area; if (!isset($GLOBALS["FEE_INFO"]))$GLOBALS["FEE_INFO"] = [ "fee_description" => "", "tax_rate" => "", ]; $GLOBALS["FEE_INFO"]["fee_description"] .= "起租面积:".$model->minimum_area; $days = 1; switch ($model->timeUnit->name){ case "日": $days = date('t', strtotime($month."-01")); $area *= $days; break; } switch ($model->discount_type){ case "按单减免": $GLOBALS["FEE_INFO"]["fee_description"] .= ",按单减免"; if ($owner_id && $month){ if ($model->timeUnit->name == '月'){ $GLOBALS["FEE_INFO"]["fee_description"] .= ":每".$model->discount_value."单/月 减免1".$model->unit->name ?? 'm²'; $report = OwnerReport::query()->select("id",DB::raw("(to_business_quantity+to_customer_quantity) AS total")) ->where("owner_id",$owner_id) ->where("counting_month","like",$month."%")->first(); if ($report && $report->total>=0)$area -= floor($report->total/$model->discount_value); }else{ $days = date('t', strtotime($month."-01")); $area *= $days; $logistics = app("OwnerPriceExpressService")->getBuildLogistic($owner_id); $logisticSql = "(''"; foreach ($logistics as $logistic)$logisticSql.=",".$logistic; $logisticSql .= ")"; $GLOBALS["FEE_INFO"]["fee_description"] .= ":每".$model->discount_value."单/".$model->timeUnit->name." 减免1".$model->unit->name ?? 'm²'; for($i=1;$i<=$days;$i++){ $d = $i<10 ? "0".$i : $i; $query = DB::raw("SELECT COUNT(1) c FROM orders WHERE logistic_id IN {$logisticSql} AND wms_status = ? AND wms_edittime BETWEEN ? AND ?"); $count = DB::selectOne($query,['订单完成',$month."-".$d." 00:00:00",$month."-".$d." 23:59:59"]); if ($count && $count->c>=0)$area -= floor($count->c/$model->discount_value); } } } break; case "固定减免": $GLOBALS["FEE_INFO"]["fee_description"] .= ",固定减免:每".$model->timeUnit->name."减免".$model->discount_value.($model->unit->name ?? 'm²'); if ($model->timeUnit->name == '月'){ $area -= $model->discount_value; }else $area -= $days*$model->discount_value; break; } $index = 0; if ($model->amount_interval){ $total = app("OrderService")->getOrderQuantity($owner_id,false,$month); for ($i=count($model->amount_interval)-1;$i>=0;$i--){ if ($total>=$model->amount_interval[$i])$index = $i; } } $GLOBALS["FEE_INFO"]["fee_description"] .= ",单价: ".$model->price[$index]."/".($model->unit->name ?? 'm²')."/".$model->timeUnit->name; $money = $area>0 ? $area*$model->price[$index] : 0; $taxRate = app("OwnerService")->getTaxRateFee($model, $owner_id); $taxFee = $money*($taxRate/100); $GLOBALS["FEE_INFO"]["fee_description"] .= ",税费: ".$taxFee; $GLOBALS["FEE_INFO"]["tax_rate"] = $taxRate; return array($money,$taxFee); } }