|
|
@@ -11,6 +11,7 @@ use Exception;
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Http\Response;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
@@ -141,284 +142,31 @@ class CustomerController extends Controller
|
|
|
"Content-type"=>"application/octet-stream",
|
|
|
"Content-Disposition"=>"attachment; filename=客户报表-".date('ymdHis').'.xlsx',
|
|
|
]);
|
|
|
+ $customers = $service->get(Auth::user(),['customer_id'=>true],['customer']);
|
|
|
+ return response()->view('customer.project.index');
|
|
|
}
|
|
|
|
|
|
public function projectCreate()
|
|
|
{
|
|
|
if(!Gate::allows('客户管理-项目-录入')){ return redirect('denied'); }
|
|
|
- $customers = app('CustomerService')->getSelection();
|
|
|
- $ownerGroups = app('UserOwnerGroupService')->getSelection();
|
|
|
- $storagePriceModels = app('OwnerStoragePriceModelService')->getSelection(["id","counting_type","using_type","minimum_area","price","unit_id"],["unit"=>function($query){$query->select("id","name");}]);
|
|
|
- $owner = null;
|
|
|
- return response()->view('customer.project.create',compact("customers","ownerGroups","storagePriceModels","owner"));
|
|
|
+ return response()->view('customer.project.create');
|
|
|
}
|
|
|
|
|
|
- public function seekOwner(Request $request)
|
|
|
- {
|
|
|
- $params = $request->input();
|
|
|
- $params["customer_id"] = true;
|
|
|
- $owner = app('OwnerService')->first($params,["customer_id"=>"null"]);
|
|
|
- if ($owner)return ["success"=>true,"data"=>$owner];
|
|
|
- else return ["success"=>false];
|
|
|
- }
|
|
|
-
|
|
|
- public function projectStore(Request $request)
|
|
|
- {
|
|
|
- if(!Gate::allows('客户管理-项目-录入')){ return redirect('denied'); }
|
|
|
- $this->validator($request->input())->validate();
|
|
|
- $params = $request->input();
|
|
|
- if ($params["id"]){
|
|
|
- /** @var Owner $owner */
|
|
|
- $owner = app('OwnerService')->find($params["id"]);
|
|
|
- app('OwnerService')->update($owner,[
|
|
|
- "customer_id" => $params["customer_id"],
|
|
|
- "tax_rate" => $params["tax_rate"],
|
|
|
- "contract_number" => $params["contract_number"],
|
|
|
- "salesman" => $params["salesman"],
|
|
|
- "linkman" => $params["linkman"],
|
|
|
- "phone_number" => $params["phone_number"],
|
|
|
- "user_owner_group_id" => $params["owner_group_id"],
|
|
|
- "waring_line_on" => $params["waring_line_on"],
|
|
|
- "description" => $params["description"],
|
|
|
- ],[
|
|
|
- "ownerStoragePriceModels" => explode(',',$params["owner_storage_price_model_id"])
|
|
|
- ]);
|
|
|
- $msg = "成功更新“".$owner->name."”的信息!";
|
|
|
- }else{
|
|
|
- $owner = app('OwnerService')->create([
|
|
|
- "name" => $params["name"],
|
|
|
- "code" => $params["code"],
|
|
|
- "customer_id" => $params["customer_id"],
|
|
|
- "tax_rate" => $params["tax_rate"],
|
|
|
- "contract_number" => $params["contract_number"],
|
|
|
- "salesman" => $params["salesman"],
|
|
|
- "linkman" => $params["linkman"],
|
|
|
- "phone_number" => $params["phone_number"],
|
|
|
- "user_owner_group_id" => $params["owner_group_id"],
|
|
|
- "waring_line_on" => $params["waring_line_on"],
|
|
|
- "description" => $params["description"],
|
|
|
- ],[
|
|
|
- "ownerStoragePriceModels" => explode(',',$params["owner_storage_price_model_id"])
|
|
|
- ]);
|
|
|
- $msg = "成功创建“".$owner->name."”项目!";
|
|
|
- }
|
|
|
- return response()->redirectTo('customer/project/index')->with('successTip',$msg);
|
|
|
- }
|
|
|
-
|
|
|
- //获取货主下所有相关计费模型
|
|
|
- public function getOwnerPriceModel(Request $request)
|
|
|
- {
|
|
|
- $owner = new Owner();
|
|
|
- $owner->id = $request->id;
|
|
|
- $owner->load(["ownerPriceOperations","ownerPriceExpresses","ownerPriceLogistics","ownerPriceDirectLogistics"]);
|
|
|
- return ["success"=>true,"data"=>["ownerPriceOperations"=>$owner->ownerPriceOperations,
|
|
|
- "ownerPriceExpresses"=>$owner->ownerPriceExpresses,
|
|
|
- "ownerPriceLogistics"=>$owner->ownerPriceLogistics,
|
|
|
- "ownerPriceDirectLogistics"=>$owner->ownerPriceDirectLogistics]];
|
|
|
- }
|
|
|
-
|
|
|
- public function projectEdit($id)
|
|
|
- {
|
|
|
- if(!Gate::allows('客户管理-项目-编辑')){ return redirect('denied'); }
|
|
|
- /** @var Owner $owner */
|
|
|
- $owner = app('OwnerService')->find($id);
|
|
|
- $owner->owner_storage_price_model_id = $owner->getOwnerStoragePriceModelIds();
|
|
|
- $customers = app('CustomerService')->getSelection();
|
|
|
- $ownerGroups = app('UserOwnerGroupService')->getSelection();
|
|
|
- $storagePriceModels = app('OwnerStoragePriceModelService')->getSelection(["id","counting_type","using_type","minimum_area","price","unit_id"],["unit"=>function($query){$query->select("id","name");}]);
|
|
|
- return response()->view('customer.project.create',compact("customers","ownerGroups","storagePriceModels",'owner'));
|
|
|
- }
|
|
|
-
|
|
|
- public function projectArea(Request $request)
|
|
|
+ public function projectArea()
|
|
|
{
|
|
|
if(!Gate::allows('客户管理-项目-面积')){ return redirect('denied'); }
|
|
|
- $areas = app('OwnerAreaReportService')->paginate($request->input(),["owner"=>function($query){$query->with(["customer","ownerStoragePriceModels"]);}]);
|
|
|
- $ownerGroups = app('UserOwnerGroupService')->getSelection();
|
|
|
- $customers = app('CustomerService')->getSelection();
|
|
|
- $owners = app('OwnerService')->getSelection();
|
|
|
- $params = $request->input();
|
|
|
- return response()->view('customer.project.area',compact("areas","ownerGroups","customers","owners","params"));
|
|
|
+ return response()->view('customer.project.area');
|
|
|
}
|
|
|
|
|
|
- public function updateArea(Request $request)
|
|
|
- {
|
|
|
- if(!Gate::allows('客户管理-项目-面积-编辑')){ return ["success"=>false,'data'=>"无权操作!"]; }
|
|
|
- if (!($request->id ?? false) || !($request->area ?? false)) return ["success"=>false,'data'=>"传递错误!"];
|
|
|
- $values = $request->area ?? null;
|
|
|
- if (!$values)return ["success"=>true,"data"=>$values];
|
|
|
- foreach ($values as $column=>$value){
|
|
|
- if ($value && (!is_numeric($value) || $value<0))return ["success"=>false,'data'=>$column."非数字或小于0!"];
|
|
|
- }
|
|
|
- $accounting_area = ((int)$values["area_on_tray"]*205) + ((int)$values["area_on_half_tray"]*1.8) + ((int)$values["area_on_flat"]*1.3);
|
|
|
- $values["accounting_area"] = $accounting_area;
|
|
|
- if (app('OwnerAreaReportService')->update(["id"=>$request->id],$values))
|
|
|
- return ["success"=>true,"data"=>$values];
|
|
|
- return ["success"=>false,"data"=>"未知错误!"];
|
|
|
- }
|
|
|
-
|
|
|
- public function projectAreaExport(Request $request)
|
|
|
- {
|
|
|
- if(!Gate::allows('客户管理-项目-面积')){ return redirect('denied'); }
|
|
|
- $params = $request->input();
|
|
|
- if ($request->checkAllSign)unset($params['checkAllSign']);
|
|
|
- else $params = ["id"=>$request->data];
|
|
|
- /** @var OwnerAreaReportService $serves */
|
|
|
- $serves = app('OwnerAreaReportService');
|
|
|
- $areas = $serves->get($params,["owner"=>function($query){$query->with(["customer","ownerStoragePriceModels","userOwnerGroup"]);}]);
|
|
|
-
|
|
|
- $column = ["状态","项目组","客户","子项目","结算月","录入时间","用仓类型","货物整托","货物半托","平面区面积","结算面积"];
|
|
|
- $list = [];
|
|
|
- foreach ($areas as $area){
|
|
|
- $list[] = [
|
|
|
- $area->status,
|
|
|
- $area->owner ? ($area->owner->userOwnerGroup ? $area->owner->userOwnerGroup->name : '') : '',
|
|
|
- $area->owner ? ($area->owner->customer ? $area->owner->customer->name : '') : '',
|
|
|
- $area->owner ? $area->owner->name : '',
|
|
|
- $area->counting_month,
|
|
|
- $area->updated_at,
|
|
|
- $area->owner ? implode(",",array_unique(array_column(($area->owner->ownerStoragePriceModels)->toArray(),"using_type"))) : '',
|
|
|
- $area->area_on_tray,
|
|
|
- $area->area_on_half_tray,
|
|
|
- $area->area_on_flat,
|
|
|
- $area->accounting_area,
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- $post = Http::post(config('go.export.url'),['type'=>'base','data'=>json_encode(["row"=>$column,"list"=>$list],JSON_UNESCAPED_UNICODE)]);
|
|
|
- if ($post->status() == 500){
|
|
|
- throw new Exception($post->header("Msg"));
|
|
|
- }
|
|
|
- return response($post,200, [
|
|
|
- "Content-type"=>"application/octet-stream",
|
|
|
- "Content-Disposition"=>"attachment; filename=项目面积报表-".date('ymdHis').'.xlsx',
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- public function financeInstantBill(Request $request)
|
|
|
+ public function financeInstantBill()
|
|
|
{
|
|
|
if(!Gate::allows('客户管理-财务-即时账单')){ return redirect('denied'); }
|
|
|
- $params = $request->input();
|
|
|
- $shops = app('ShopService')->getSelection();
|
|
|
- $customers = app('CustomerService')->getSelection();
|
|
|
- $owners = app('OwnerService')->getSelection();
|
|
|
- $details = app('OwnerFeeDetailService')->paginate($params,["owner"=>function($query){$query->with("customer");},"shop","processMethod","logistic"]);
|
|
|
- return response()->view('customer.finance.instantBill',compact("details","params","shops","customers","owners"));
|
|
|
+ return response()->view('customer.finance.instantBill');
|
|
|
}
|
|
|
|
|
|
- public function financeInstantBillExport(Request $request)
|
|
|
- {
|
|
|
- if(!Gate::allows('客户管理-财务-即时账单')){ return redirect('denied'); }
|
|
|
- $params = $request->input();
|
|
|
- if ($request->checkAllSign)unset($params['checkAllSign']);
|
|
|
- else $params = ["id"=>$request->data];
|
|
|
- $sql = app('OwnerFeeDetailService')->getSql($params);
|
|
|
-
|
|
|
- $row = ["客户", "项目", "作业时间", "类型","店铺", "单号(发/收/退/提)", "收件人", "收件人电话", "商品数量",
|
|
|
- "物流/快递单号", "体积", "重量", "承运商", "操作费", "物流费", "合计"];
|
|
|
- $column = ["customer_name", "owner_name", "worked_at", "type","shop_name", "operation_bill", "consignee_name", "consignee_phone", "commodity_amount",
|
|
|
- "logistic_bill", "volume", "weight", "logistic_name", "work_fee", "logistic_fee", "total"];
|
|
|
- $rule = ["work_fee"=>"mysqlDate"];
|
|
|
-
|
|
|
- $post = Http::post(config('go.export.url'),['type'=>'unify','sql'=>$sql, 'connection'=>'mysql',
|
|
|
- 'row'=>json_encode($row,JSON_UNESCAPED_UNICODE), 'column'=>json_encode($column), 'rule'=>json_encode($rule)]);
|
|
|
- if ($post->status() == 500){
|
|
|
- throw new Exception($post->header("Msg"));
|
|
|
- }
|
|
|
- return response($post,200, [
|
|
|
- "Content-type"=>"application/octet-stream",
|
|
|
- "Content-Disposition"=>"attachment; filename=即时账单记录-".date('ymdHis').'.xlsx',
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- public function financeBillConfirmation(Request $request)
|
|
|
- {
|
|
|
- if(!Gate::allows('客户管理-财务-账单确认')){ return redirect('denied'); }
|
|
|
- $params = $request->input();
|
|
|
- $ownerGroups = app('UserOwnerGroupService')->getSelection();
|
|
|
- $customers = app('CustomerService')->getSelection();
|
|
|
- $owners = app('OwnerService')->getSelection();
|
|
|
- $bills = app('OwnerBillReportService')->paginate($params,["owner"=>function($query){
|
|
|
- /** @var Builder $query */
|
|
|
- $query->with(["customer","userOwnerGroup"]);
|
|
|
- }]);
|
|
|
- return response()->view('customer.finance.billConfirmation',compact("params","owners","ownerGroups","customers","bills"));
|
|
|
- }
|
|
|
-
|
|
|
- public function financeBillConfirmationExport(Request $request)
|
|
|
+ public function financeBillConfirmation()
|
|
|
{
|
|
|
if(!Gate::allows('客户管理-财务-账单确认')){ return redirect('denied'); }
|
|
|
- $params = $request->input();
|
|
|
- if ($request->checkAllSign)unset($params['checkAllSign']);
|
|
|
- else $params = ["id"=>$request->data];
|
|
|
- /** @var OwnerBillReportService $serves */
|
|
|
- $serves = app('OwnerBillReportService');
|
|
|
- $bills = $serves->get($params,["owner"=>function($query){
|
|
|
- /** @var Builder $query */
|
|
|
- $query->with(["customer","userOwnerGroup"]);
|
|
|
- }]);
|
|
|
-
|
|
|
- $column = ["项目小组","客户","子项目","结算月","录入日期","原始账单金额","确认账单金额","差额","状态"];
|
|
|
- $list = [];
|
|
|
- foreach ($bills as $bill){
|
|
|
- $list[] = [
|
|
|
- $bill->owner ? ($bill->owner->userOwnerGroup ? $bill->owner->userOwnerGroup->name : '') : '',
|
|
|
- $bill->owner ? ($bill->owner->customer ? $bill->owner->customer->name : '') : '',
|
|
|
- $bill->owner ? $bill->owner->name : '',
|
|
|
- $bill->counting_month,
|
|
|
- $bill->updated_at,
|
|
|
- $bill->initial_fee,
|
|
|
- $bill->confirm_fee,
|
|
|
- $bill->difference,
|
|
|
- $bill->confirmed == '是' ? '已确认' : '未确认',
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- $post = Http::post(config('go.export.url'),['type'=>'base','data'=>json_encode(["row"=>$column,"list"=>$list],JSON_UNESCAPED_UNICODE)]);
|
|
|
- if ($post->status() == 500){
|
|
|
- throw new Exception($post->header("Msg"));
|
|
|
- }
|
|
|
- return response($post,200, [
|
|
|
- "Content-type"=>"application/octet-stream",
|
|
|
- "Content-Disposition"=>"attachment; filename=客户账单报表-".date('ymdHis').'.xlsx',
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
- public function updateBillReport(Request $request)
|
|
|
- {
|
|
|
- if(!Gate::allows('客户管理-财务-账单确认-编辑')){ return ["success"=>false,'data'=>"无权操作!"]; }
|
|
|
- if (!$request->confirm_fee || !is_numeric($request->confirm_fee) || $request->confirm_fee<0)return ["success"=>false,"data"=>"非法金额参数"];
|
|
|
- $date = date('Y-m-d H:i:s');
|
|
|
- app('OwnerBillReportService')->update(["id"=>$request->id],["confirm_fee"=>$request->confirm_fee,"difference"=>DB::raw($request->confirm_fee.'- initial_fee'),"updated_at"=>$date]);
|
|
|
- return ["success"=>true,"data"=>$date];
|
|
|
- }
|
|
|
-
|
|
|
- public function billConfirm(Request $request)
|
|
|
- {
|
|
|
- if(!Gate::allows('客户管理-财务-账单确认-完结')){ return ["success"=>false,'data'=>"无权操作!"]; }
|
|
|
- if (!($request->id ?? false))return["success"=>false,"data"=>"非法参数"];
|
|
|
- app('OwnerBillReportService')->update(["id"=>$request->id],["confirmed"=>"是"]);
|
|
|
- return ["success"=>true];
|
|
|
- }
|
|
|
-
|
|
|
- private function validator(array $params){
|
|
|
- $id = $params['id'] ?? null;
|
|
|
- $validator=Validator::make($params,[
|
|
|
- 'id' => ['required_without_all:code,name'],
|
|
|
- 'code'=>['required','max:50',$id ? "unique:owners,code,$id":'unique:owners,code'],
|
|
|
- 'name'=>['required','max:50'],
|
|
|
- 'customer_id'=>['required'],
|
|
|
- 'owner_group_id'=>['required'],
|
|
|
- 'tax_rate' => ['required','numeric'],
|
|
|
- ],[
|
|
|
- 'required'=>':attribute 为必填项',
|
|
|
- 'unique'=>':attribute 已存在',
|
|
|
- ],[
|
|
|
- 'code'=>'项目代码',
|
|
|
- 'name'=>'项目名称',
|
|
|
- 'customer_id'=>'客户',
|
|
|
- 'owner_group_id'=>'工作组',
|
|
|
- 'tax_rate' => '税率'
|
|
|
- ]);
|
|
|
- return $validator;
|
|
|
+ return response()->view('customer.finance.billConfirmation');
|
|
|
}
|
|
|
}
|