Commit 4962574b by 汪伟伟

结算单

parent a7a7b87b
...@@ -3,8 +3,10 @@ ...@@ -3,8 +3,10 @@
namespace App\Admin\Controllers; namespace App\Admin\Controllers;
use App\Admin\Extensions\Tools\BackAction; use App\Admin\Extensions\Tools\BackAction;
use App\Admin\Extensions\Tools\OrderDetailAction;
use App\Admin\Repositories\TasksReceive; use App\Admin\Repositories\TasksReceive;
use App\Models\TasksApprove; use App\Models\TasksApprove;
use App\Models\TasksOrder;
use Dcat\Admin\Actions\Action; use Dcat\Admin\Actions\Action;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
use Dcat\Admin\Form; use Dcat\Admin\Form;
...@@ -38,66 +40,38 @@ class TaskReceiveController extends AdminController ...@@ -38,66 +40,38 @@ class TaskReceiveController extends AdminController
protected function getOrderData() protected function getOrderData()
{ {
return Grid::make(TasksReceive::with(['task','collects','user']), function (Grid $grid) { return Grid::make(TasksOrder::query(), function (Grid $grid) {
$user = Admin::user(); $user = Admin::user();
$user->is_admin == 0 && $grid->model()->where('user_id', $user->id); $grid->model()->where('user_id',$user->id);
if ($status == 0) $grid->model()->where('status', 0);
if ($status == 1) $grid->model()->where('status','>',0);
// dd(trans('admin.view'));//查看
// 在 display 回调中使用 // 在 display 回调中使用
$grid->column('序号')->display(function () { $grid->column('序号')->display(function () {
return $this->_index + 1; return $this->_index + 1;
}); });
if ($user->is_admin == 1) {
$grid->column('user.name', '用户');
$grid->disableEditButton();
}
// $grid->column('id')->sortable(); // $grid->column('id')->sortable();
$grid->column('task.name', '指标名称'); $grid->column('time','结算时间');
$grid->column('task.city_id', '地区')->distpicker(); $grid->column('num','数量');
$grid->column('task.year', '时间'); $grid->column('amount','金额');
$grid->column('task.refer', '参考信源'); $grid->column('pay_img','转账截图');
$grid->column('task.level', '等级'); $grid->column('status', '状态')->display(function ($val) {
return TasksOrder::ORDER_STATUS_DESC[$val];
if ($status == 1) { });
$grid->column('task.price', '单价');
$grid->column('collects.value', '指标值'); // $grid->column('created_at');
$grid->column('collects.reality_refer', '实际信源'); // $grid->column('updated_at')->sortable();
// $grid->column('collects.net_img', '网页截图');
}
if ($status == -1 || $status == 1){
$grid->column('status', '状态')->display(function ($val){
return \App\Models\TasksReceive::STATUS_DESC[$val];
});
}
$grid->actions(function (Grid\Displayers\Actions $actions) use ($user) { $grid->actions(function (Grid\Displayers\Actions $actions) use ($user) {
if ($user->is_admin == 0) { $actions->append(new OrderDetailAction());//
if ($this->status <= 2) {
$actions->append(new BackAction());//退回按钮
}else{
$actions->disableEdit();//已经通过的任务不能编辑
}
}
}); });
$grid->disableCreateButton()->disableDeleteButton()->disableEditButton()->disableViewButton();
$grid->filter(function (Grid\Filter $filter) { $grid->filter(function (Grid\Filter $filter) {
// $filter->equal('id'); // $filter->equal('id');
$filter->like('task.name', '指标名称');
}); });
$grid->disableDeleteButton()->disableCreateButton();
}); });
} }
......
...@@ -73,21 +73,24 @@ class TasksApproveController extends AdminController ...@@ -73,21 +73,24 @@ class TasksApproveController extends AdminController
$grid->column('collects.net_img', '截图链接'); $grid->column('collects.net_img', '截图链接');
if ($status) { if ($status) {
$grid->column('status', '状态')->display(function ($statusValue) {//是当前字段的值 $grid->column('status', '状态')->display(function ($statusValue) {//是当前字段的值
return $statusValue == 1 ? '未通过' : '通过'; return \App\Models\TasksApprove::APPROVE_STATUS_DESC[$statusValue];
}); });
} }
// $grid->tools('<a class="btn btn-primary disable-outline">测试按钮</a>'); // $grid->tools('<a class="btn btn-primary disable-outline">测试按钮</a>');
$grid->disableEditButton()->disableDeleteButton()->disableCreateButton()->disableFilterButton()->disableViewButton(); $grid->disableEditButton()->disableDeleteButton()->disableCreateButton()->disableFilterButton()->disableViewButton()->disableBatchDelete();
$grid->filter(function (Grid\Filter $filter) { $grid->filter(function (Grid\Filter $filter) {
$filter->equal('id'); $filter->equal('id');
}); });
$grid->actions(function (Grid\Displayers\Actions $actions){
if ($this->status < 3){
$actions->append(new PassAction());//通过按钮
$actions->append(new NotPassAction());//不通过按钮
}
});
$grid->actions([new PassAction()]);//通过按钮
$grid->actions([new NotPassAction()]);//不通过按钮
}); });
} }
......
<?php
namespace App\Admin\Controllers;
use App\Admin\Repositories\TasksOrder;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
class TasksOrderController extends AdminController
{
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
return Grid::make(new TasksOrder(), function (Grid $grid) {
$grid->column('id')->sortable();
$grid->column('task_id');
$grid->column('user_id');
$grid->column('receive_id');
$grid->column('name');
$grid->column('city_id');
$grid->column('year');
$grid->column('refer');
$grid->column('reality_refer');
$grid->column('value');
$grid->column('pay_img');
$grid->column('amount');
$grid->column('user_confirm');
$grid->column('pay_confirm');
$grid->column('created_at');
$grid->column('updated_at')->sortable();
$grid->filter(function (Grid\Filter $filter) {
$filter->equal('id');
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new TasksOrder(), function (Show $show) {
$show->field('id');
$show->field('task_id');
$show->field('user_id');
$show->field('receive_id');
$show->field('name');
$show->field('city_id');
$show->field('year');
$show->field('refer');
$show->field('reality_refer');
$show->field('value');
$show->field('pay_img');
$show->field('amount');
$show->field('user_confirm');
$show->field('pay_confirm');
$show->field('created_at');
$show->field('updated_at');
});
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
return Form::make(new TasksOrder(), function (Form $form) {
$form->display('id');
$form->text('task_id');
$form->text('user_id');
$form->text('receive_id');
$form->text('name');
$form->text('city_id');
$form->text('year');
$form->text('refer');
$form->text('reality_refer');
$form->text('value');
$form->text('pay_img');
$form->text('amount');
$form->text('user_confirm');
$form->text('pay_confirm');
$form->display('created_at');
$form->display('updated_at');
});
}
}
<?php
namespace App\Admin\Extensions\Tools;
use App\Models\Task;
use App\Models\TasksApprove;
use App\Models\TasksOrder;
use App\Models\TasksReceive;
use Dcat\Admin\Grid\BatchAction;
use Illuminate\Http\Request;
class CreateSettlementOrder extends BatchAction
{
protected $action;
// 注意action的构造方法参数一定要给默认值
public function __construct($title = null, $action = 1)
{
$this->title = $title;
$this->action = $action;
}
// 确认弹窗信息
public function confirm()
{
return '您确定要生成结算单吗?';
}
// 处理请求
public function handle(Request $request)
{
// 获取选中的ID数组
$keys = $this->getKey();
// 获取请求参数
// $action = $request->get('action');
$receives = TasksReceive::query()->whereIn('id', $keys)->get()->toArray();
$userId = array_unique(array_column($receives, 'user_id'));
if (count($userId) > 1) {
return $this->response()->error('必须同一个用户数据才能生成结算单');
}
$taskIds = array_unique(array_column($receives, 'task_id'));
$time = date('Y-m-d H:i:s');
$orderId = TasksOrder::query()->insertGetId([
'user_id' => $userId[0],
'time' => $time,
'num' => count($keys),
'amount' => Task::query()->whereIn('id', $taskIds)->sum('price'),
'created_at' => $time,
'updated_at' => $time,
]);
TasksApprove::query()->whereIn('receive_id', $keys)->update(['status' => 3]);
TasksReceive::query()->whereIn('id', $keys)->update(['order_id' => $orderId, 'status' => 4]);
// dd($orderId);
return $this->response()->success('生成结算单成功')->refresh();
}
// 设置请求参数
public function parameters()
{
return [
'action' => $this->action,
];
}
}
<?php
namespace App\Admin\Extensions\Tools;
use App\Admin\Forms\MsgSetting;
use App\Admin\Forms\OrderDetailTc;
use App\Models\Task;
use App\Models\TasksReceive;
use Dcat\Admin\Actions\Action;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Widgets\Modal;
use Illuminate\Http\Request;
class OrderDetailAction extends RowAction
{
protected $title = '查看详情';
/**
* 添加JS
*
*
* * @return string
*/
/**
* 处理请求,如果不需要接口处理,请直接删除这个方法
*
* @param Request $request
*
* @return \Dcat\Admin\Actions\Response
*/
public function handle(Request $request)
{
// 获取主键
$id = $this->getKey();
// $user = Admin::user();
return $this->response()->redirect('orderReceive/'.$id);
}
public function html()
{
// $this->setHtmlAttribute(['data-excel' => $this->row->excel_url, 'class' => 'download-btn fa fa-download']);
return parent::html();
}
}
<?php
namespace App\Admin\Forms;
use App\Models\TasksApprove;
use App\Models\TasksReceive;
use Dcat\Admin\Admin;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Grid;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
class OrderDetailTc extends Form implements LazyRenderable
{
use LazyWidget; // 使用异步加载功能
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
// 获取外部传递参数
$id = $this->payload['id'] ?? null;
// 表单参数
// $msg = $input['msg'] ?? null;
return $this
->response()
->success('Processed successfully')
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
// Since v1.6.5 弹出确认弹窗
// $this->confirm('您确定要提交表单吗', 'content');
// $this->text('msg','原因');
return Grid::make(\App\Admin\Repositories\TasksReceive::with(['task','collects','user']), function (Grid $grid) {
$user = Admin::user();
// dd(trans('admin.view'));//查看
// 在 display 回调中使用
$grid->column('序号')->display(function () {
return $this->_index + 1;
});
if ($user->is_admin == 1) {
$grid->column('user.name', '用户');
$grid->disableEditButton();
}
// $grid->column('id')->sortable();
$grid->column('task.name', '指标名称');
$grid->column('task.city_id', '地区')->distpicker();
$grid->column('task.year', '时间');
$grid->column('task.refer', '参考信源');
$grid->column('task.level', '等级');
$grid->column('task.price', '单价');
$grid->column('collects.value', '指标值');
$grid->column('collects.reality_refer', '实际信源');
// $grid->column('collects.net_img', '网页截图');
$grid->column('status', '状态')->display(function ($val){
return \App\Models\TasksReceive::STATUS_DESC[$val];
});
$grid->disableActions();
});
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
return [
// 'name' => 'John Doe',
// 'email' => 'John.Doe@gmail.com',
];
}
}
<?php
namespace App\Admin\Repositories;
use App\Models\TasksOrder as Model;
use Dcat\Admin\Repositories\EloquentRepository;
class TasksOrder extends EloquentRepository
{
/**
* Model.
*
* @var string
*/
protected $eloquentClass = Model::class;
}
...@@ -15,12 +15,18 @@ Route::group([ ...@@ -15,12 +15,18 @@ Route::group([
$router->resource('tasks', 'TaskController'); $router->resource('tasks', 'TaskController');
$router->get('receive', 'TaskController@receiveIndex'); $router->get('receive', 'TaskController@receiveIndex');
$router->get('receive/{id}', 'TaskController@receiveDetail'); $router->get('receive/{id}', 'TaskController@receiveDetail');
$router->resource('receives', 'TaskReceiveController'); $router->resource('receives', 'TaskReceiveController');
$router->resource('approves', 'TasksApproveController'); $router->resource('approves', 'TasksApproveController');
$router->resource('orders', 'TasksOrderController'); $router->resource('orders', 'TasksOrderController');
$router->get('orderReceive/{id}', 'TasksOrderController@orderReceive');
// $router->get('/approves/{id}/edit', 'TasksApproveController@edit'); // $router->get('/approves/{id}/edit', 'TasksApproveController@edit');
}); });
...@@ -11,6 +11,13 @@ class TasksApprove extends Model ...@@ -11,6 +11,13 @@ class TasksApprove extends Model
use HasDateTimeFormatter; use HasDateTimeFormatter;
protected $table = 'tasks_approves'; protected $table = 'tasks_approves';
const APPROVE_STATUS_DESC = [
0 => '未审核',
1 => '未通过',
2 => '通过',
3 => '已结算',
];
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
* *
......
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;
class TasksOrder extends Model
{
use HasDateTimeFormatter;
protected $table = 'tasks_orders';
}
...@@ -28,6 +28,7 @@ class TasksReceive extends Model ...@@ -28,6 +28,7 @@ class TasksReceive extends Model
protected $fillable = [ protected $fillable = [
'task_id', 'task_id',
'user_id', 'user_id',
'order_id',
'status', 'status',
'created_at', 'created_at',
'updated_at', 'updated_at',
...@@ -51,6 +52,11 @@ class TasksReceive extends Model ...@@ -51,6 +52,11 @@ class TasksReceive extends Model
return $this->belongsTo(AdminUser::class); return $this->belongsTo(AdminUser::class);
} }
public function order()
{
return $this->belongsTo(TasksOrder::class,'order_id','id');
}
public function collects() public function collects()
{ {
return $this->hasOne(TasksCollect::class, 'receive_id', 'id'); return $this->hasOne(TasksCollect::class, 'receive_id', 'id');
......
...@@ -17,6 +17,7 @@ class CreateTasksReceivesTable extends Migration ...@@ -17,6 +17,7 @@ class CreateTasksReceivesTable extends Migration
$table->bigIncrements('id'); $table->bigIncrements('id');
$table->bigInteger('task_id')->comment('系统任务id'); $table->bigInteger('task_id')->comment('系统任务id');
$table->bigInteger('user_id')->comment('领取任务的用户id'); $table->bigInteger('user_id')->comment('领取任务的用户id');
$table->bigInteger('order_id')->default('0')->comment('所属结算单id');
$table->tinyInteger('status')->default('0')->comment('任务状态:(0:已领取但未完成的任务;1:已经完成但未审核的任务;2:审核不通过的任务;3:审核通过但未结算的任务;4:已经结算的任务)'); $table->tinyInteger('status')->default('0')->comment('任务状态:(0:已领取但未完成的任务;1:已经完成但未审核的任务;2:审核不通过的任务;3:审核通过但未结算的任务;4:已经结算的任务)');
$table->timestamps(); $table->timestamps();
}); });
......
...@@ -18,7 +18,7 @@ class CreateTasksApprovesTable extends Migration ...@@ -18,7 +18,7 @@ class CreateTasksApprovesTable extends Migration
$table->bigInteger('task_id')->comment('系统任务id'); $table->bigInteger('task_id')->comment('系统任务id');
$table->bigInteger('user_id')->default('1')->comment('用户id'); $table->bigInteger('user_id')->default('1')->comment('用户id');
$table->bigInteger('receive_id')->comment('用户领取的任务id'); $table->bigInteger('receive_id')->comment('用户领取的任务id');
$table->tinyInteger('status')->default('0')->comment('0:未审核,1:审核不通过,2:审核通过'); $table->tinyInteger('status')->default('0')->comment('0:未审核,1:审核不通过,2:审核通过,3:已结算');
$table->string('msg')->nullable()->comment('未通过原因'); $table->string('msg')->nullable()->comment('未通过原因');
$table->timestamps(); $table->timestamps();
}); });
......
...@@ -15,19 +15,12 @@ class CreateTasksOrdersTable extends Migration ...@@ -15,19 +15,12 @@ class CreateTasksOrdersTable extends Migration
{ {
Schema::create('tasks_orders', function (Blueprint $table) { Schema::create('tasks_orders', function (Blueprint $table) {
$table->bigIncrements('id'); $table->bigIncrements('id');
$table->bigInteger('task_id')->comment('系统任务id');
$table->bigInteger('user_id')->default('1')->comment('用户id'); $table->bigInteger('user_id')->default('1')->comment('用户id');
$table->bigInteger('receive_id')->comment('用户领取的任务id'); $table->dateTime('time')->comment('计算时间');
$table->string('name')->default('1')->nullable()->comment('指标名称'); $table->integer('num')->comment('数量');
$table->string('city_id')->nullable()->comment('地区');
$table->string('year')->nullable()->comment('年份');
$table->string('refer')->nullable()->comment('参考信源');
$table->string('reality_refer')->nullable()->comment('实际信源链接');
$table->string('value')->nullable()->comment('数值');
$table->string('pay_img')->nullable()->comment('转账截图');
$table->decimal('amount')->default('0.00')->comment('总金额'); $table->decimal('amount')->default('0.00')->comment('总金额');
$table->tinyInteger('user_confirm')->default('0')->comment('用户是否确认'); $table->string('pay_img')->nullable()->comment('转账截图');
$table->tinyInteger('pay_confirm')->default('0')->comment('用户是否确认收款'); $table->tinyInteger('status')->default('0')->comment('0:未确认;1:已确认;2:确认收款');
$table->timestamps(); $table->timestamps();
}); });
} }
......
...@@ -62,9 +62,11 @@ namespace Dcat\Admin { ...@@ -62,9 +62,11 @@ namespace Dcat\Admin {
* @property Grid\Column|Collection refer_level * @property Grid\Column|Collection refer_level
* @property Grid\Column|Collection remark * @property Grid\Column|Collection remark
* @property Grid\Column|Collection amount * @property Grid\Column|Collection amount
* @property Grid\Column|Collection pay_confirm
* @property Grid\Column|Collection pay_img * @property Grid\Column|Collection pay_img
* @property Grid\Column|Collection time
* @property Grid\Column|Collection pay_confirm
* @property Grid\Column|Collection user_confirm * @property Grid\Column|Collection user_confirm
* @property Grid\Column|Collection order_id
* @property Grid\Column|Collection email_verified_at * @property Grid\Column|Collection email_verified_at
* *
* @method Grid\Column|Collection city_id(string $label = null) * @method Grid\Column|Collection city_id(string $label = null)
...@@ -118,9 +120,11 @@ namespace Dcat\Admin { ...@@ -118,9 +120,11 @@ namespace Dcat\Admin {
* @method Grid\Column|Collection refer_level(string $label = null) * @method Grid\Column|Collection refer_level(string $label = null)
* @method Grid\Column|Collection remark(string $label = null) * @method Grid\Column|Collection remark(string $label = null)
* @method Grid\Column|Collection amount(string $label = null) * @method Grid\Column|Collection amount(string $label = null)
* @method Grid\Column|Collection pay_confirm(string $label = null)
* @method Grid\Column|Collection pay_img(string $label = null) * @method Grid\Column|Collection pay_img(string $label = null)
* @method Grid\Column|Collection time(string $label = null)
* @method Grid\Column|Collection pay_confirm(string $label = null)
* @method Grid\Column|Collection user_confirm(string $label = null) * @method Grid\Column|Collection user_confirm(string $label = null)
* @method Grid\Column|Collection order_id(string $label = null)
* @method Grid\Column|Collection email_verified_at(string $label = null) * @method Grid\Column|Collection email_verified_at(string $label = null)
*/ */
class Grid {} class Grid {}
...@@ -179,9 +183,11 @@ namespace Dcat\Admin { ...@@ -179,9 +183,11 @@ namespace Dcat\Admin {
* @property Show\Field|Collection refer_level * @property Show\Field|Collection refer_level
* @property Show\Field|Collection remark * @property Show\Field|Collection remark
* @property Show\Field|Collection amount * @property Show\Field|Collection amount
* @property Show\Field|Collection pay_confirm
* @property Show\Field|Collection pay_img * @property Show\Field|Collection pay_img
* @property Show\Field|Collection time
* @property Show\Field|Collection pay_confirm
* @property Show\Field|Collection user_confirm * @property Show\Field|Collection user_confirm
* @property Show\Field|Collection order_id
* @property Show\Field|Collection email_verified_at * @property Show\Field|Collection email_verified_at
* *
* @method Show\Field|Collection city_id(string $label = null) * @method Show\Field|Collection city_id(string $label = null)
...@@ -235,9 +241,11 @@ namespace Dcat\Admin { ...@@ -235,9 +241,11 @@ namespace Dcat\Admin {
* @method Show\Field|Collection refer_level(string $label = null) * @method Show\Field|Collection refer_level(string $label = null)
* @method Show\Field|Collection remark(string $label = null) * @method Show\Field|Collection remark(string $label = null)
* @method Show\Field|Collection amount(string $label = null) * @method Show\Field|Collection amount(string $label = null)
* @method Show\Field|Collection pay_confirm(string $label = null)
* @method Show\Field|Collection pay_img(string $label = null) * @method Show\Field|Collection pay_img(string $label = null)
* @method Show\Field|Collection time(string $label = null)
* @method Show\Field|Collection pay_confirm(string $label = null)
* @method Show\Field|Collection user_confirm(string $label = null) * @method Show\Field|Collection user_confirm(string $label = null)
* @method Show\Field|Collection order_id(string $label = null)
* @method Show\Field|Collection email_verified_at(string $label = null) * @method Show\Field|Collection email_verified_at(string $label = null)
*/ */
class Show {} class Show {}
......
<?php
return [
'labels' => [
'TasksOrder' => 'TasksOrder',
'tasks-order' => 'TasksOrder',
],
'fields' => [
'task_id' => '系统任务id',
'user_id' => '用户id',
'receive_id' => '用户领取的任务id',
'name' => '指标名称',
'city_id' => '地区',
'year' => '年份',
'refer' => '参考信源',
'reality_refer' => '实际信源链接',
'value' => '数值',
'pay_img' => '转账截图',
'amount' => '总金额',
'user_confirm' => '用户是否确认',
'pay_confirm' => '用户是否确认收款',
],
'options' => [
],
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment