diff --git a/app/Helper/function.php b/app/Helper/function.php index 78745d7e..e43e6a1e 100644 --- a/app/Helper/function.php +++ b/app/Helper/function.php @@ -14,6 +14,17 @@ if (!function_exists('uuid_generate')) { } } +if (!function_exists('create_customer_num')) { + /** + * 生成客户编号 + * @return string + */ + function create_customer_num() + { + return 'K'.date('YmdHis').\Illuminate\Support\Facades\Redis::incr('customer_num_id'); + } +} + if (!function_exists('create_order_num')) { /** * 生成唯一订单号 diff --git a/app/Http/Controllers/Account/PayController.php b/app/Http/Controllers/Account/PayController.php new file mode 100644 index 00000000..a7fa6e4b --- /dev/null +++ b/app/Http/Controllers/Account/PayController.php @@ -0,0 +1,71 @@ +ajax()){ + $res = OrderPay::with('order') + ->orderBy('status','asc') + ->orderByDesc('created_at') + ->paginate($request->input('limit',30)); + return $this->success('ok',$res->items(),$res->total()); + } + return View::make('account.pay.index'); + } + + public function check(Request $request) + { + $model = OrderPay::with('order')->where('id','=',$request->input('id'))->first(); + if ($request->ajax()){ + $data = $request->all(['check_result','status']); + if ($model->order==null){ + return $this->error('订单已不存在'); + } + DB::beginTransaction(); + try { + if ($data['status']==2&&!$data['check_result']){ + return $this->error('请备注审核未通过原因'); + } + $model->update([ + 'check_result' => $data['check_result'], + 'status' => $data['status'], + 'check_user_id' => $request->user()->id, + 'check_user_nickname' => $request->user()->nickname, + 'check_time' => date('Y-m-d H:i:s'), + ]); + if ($data['status']==1){ + $payed_money = $model->order->payed_money + $model->money; + if ($payed_money >= $model->order->total_money){ + $model->order->update([ + 'payed_money' => $payed_money, + 'status' => 1, + ]); + }else{ + $model->order->update([ + 'payed_money' => $payed_money, + ]); + } + } + DB::commit(); + return $this->success(); + }catch (\Exception $exception){ + DB::rollBack(); + Log::error('审核异常:'.$exception->getMessage()); + return $this->error(); + } + } + return View::make('account.pay.check',compact('model')); + } + +} diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 22fd9aee..5bf0908b 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -6,6 +6,8 @@ use App\Models\Cdr; use App\Models\CustomerRemark; use App\Models\Department; use App\Models\Node; +use App\Models\Order; +use App\Models\OrderPay; use App\Models\OrderRemark; use App\Models\Permission; use App\Models\Role; @@ -190,4 +192,12 @@ class ApiController extends Controller } + + public function payList(Request $request) + { + $id = $request->input('id'); + $res = OrderPay::query()->where('order_id','=',$id)->orderByDesc('id')->paginate($request->get('limit', 2)); + return $this->success('ok',['list'=>$res->items(),'lastPage'=>$res->lastPage()]); + } + } diff --git a/app/Http/Controllers/Crm/AssignmentController.php b/app/Http/Controllers/Crm/AssignmentController.php index 88bd34a0..816f40f9 100644 --- a/app/Http/Controllers/Crm/AssignmentController.php +++ b/app/Http/Controllers/Crm/AssignmentController.php @@ -87,7 +87,7 @@ class AssignmentController extends Controller DB::beginTransaction(); try{ $customer_id = DB::table('customer')->insertGetId([ - 'uuid' => uuid_generate(), + 'uuid' => create_customer_num(), 'name' => $data['name'], 'contact_name' => $data['contact_name'], 'contact_phone' => $data['contact_phone'], diff --git a/app/Http/Controllers/Crm/CustomerController.php b/app/Http/Controllers/Crm/CustomerController.php index 82afab39..7ff3faf5 100644 --- a/app/Http/Controllers/Crm/CustomerController.php +++ b/app/Http/Controllers/Crm/CustomerController.php @@ -22,6 +22,7 @@ class CustomerController extends Controller { if ($request->ajax()){ $data = $request->all([ + 'uuid', 'name', 'contact_name', 'contact_phone', @@ -42,6 +43,10 @@ class CustomerController extends Controller } }) ->where('status','=',3) + //客户编号 + ->when($data['uuid'], function ($query) use ($data) { + return $query->where('uuid', $data['uuid']); + }) //客户名称 ->when($data['name'], function ($query) use ($data) { return $query->where('name', $data['name']); @@ -114,7 +119,7 @@ class CustomerController extends Controller DB::beginTransaction(); try{ $customer_id = DB::table('customer')->insertGetId([ - 'uuid' => uuid_generate(), + 'uuid' => create_customer_num(), 'name' => $data['name'], 'contact_name' => $data['contact_name'], 'contact_phone' => $data['contact_phone'], diff --git a/app/Http/Controllers/Order/OrderController.php b/app/Http/Controllers/Order/OrderController.php index 0cb18a2a..5d6ec086 100644 --- a/app/Http/Controllers/Order/OrderController.php +++ b/app/Http/Controllers/Order/OrderController.php @@ -21,10 +21,32 @@ class OrderController extends Controller { if ($request->ajax()){ $user = $request->user(); + $data = $request->all([ + 'name', + 'contact_name', + 'contact_phone', + 'num', + ]); $res = Order::query() ->where(function ($q) use ($user){ return $q->where('frontend_user_id',$user->id)->orWhere('backend_user_id',$user->id); }) + //订单号 + ->when($data['num'], function ($query) use ($data) { + return $query->where('num', $data['num']); + }) + //客户名称 + ->when($data['name'], function ($query) use ($data) { + return $query->where('name', $data['name']); + }) + //联系电话 + ->when($data['contact_phone'], function ($query) use ($data) { + return $query->where('contact_phone', $data['contact_phone']); + }) + //联系人 + ->when($data['contact_name'], function ($query) use ($data) { + return $query->where('contact_name', $data['contact_name'] ); + }) ->orderBy('status','asc') ->orderByDesc('accept_time') ->paginate($request->get('limit', 30)); @@ -57,7 +79,9 @@ class OrderController extends Controller return $this->error('订单金额比例不正确'); } $user = User::query()->where('id',$data['user_id'])->first(); - $customer->update(['is_end'=>1]); + if ($customer->is_end!=1){ + $customer->update(['is_end'=>1]); + } Order::create([ 'num' => create_order_num(), 'customer_id' => $customer->id, @@ -164,6 +188,8 @@ class OrderController extends Controller 'pay_type' => $data['pay_type'], 'content' => $data['content'], 'status' => 0, + 'created_user_id' => $request->user()->id, + 'created_user_nickname' => $request->user()->nickname, ]); DB::commit(); return $this->success('操作成功,等待财务审核'); diff --git a/app/Models/OrderPay.php b/app/Models/OrderPay.php index 94dd09e7..b6c15683 100644 --- a/app/Models/OrderPay.php +++ b/app/Models/OrderPay.php @@ -3,9 +3,28 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Arr; class OrderPay extends Model { protected $table = 'order_pay'; protected $guarded = ['id']; + + protected $appends = ['pay_type_name','status_name']; + + public function getPayTypeNameAttribute() + { + return $this->attributes['pay_type_name'] = Arr::get(config('freeswitch.pay_type'),$this->pay_type,'-'); + } + + public function getStatusNameAttribute() + { + return $this->attributes['status_name'] = Arr::get([0=>'待审核',1=>'审核通过',2=>'审核不通过'],$this->status,'-'); + } + + public function order() + { + return $this->hasOne(Order::class,'id','order_id'); + } + } diff --git a/database/migrations/2021_03_29_142739_order_pay.php b/database/migrations/2021_03_29_142739_order_pay.php index 1ebdbca8..20df2afa 100644 --- a/database/migrations/2021_03_29_142739_order_pay.php +++ b/database/migrations/2021_03_29_142739_order_pay.php @@ -20,6 +20,12 @@ class OrderPay extends Migration $table->tinyInteger('pay_type')->comment('1现金|2对公账户|3支付宝|4微信|5其它'); $table->text('content')->comment('备注'); $table->tinyInteger('status')->default(0)->comment('审核状态,0待审核,1审核通过,2审核不通过'); + $table->unsignedBigInteger('check_user_id')->default(0)->comment('审核人ID'); + $table->string('check_user_nickname')->nullable()->comment('审核人昵称'); + $table->text('check_result')->nullable()->comment('审核备注'); + $table->text('check_time')->nullable()->comment('审核时间'); + $table->unsignedBigInteger('created_user_id')->default(0)->comment('操作人ID'); + $table->string('created_user_nickname')->nullable()->comment('操作人昵称'); $table->timestamps(); }); } diff --git a/database/seeds/MenuTableSeeder.php b/database/seeds/MenuTableSeeder.php index 1c8af797..8ea658c6 100644 --- a/database/seeds/MenuTableSeeder.php +++ b/database/seeds/MenuTableSeeder.php @@ -99,6 +99,33 @@ class MenuTableSeeder extends Seeder ], ] ], + [ + 'name' => '实时聊天', + 'route' => null, + 'url' => null, + 'icon' => 'layui-icon-cellphone-fine', + 'type' => 2, + 'sort' => 2, + 'permission_name' => 'chat', + 'child' => [ + [ + 'name' => '消息中心', + 'route' => 'chat.message', + 'url' => null, + 'icon' => 'layui-icon-note', + 'type' => 1, + 'permission_name' => 'chat.message', + ], + [ + 'name' => '语音通话', + 'route' => 'chat.audio', + 'url' => null, + 'icon' => 'layui-icon-service', + 'type' => 1, + 'permission_name' => 'chat.audio', + ], + ] + ], [ 'name' => 'CRM管理', 'route' => null, @@ -174,33 +201,6 @@ class MenuTableSeeder extends Seeder ], ] ], - [ - 'name' => '实时聊天', - 'route' => null, - 'url' => null, - 'icon' => 'layui-icon-cellphone-fine', - 'type' => 2, - 'sort' => 2, - 'permission_name' => 'chat', - 'child' => [ - [ - 'name' => '消息中心', - 'route' => 'chat.message', - 'url' => null, - 'icon' => 'layui-icon-note', - 'type' => 1, - 'permission_name' => 'chat.message', - ], - [ - 'name' => '语音通话', - 'route' => 'chat.audio', - 'url' => null, - 'icon' => 'layui-icon-service', - 'type' => 1, - 'permission_name' => 'chat.audio', - ], - ] - ], [ 'name' => '订单模块', 'route' => null, @@ -220,6 +220,25 @@ class MenuTableSeeder extends Seeder ], ] ], + [ + 'name' => '账务模块', + 'route' => null, + 'url' => null, + 'icon' => 'layui-icon-diamond', + 'type' => 2, + 'sort' => 2, + 'permission_name' => 'account', + 'child' => [ + [ + 'name' => '订单付款', + 'route' => 'account.pay', + 'url' => null, + 'icon' => 'layui-icon-dollar', + 'type' => 1, + 'permission_name' => 'account.pay', + ], + ] + ], ]; $permissions = \App\Models\Permission::pluck('id','name')->toArray(); foreach ($datas as $k1 => $d1){ diff --git a/database/seeds/UserTableSeeder.php b/database/seeds/UserTableSeeder.php index e4dc1b60..4e8e2d6e 100644 --- a/database/seeds/UserTableSeeder.php +++ b/database/seeds/UserTableSeeder.php @@ -247,6 +247,19 @@ class UserTableSeeder extends Seeder ], ], ], + [ + 'name' => 'account', + 'display_name' => '财务模块', + 'child' => [ + [ + 'name' => 'account.pay', + 'display_name' => '订单付款', + 'child' => [ + ['name' => 'account.pay.check', 'display_name' => '审核'], + ] + ], + ], + ], ]; foreach ($permissions as $pem1) { //生成一级权限 diff --git a/resources/views/account/pay/check.blade.php b/resources/views/account/pay/check.blade.php new file mode 100644 index 00000000..5fad977c --- /dev/null +++ b/resources/views/account/pay/check.blade.php @@ -0,0 +1,33 @@ +@extends('base') + +@section('content') +