|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
+use App\Owner;
|
|
|
use App\Services\OwnerReportService;
|
|
|
use App\Services\OwnerService;
|
|
|
use Exception;
|
|
|
@@ -10,6 +11,7 @@ use Illuminate\Http\Request;
|
|
|
use Illuminate\Http\Response;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
class CustomerController extends Controller
|
|
|
{
|
|
|
@@ -35,7 +37,7 @@ class CustomerController extends Controller
|
|
|
|
|
|
public function projectReportExport(Request $request)
|
|
|
{
|
|
|
- if(!Gate::allows('客户管理-项目-报表')){ return '没有权限'; }
|
|
|
+ if(!Gate::allows('客户管理-项目-报表')){ return redirect('denied'); }
|
|
|
/** @var OwnerReportService $service */
|
|
|
$service = app('OwnerReportService');
|
|
|
$withs = ["ownerBillReport","owner"=>function($query){
|
|
|
@@ -82,14 +84,145 @@ class CustomerController extends Controller
|
|
|
if(!Gate::allows('客户管理-项目-查询')){ return redirect('denied'); }
|
|
|
/** @var OwnerService $service */
|
|
|
$service = app('OwnerService');
|
|
|
- $customers = $service->get(['customer_id'=>true],['customer']);
|
|
|
- return response()->view('customer.project.index');
|
|
|
+ $owners = $service->paginate(['customer_id'=>true],['customer',"userOwnerGroup","ownerStoragePriceModels","ownerAreaReport"=>function($query){
|
|
|
+ $month = date('Y-m');
|
|
|
+ /** @var Builder $query */
|
|
|
+ $query->where("counting_month","like",$month."%");
|
|
|
+ }]);
|
|
|
+ return response()->view('customer.project.index',compact("owners"));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function projectIndexExport(Request $request)
|
|
|
+ {
|
|
|
+ if(!Gate::allows('客户管理-项目-查询')){ return redirect('denied'); }
|
|
|
+ /** @var OwnerService $service */
|
|
|
+ $service = app('OwnerService');
|
|
|
+ $withs = ['customer',"userOwnerGroup","ownerStoragePriceModels","ownerAreaReport"=>function($query){
|
|
|
+ $month = date('Y-m');
|
|
|
+ /** @var Builder $query */
|
|
|
+ $query->where("counting_month","like",$month."%");
|
|
|
+ }];
|
|
|
+ $params = $request->input();
|
|
|
+ $params['customer_id']=true;
|
|
|
+ if ($request->checkAllSign ?? false) unset($params['checkAllSign']);
|
|
|
+ else $params = ["id"=>$request->data ?? ''];
|
|
|
+ $owners = $service->get($params,$withs);
|
|
|
+ $column = ["客户","税率","项目","货主代码","合同号","创建日期","销售名称","公司全称","联系人","联系电话","项目小组","用仓类型","当月结算面积","月单量预警","是否激活","项目描述"];
|
|
|
+ $list = [];
|
|
|
+ foreach ($owners as $owner){
|
|
|
+ $list[] = [
|
|
|
+ $owner->customer ? $owner->customer->name : '',
|
|
|
+ $owner->tax_rate,
|
|
|
+ $owner->name,
|
|
|
+ $owner->code,
|
|
|
+ $owner->contract_number,
|
|
|
+ $owner->created_at,
|
|
|
+ $owner->salesman,
|
|
|
+ $owner->customer ? $owner->customer->company_name : '',
|
|
|
+ $owner->linkman,
|
|
|
+ $owner->phone_number,
|
|
|
+ $owner->userOwnerGroup ? $owner->userOwnerGroup->name : '',
|
|
|
+ implode(",",array_unique(array_column(($owner->ownerStoragePriceModels)->toArray(),"using_type"))),
|
|
|
+ $owner->ownerAreaReport ? $owner->ownerAreaReport->accounting_area : '',
|
|
|
+ $owner->waring_line_on,
|
|
|
+ $owner->deleted_at ? '否' : '是',
|
|
|
+ $owner->description
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $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 projectCreate()
|
|
|
{
|
|
|
if(!Gate::allows('客户管理-项目-录入')){ return redirect('denied'); }
|
|
|
- return response()->view('customer.project.create');
|
|
|
+ $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"));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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()
|
|
|
@@ -109,4 +242,26 @@ class CustomerController extends Controller
|
|
|
if(!Gate::allows('客户管理-财务-账单确认')){ return redirect('denied'); }
|
|
|
return response()->view('customer.finance.billConfirmation');
|
|
|
}
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|