创建版本

This commit is contained in:
2021-02-22 12:17:00 +08:00
commit af555f49c3
2332 changed files with 369202 additions and 0 deletions
@@ -0,0 +1,154 @@
<?php namespace Gdoo\Order\Controllers;
use DB;
use Request;
use Auth;
use Validator;
use Gdoo\Model\Form;
use Gdoo\Model\Grid;
use Gdoo\User\Models\User;
use Gdoo\Order\Models\Logistics;
use Gdoo\Index\Controllers\DefaultController;
class LogisticsController extends DefaultController
{
public $permission = ['dialog'];
public function indexAction()
{
$header = Grid::header([
'code' => 'logistics',
'referer' => 1,
'search' => ['by' => ''],
'trash_btn' => 0,
]);
$cols = $header['cols'];
$cols['actions']['options'] = [[
'name' => '编辑',
'action' => 'edit',
'display' => $this->access['edit'],
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$model->select($header['select']);
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header);
return $items->toJson();
}
$header['buttons'] = [
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
];
$header['cols'] = $cols;
$header['tabs'] = Logistics::$tabs;
$header['bys'] = Logistics::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
// 新建客户联系人
public function createAction($action = 'edit')
{
$id = (int)Request::get('id');
$form = Form::make(['code' => 'logistics', 'id' => $id, 'action' => $action]);
return $this->display([
'form' => $form,
], 'create');
}
// 创建客户联系人
public function editAction()
{
return $this->createAction();
}
// 创建客户联系人
public function showAction()
{
return $this->createAction('show');
}
// 删除
public function deleteAction()
{
if (Request::method() == 'POST') {
$ids = Request::get('id');
return Form::remove(['code' => 'logistics', 'ids' => $ids]);
}
}
/**
* 弹出层信息
*/
public function dialogAction()
{
$search = search_form([
'advanced' => '',
'prefix' => '',
'offset' => '',
'sort' => '',
'order' => '',
'limit' => '',
], [
['text','logistics.name','名称'],
]);
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table('logistics');
// 排序方式
if ($query['sort'] && $query['order']) {
$model->orderBy('logistics.'.$query['sort'], $query['order']);
}
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
if ($query['q']) {
$model->where('logistics.name', 'like', '%'.$query['q'].'%');
}
$model->selectRaw("logistics.*, logistics.name as text");
if ($query['limit']) {
$rows = $model->paginate($query['limit']);
} else {
$rows['total'] = $model->count();
$rows['data'] = $model->get();
}
return response()->json($rows);
}
return $this->render([
'search' => $search,
'query' => $query,
]);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,407 @@
<?php namespace Gdoo\Order\Controllers;
use DB;
use Request;
use Auth;
use Cache;
use Gdoo\Customer\Models\Customer;
use Gdoo\Product\Models\Product;
use Gdoo\Product\Models\ProductCategory;
use Gdoo\Stock\Models\Warehouse;
use Gdoo\Order\Models\CustomerOrder;
use Gdoo\Stock\Models\Stock;
use Gdoo\Produce\Services\ProduceService;
use Gdoo\Index\Controllers\DefaultController;
class PlanController extends DefaultController
{
public $permission = [
'producePlan',
];
/**
* 生产计划总表
*/
public function indexAction()
{
// 开始天
$sdate = date('Y-m-d', strtotime("-1 day"));
// 结束天
$edate = date('Y-m-d', strtotime("+2 day"));
$search = search_form([], [[
'form_type' => 'date2',
'field' => 'date',
'name' => '计划日期',
'value' => [$sdate, $edate]
],[
'form_type' =>'select',
'field' => 'type',
'name' => '内销/外贸',
'options' => [['id'=>1, 'name'=> '内销'], ['id'=>2, 'name'=> '外贸']]
],[
'form_type' =>'dialog',
'field' => 'warehouse_id',
'name' => '仓库',
'options' => ['url' => 'stock/warehouse/dialog', 'query' => []]
],[
'form_type' =>'dialog',
'field' => 'category_id',
'name' => '产品类别',
'options' => ['url' => 'product/category/dialog', 'query' => []]
],
], 'model');
$query = [];
if (Request::method() == 'POST') {
foreach($search['where'] as $where) {
if ($where['active']) {
$query[$where['field']] = $where['search'];
}
}
if ($query['date']) {
$sdate = $query['date'][0];
$edate = $query['date'][1];
}
$rows = ProduceService::getPlanDetail($sdate, $edate, $query['warehouse_id'], $query['category_id'], $query['type']);
$json = ['data' => $rows, 'status' => true];
return response()->json($json);
}
$header = [
'table' => 'produce_data',
'master_table' => 'produce_data',
'buttons' => [],
'search_form' => $search,
'simple_search_form' => 0,
];
$header['left_buttons'] = [
['name' => '导出', 'color' => 'default', 'icon' => 'fa-mail-forward', 'action' => 'export', 'display' => 1],
];
return $this->display([
'search' => $search,
'header' => $header,
]);
}
/**
* 外销进度表
*/
public function export_saleAction()
{
// 开始天
$sdate = date('Y-m-01');
// 结束天
$edate = date('Y-m-d');
$options = option('flow.status');
$search = search_form([], [[
'form_type' => 'date2',
'field' => 'mm.created_dt',
'name' => '订单日期',
'value' => [$sdate, $edate]
],[
'form_type' => 'text',
'field' => 'mm.sn',
'name' => '单据编号',
],[
'form_type' =>'dialog',
'field' => 'mm.product_id',
'name' => '产品名称',
'options' => ['url' => 'product/product/dialog', 'query' => []]
],[
'form_type' =>'dialog',
'field' => 'mm.customer_id',
'name' => '客户',
'options' => ['url' => 'customer/customer/dialog', 'query' => []]
],[
'form_type' =>'select',
'field' => 'mm.status',
'name' => '状态',
'options' => $options
],
], 'model');
$query = $search['query'];
if (Request::method() == 'POST') {
$rows = [];
if ($query['filter'] == 1) {
$sql = "mm.status,
mm.id,
mm.sn,
mm.created_at,
mm.created_dt,
mm.customer_id,
mm.customer_name,
mm.customer_code,
mm.product_id,
mm.product_code,
mm.product_name,
mm.product_spec,
mm.quantity,
mm.batch_sn,
pp.plan_num,
r.storage_num
FROM (SELECT m.status,
m.id,
m.sn,
m.created_at,
".sql_year_month_day('m.created_at', 'ts')." AS created_dt,
m.customer_id,
c.name AS customer_name,
c.code AS customer_code,
d.product_id,
p.code AS product_code,
p.name AS product_name,
p.spec AS product_spec,
d.quantity,
d.batch_sn
FROM customer_order_data d
LEFT JOIN product p ON p.id = d.product_id
LEFT JOIN customer_order m ON m.id = d.order_id
LEFT JOIN customer c ON c.id = m.customer_id
WHERE m.type_id = 2) mm
LEFT JOIN (SELECT produce_plan_data.batch_sn,
produce_plan_data.product_id,
sum(isnull(produce_plan_data.plan_num, 0)) AS plan_num
FROM produce_plan_data
WHERE produce_plan_data.batch_sn IS NOT NULL AND produce_plan_data.plan_num IS NOT NULL
GROUP BY produce_plan_data.product_id, produce_plan_data.batch_sn) pp ON mm.product_id = pp.product_id AND mm.batch_sn = pp.batch_sn
LEFT JOIN (SELECT stock_record10_data.product_id,
stock_record10_data.batch_sn,
sum(isnull(stock_record10_data.quantity, 0)) AS storage_num
FROM stock_record10_data
GROUP BY stock_record10_data.product_id, stock_record10_data.batch_sn) r ON mm.product_id = r.product_id AND mm.batch_sn = r.batch_sn
";
$model = DB::query()->selectRaw($sql)
->orderBy('created_at', 'desc');
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$rows = $model->get();
$options = $options->pluck('name', 'id');
$rows->transform(function($item) use($options) {
$item['status'] = $options[$item['status']];
return $item;
});
}
$json = ['data' => $rows, 'status' => true];
return response()->json($json);
}
$search['table'] = 'produce_plan';
return $this->display([
'search' => $search,
]);
}
/**
* 生产计划
*/
public function produceAction()
{
// 开始天
$sdate = date('Y-m-d', strtotime("-1 day"));
// 结束天
$edate = date('Y-m-d', strtotime("+2 day"));
$search = search_form([], [[
'form_type' => 'date2',
'field' => 'date',
'name' => '计划日期',
'value' => [$sdate, $edate]
],[
'form_type' =>'select',
'field' => 'type',
'name' => '内销/外贸',
'options' => [['id'=>1, 'name'=> '内销'], ['id'=>2, 'name'=> '外贸']]
],[
'form_type' =>'dialog',
'field' => 'category_id',
'name' => '产品类别',
'options' => ['url' => 'product/category/dialog', 'query' => []]
],
], 'model');
$query = [];
if (Request::method() == 'POST') {
foreach($search['where'] as $where) {
if ($where['active']) {
$query[$where['field']] = $where['search'];
}
}
if ($query['date']) {
$sdate = $query['date'][0];
$edate = $query['date'][1];
}
$dates = array_reverse(date_range($sdate, $edate));
$columns = [];
// 创建计划主表
foreach ($dates as $produce_dt) {
if ($produce_dt) {
$produce = DB::table('produce_data')
->where('date', $produce_dt)
->first();
$editable = false;
$btn = '';
if ($produce['status'] == 1) {
$btn = ' <a href="javascript:;" class="btn btn-default btn-xs disabled">已提交</a>';
} else {
if ($this->access['produce_save']) {
$btn .= ' <a href="javascript:;" data-toggle="produce_data" data-id="'.$produce_dt.'" data-action="save" class="btn btn-default btn-xs">保存</a>';
$editable = true;
}
if ($this->access['produce_submit']) {
$btn .= ' <a href="javascript:;" data-toggle="produce_data" data-id="'.$produce_dt.'" data-action="submit" class="btn btn-default btn-xs">提交</a>';
}
}
$_produce_dt = str_replace('-', '_', $produce_dt);
$columns[] = [
'headerName' => $produce_dt.$btn,
'cellRenderer' => 'htmlCellRenderer',
'children' => [
['cellClass' => 'text-right', 'headerName' => '发货计划', 'width' => 60, 'cellRenderer' => 'wfhjh', 'field' => 'wfhjh_num_'.$_produce_dt, 'type' => 'number', 'numberOptions' => ['places' => 0, 'default' => ''], 'calcFooter' => 'sum'],
['cellClass' => 'text-right', 'headerName' => '营销计划', 'width' => 60, 'field' => 'sale_plan_num_'.$_produce_dt, 'type' => 'number', 'numberOptions' => ['places' => 0, 'default' => ''], 'calcFooter' => 'sum', 'editable'=> $editable],
['cellClass' => 'text-right', 'headerName' => '生产计划', 'width' => 60, 'field' => 'produce_plan_num_'.$_produce_dt, 'type' => 'number', 'numberOptions' => ['places' => 0, 'default' => ''], 'calcFooter' => 'sum'],
['cellClass' => 'text-right', 'headerName' => '计划变更', 'width' => 60, 'field' => 'produce_bg_num_'.$_produce_dt, 'type' => 'number', 'numberOptions' => ['places' => 0, 'default' => ''], 'calcFooter' => 'sum'],
['cellClass' => 'text-right', 'headerName' => '成品入库', 'width' => 60, 'field' => 'rk_num_'.$_produce_dt, 'type' => 'number', 'numberOptions' => ['places' => 0, 'default' => ''], 'calcFooter' => 'sum'],
]
];
}
}
$rows = ProduceService::getPlanDetail($sdate, $edate, 0, $query['category_id'], $query['type']);
$json = ['columns' => $columns, 'data' => $rows, 'status' => true];
return response()->json($json);
}
$header = [
'table' => 'produce_data',
'master_table' => 'produce_data',
'buttons' => [],
'search_form' => $search,
'simple_search_form' => 0,
];
$header['left_buttons'] = [
['name' => '导出', 'color' => 'default', 'icon' => 'fa-mail-forward', 'action' => 'export', 'display' => 1],
];
return $this->display([
'search' => $search,
'header' => $header,
]);
}
/**
* 获取发货计划明细
*/
public function producePlanAction()
{
$query = Request::all();
if (Request::method() == 'POST') {
$sql = "d.product_id, SUM(isnull(d.delivery_quantity,0) - isnull(i.Num,0) - isnull(r.Num,0)) as fhjh_num, m.pay_dt,
m.plan_delivery_dt,m.export_country,c.name as customer_name,m.sn
FROM customer_order_data AS d
left JOIN customer_order AS m ON m.id = d.order_id
left JOIN customer as c ON m.customer_id = c.id
LEFT JOIN (select dd.sale_data_id,SUM(dd.quantity) Num
from stock_delivery_data dd,stock_delivery mm
where mm.id = dd.delivery_id
GROUP BY dd.sale_data_id
) as i ON i.sale_data_id = d.id
LEFT JOIN (select dd.sale_data_id, SUM(dd.quantity) Num
from stock_allocation_data dd, stock_allocation mm
where mm.id = dd.allocation_id
GROUP BY dd.sale_data_id
) as r ON r.sale_data_id = d.id
";
$date = str_replace('_', '-', $query['date']);
$model = DB::query()->selectRaw($sql);
$model->whereRaw('ISNULL(d.use_close, 0) = 0 and m.status > 0')
->where('plan_delivery_dt', $date)
->where('product_id', $query['product_id'])
->havingRaw('isnull(SUM(d.delivery_quantity),0) - isnull(i.Num,0) - isnull(r.Num,0) <> 0')
->groupBy(DB::raw('m.sn, d.product_id, d.delivery_quantity, i.Num, r.Num, m.pay_dt, m.plan_delivery_dt, m.export_country, c.name, m.sn'));
$rows = $model->get();
return ['data' => $rows];
}
return $this->render([
'query' => $query,
]);
}
// 保存生产计划
public function produce_saveAction()
{
if (Request::method() == 'POST') {
$gets = Request::all();
$date = $gets['date'];
foreach ($gets['rows'] as $row) {
$has = DB::table('produce_data')
->where('product_id', $row['product_id'])
->where('date', $date)
->first();
if (empty($has)) {
$row['date'] = $date;
DB::table('produce_data')->insert($row);
} else {
if ($has['quantity'] > 0) {
DB::table('produce_data')->where('id', $has['id'])->update($row);
} else {
// 数量如果不大于0就删除
DB::table('produce_data')->where('id', $has['id'])->delete();
}
}
}
return $this->json('营销计划保存成功。', true);
}
}
// 提交生产计划
public function produce_submitAction()
{
if (Request::method() == 'POST') {
$gets = Request::all();
$count = DB::table('produce_data')->where('date', $gets['date'])->get();
if ($count > 0) {
DB::table('produce_data')->where('date', $gets['date'])->update(['status' => 1]);
return $this->json('营销计划提交成功。', true);
} else {
return $this->json('营销计划为空不能提交。', true);
}
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,299 @@
<?php namespace Gdoo\Order\Controllers;
use DB;
use Request;
use Validator;
use Gdoo\User\Models\User;
use Gdoo\Order\Models\SampleApply;
use Gdoo\Order\Models\SampleApplyProduct;
use Gdoo\Model\Grid;
use Gdoo\Model\Form;
use Gdoo\Order\Services\OrderService;
use Gdoo\Index\Controllers\WorkflowController;
class SampleApplyController extends WorkflowController
{
public $permission = ['dialog', 'serviceDelivery'];
// 列表
public function indexAction()
{
$header = Grid::header([
'code' => 'sample_apply',
'referer' => 1,
'search' => ['by' => ''],
]);
$cols = $header['cols'];
$cols = $header['cols'];
// 自定义列
$customFields = [
'quantity' => [
'headerName' => '数量',
'field' => 'quantity',
'calcFooter' => 'sum',
'width' => 80,
'suppressMenu' => true,
'type' => 'number',
'cellStyle' => ['text-align' => 'right'],
],
'money' => [
'headerName' => '金额',
'field' => 'money',
'calcFooter' => 'sum',
'width' => 80,
'suppressMenu' => true,
'type' => 'number',
'cellStyle' => ['text-align' => 'right'],
],
];
$cols = Grid::addColumns($cols, 'master_region_id_name', $customFields);
$cols['actions']['options'] = [[
'name' => '显示',
'action' => 'show',
'display' => $this->access['show'],
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
if ($this->access['index'] <> 4) {
// 这里需要包括创建者权限
$authorise = User::authoriseAccess();
$model->whereIn('sample_apply.created_id', $authorise);
}
$model->select($header['select']);
// 发货统计
$model->leftJoin(DB::raw('(select SUM(ISNULL(d.money, 0)) money, SUM(ISNULL(d.quantity, 0)) quantity, d.sample_id
FROM sample_apply_data as d
GROUP BY d.sample_id
) sad
'), 'sample_apply.id', '=', 'sad.sample_id');
$model->addSelect(DB::raw('sad.*'));
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header);
return $items->toJson();
}
$header['buttons'] = [
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
];
$header['right_buttons'] = [
['name' => '关闭', 'color' => 'default', 'icon' => 'fa-lock', 'action' => 'close', 'display' => $this->access['close']],
];
$header['cols'] = $cols;
$header['tabs'] = SampleApply::$tabs;
$header['bys'] = SampleApply::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
// 明细列表
public function detailAction()
{
$header = Grid::header([
'code' => 'sample_apply',
'referer' => 1,
'template_id' => 79,
'search' => ['by' => ''],
]);
$cols = $header['cols'];
$cols['actions']['options'] = [[
'name' => '显示',
'action' => 'show',
'display' => $this->access['show'],
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
if ($this->access['index'] <> 4) {
// 这里需要包括创建者权限
$authorise = User::authoriseAccess();
$model->whereIn('sample_apply.created_id', $authorise);
}
$model->select($header['select']);
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header);
return $items->toJson();
}
$header['buttons'] = [
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
];
$header['right_buttons'] = [
['name' => '关闭', 'color' => 'default', 'icon' => 'fa-lock', 'action' => 'close', 'display' => $this->access['close']],
];
$header['cols'] = $cols;
$header['tabs'] = SampleApply::$tabs2;
$header['bys'] = SampleApply::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
// 新建
public function createAction($action = 'edit')
{
$id = (int) Request::get('id');
$header['action'] = $action;
$header['code'] = 'sample_apply';
$header['id'] = $id;
$form = Form::make($header);
$tpl = $action == 'print' ? 'print' : 'create';
return $this->display([
'form' => $form,
], $tpl);
}
// 编辑
public function editAction()
{
return $this->createAction();
}
// 审核
public function auditAction()
{
return $this->createAction('audit');
}
// 显示
public function showAction()
{
return $this->createAction('show');
}
// 打印
public function printAction()
{
$this->layout = 'layouts.print2';
print_prince($this->createAction('print'));
}
// 关闭
public function closeAction()
{
$gets = Request::all();
if (Request::method() == 'POST') {
$rows = SampleApplyProduct::whereIn('id', $gets['ids'])->get();
foreach($rows as $row) {
$row->use_close = $row->use_close == 1 ? 0 : 1;
$row->save();
}
return $this->json('恭喜你,操作成功。', url_referer('index'));
}
return $this->render([
'gets' => $gets,
]);
}
// 样品出库
public function serviceDeliveryAction()
{
$header = Grid::header([
'code' => 'sample_apply',
'prefix' => '',
]);
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
if ($query['master']) {
$model = DB::table('sample_apply')
->leftJoin('department', 'department.id', '=', 'sample_apply.department_id')
->leftJoin('customer_region', 'customer_region.id', '=', 'sample_apply.region_id');
$model->orderBy('sample_apply.id', 'desc');
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$model->whereExists(function($q) {
$q->selectRaw('1 FROM('.OrderService::getSampleSelectDetailSql().') as sad')->whereRaw('sad.sample_id = sample_apply.id');
});
$model->selectRaw('
sample_apply.*,
department.name as department_name,
customer_region.name as region_name
');
$rows = $model->get();
} else {
$model = DB::query()->selectRaw('* FROM('.OrderService::getSampleSelectDetailSql().') as a');
$rows = $model->whereIn('sample_id', (array)$query['ids'])->get(['*', 'sample_data_id as id'])->toArray();
}
return $this->json($rows, true);
}
return $this->render([
'search' => $search,
'query' => $query,
]);
}
// 删除
public function deleteAction()
{
if (Request::method() == 'POST') {
$ids = Request::get('id');
return Form::remove(['code' => 'sample_apply', 'ids' => $ids]);
}
}
}
@@ -0,0 +1,137 @@
<?php namespace Gdoo\Order\Controllers;
use DB;
use Request;
use Validator;
use Gdoo\Model\Grid;
use Gdoo\Model\Form;
use Gdoo\Order\Models\CustomerOrderType;
use Gdoo\Index\Controllers\DefaultController;
class TypeController extends DefaultController
{
public $permission = ['dialog'];
public function indexAction()
{
$header = Grid::header([
'code' => 'customer_order_type',
'referer' => 1,
'search' => ['by' => ''],
'trash_btn' => 0,
]);
$cols = $header['cols'];
$cols['actions']['options'] = [[
'name' => '编辑',
'action' => 'edit',
'display' => $this->access['edit'],
]];
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = DB::table($header['table'])->setBy($header);
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->orderBy($header['sort'], $header['order'])
->orderBy('id', 'desc');
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$model->select($header['select']);
$rows = $model->paginate($query['limit'])->appends($query);
$items = Grid::dataFilters($rows, $header);
return $items->toJson();
}
$header['buttons'] = [
['name' => '删除', 'icon' => 'fa-remove', 'action' => 'delete', 'display' => $this->access['delete']],
['name' => '导出', 'icon' => 'fa-share', 'action' => 'export', 'display' => 1],
];
$header['cols'] = $cols;
$header['tabs'] = CustomerOrderType::$tabs;
$header['bys'] = CustomerOrderType::$bys;
$header['js'] = Grid::js($header);
return $this->display([
'header' => $header,
]);
}
// 新建客户联系人
public function createAction()
{
$id = (int)Request::get('id');
$form = Form::make(['code' => 'customer_order_type', 'id' => $id]);
return $this->render([
'form' => $form,
], 'create');
}
// 创建客户联系人
public function editAction()
{
return $this->createAction();
}
/**
* 弹出层信息
*/
public function dialogAction()
{
$header = Grid::header([
'code' => 'customer_order_type',
]);
$search = $header['search_form'];
$query = $search['query'];
if (Request::method() == 'POST') {
$model = CustomerOrderType::query();
foreach ($header['join'] as $join) {
$model->leftJoin($join[0], $join[1], $join[2], $join[3]);
}
$model->where('customer_order_type.status', 1)
->orderBy($header['sort'], $header['order']);
foreach ($search['where'] as $where) {
if ($where['active']) {
$model->search($where);
}
}
$model->select($header['select']);
$rows = $model->paginate($query['limit']);
$items = Grid::dataFilters($rows, $header, function($item) {
$item['text'] = $item['name'];
return $item;
});
return response()->json($items);
}
$query['form_id'] = $query['jqgrid'] == '' ? $query['id'] : $query['jqgrid'];
return $this->render([
'search' => $search,
'query' => $query,
]);
}
// 删除
public function deleteAction()
{
if (Request::method() == 'POST') {
$ids = Request::get('id');
return Form::remove(['code' => 'customer_order_type', 'ids' => $ids]);
}
}
}
@@ -0,0 +1,276 @@
<?php namespace Gdoo\Order\Controllers;
use DB;
use Request;
use Auth;
use Gdoo\Index\Controllers\DefaultController;
class WidgetController extends DefaultController
{
public $permission = ['index', 'goods'];
public function indexAction()
{
if (Request::method() == 'POST') {
$region = regionCustomer();
$ym = date('Y-m');
$ymd = date('Y-m-d');
// 本日收到 []个客户[]张订单,[]件货。
$model = DB::table('customer_order')
->leftJoin('customer_order_data', 'customer_order_data.order_id', '=', 'customer_order.id')
->leftJoin('product', 'product.id', '=', 'customer_order_data.product_id')
->leftJoin('customer', 'customer.id', '=', 'customer_order.customer_id')
->whereRaw('product.id <> 20226 and isnull(product.product_type, 0) = 1');
$model->whereRaw(sql_year_month_day('customer_order.created_at', 'ts').'=?', [$ymd]);
$model->selectRaw('
COUNT(DISTINCT customer_order.id) AS count,
COUNT(DISTINCT customer_order.customer_id) AS customer_count,
SUM(customer_order_data.delivery_quantity) AS quantity,
sum(isnull(customer_order_data.money, 0) - isnull(customer_order_data.other_money, 0)) money
');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$res = $model->first();
$rows[] = ['id' => 2, 'title' => '本日收到 <span class="red">'.number_format($res['customer_count']).'</span> 个客户 <span class="red">'.number_format($res['count']).'</span> 张订单,<span class="red">'.number_format($res['quantity']).'</span> 件,<span class="red">'.number_format($res['money']).'</span> 元'];
// 本月收到 []个客户[]张订单,[]件货。
$model = DB::table('customer_order')
->leftJoin('customer_order_data', 'customer_order_data.order_id', '=', 'customer_order.id')
->leftJoin('product', 'product.id', '=', 'customer_order_data.product_id')
->leftJoin('customer', 'customer.id', '=', 'customer_order.customer_id');
$model->whereRaw('product.id <> 20226 and isnull(product.product_type, 0) = 1');
$model->whereRaw(sql_year_month('customer_order.created_at', 'ts').'=?', [$ym]);
$model->selectRaw('
COUNT(DISTINCT customer_order.id) AS count,
COUNT(DISTINCT customer_order.customer_id) AS customer_count,
SUM(customer_order_data.delivery_quantity) AS quantity,
sum(isnull(customer_order_data.money, 0) - isnull(customer_order_data.other_money, 0)) money
');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$res = $model->first();
$rows[] = ['id' => 2, 'title' => '本月收到 <span class="red">'.number_format($res['customer_count']).'</span> 个客户 <span class="red">'.number_format($res['count']).'</span> 张订单,<span class="red">'.number_format($res['quantity']).'</span> 件,<span class="red">'.number_format($res['money']).'</span> 元'];
// 本月收到的订单中已发出[]张订单,[]件货
$model = DB::table('customer_order')
->leftJoin('customer_order_data', 'customer_order_data.order_id', '=', 'customer_order.id')
->leftJoin('product', 'product.id', '=', 'customer_order_data.product_id')
->leftJoin('customer', 'customer.id', '=', 'customer_order.customer_id');
$model->whereRaw('product.id <> 20226 and isnull(product.product_type, 0) = 1');
$model->whereRaw(sql_year_month('customer_order.created_at', 'ts').'=?', [$ym]);
$model->leftJoin(DB::raw("(
select
SUM(ISNULL(d.quantity, 0)) yf_num,
sum(isnull(d.money, 0) - isnull(d.other_money, 0)) yf_money,
d.sale_data_id,
d.sale_id
FROM stock_delivery_data as d
left join stock_delivery as m on m.id = d.delivery_id
GROUP BY d.sale_id, d.sale_data_id
) sdd
"), 'customer_order_data.id', '=', 'sdd.sale_data_id');
$model->where('sdd.yf_num', '>', 0);
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$model->selectRaw('
COUNT(DISTINCT customer_order.id) AS count,
COUNT(DISTINCT sdd.sale_id) AS count,
SUM(sdd.yf_num) AS quantity,
sum(sdd.yf_money) as money
');
$res = $model->first();
$rows[] = ['title' => '本月收到的订单中已发出 <span class="red">'.number_format($res['count']).'</span> 张订单,<span class="red">'.number_format($res['quantity']).'</span> 件,<span class="red">'.number_format($res['money']).'</span> 元'];
// 上月订单本月发出[]张,[]件货。
$model = DB::table('customer_order')
->leftJoin('customer_order_data', 'customer_order_data.order_id', '=', 'customer_order.id')
->leftJoin('product', 'product.id', '=', 'customer_order_data.product_id')
->leftJoin('customer', 'customer.id', '=', 'customer_order.customer_id')
->whereRaw('isnull(product.product_type, 0) = 1');
$model->whereRaw(sql_year_month('customer_order.created_at', 'ts').'=?', [date("Y-m", strtotime("-1 month"))]);
$model->leftJoin(DB::raw("(
select
SUM(ISNULL(d.quantity, 0)) yf_num,
sum(isnull(d.money, 0) - isnull(d.other_money, 0)) yf_money,
d.sale_data_id,
d.sale_id
FROM stock_delivery_data as d
left join stock_delivery as m on m.id = d.delivery_id
where ".sql_year_month('m.invoice_dt')." = '$ym'
GROUP BY d.sale_id, d.sale_data_id
) sdd
"), 'customer_order_data.id', '=', 'sdd.sale_data_id');
$model->where('sdd.yf_num', '>', 0)
->selectRaw('COUNT(DISTINCT sdd.sale_id) AS count, SUM(sdd.yf_num) AS quantity, sum(sdd.yf_money) as money');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$res = $model->first();
$rows[] = ['title' => '上月订单本月发出 <span class="red">'.number_format($res['count']).'</span> 张订单,<span class="red">'.number_format($res['quantity']).' </span>件,<span class="red">'.number_format($res['money']).'</span> 元'];
// 本月共发出件和金额
$delivery = DB::table('stock_delivery')
->leftJoin('stock_delivery_data', 'stock_delivery_data.delivery_id', '=', 'stock_delivery.id')
->leftJoin('product', 'product.id', '=', 'stock_delivery_data.product_id')
->leftJoin('customer', 'customer.id', '=', 'stock_delivery.customer_id');
$delivery->whereRaw('stock_delivery_data.product_id <> 20226 and isnull(product.product_type, 0) = 1');
$delivery->whereRaw(sql_year_month('stock_delivery.invoice_dt').'=?', [$ym]);
$delivery->groupBy('product.category_id', 'stock_delivery.invoice_dt')
->selectRaw('
stock_delivery.invoice_dt,
product.category_id,
COUNT(DISTINCT stock_delivery.id) AS count,
SUM(stock_delivery_data.quantity) AS quantity,
sum(isnull(stock_delivery_data.money, 0) - isnull(stock_delivery_data.other_money, 0)) money
');
// 本月退货件和金额
$cancel = DB::table('stock_cancel')
->leftJoin('stock_cancel_data', 'stock_cancel_data.cancel_id', '=', 'stock_cancel.id')
->leftJoin('product', 'product.id', '=', 'stock_cancel_data.product_id')
->leftJoin('customer', 'customer.id', '=', 'stock_cancel.customer_id');
$cancel->whereRaw('stock_cancel_data.product_id <> 20226 and isnull(product.product_type, 0) = 1');
$cancel->whereRaw(sql_year_month('stock_cancel.invoice_dt').'=?', [$ym]);
$cancel->groupBy('product.category_id', 'stock_cancel.invoice_dt')
->selectRaw('
stock_cancel.invoice_dt,
product.category_id,
COUNT(DISTINCT stock_cancel.id) AS count,
SUM(stock_cancel_data.quantity) AS quantity,
sum(isnull(stock_cancel_data.money, 0) - isnull(stock_cancel_data.other_money, 0)) money
');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$delivery->whereIn($key, $where);
$cancel->whereIn($key, $where);
}
}
$res = $delivery->unionAll($cancel)->get();
$rows[] = ['title' => '本月共发出 <span class="red">'.number_format($res->sum('count')).'</span> 张发货单,<span class="red">'.number_format($res->sum('quantity')).' </span>件,<span class="red">'.number_format($res->sum('money')).'</span> 元'];
// 本月直营共发出件和金额
$direct = DB::table('stock_direct')
->leftJoin('stock_direct_data', 'stock_direct_data.direct_id', '=', 'stock_direct.id')
->leftJoin('product', 'product.id', '=', 'stock_direct_data.product_id')
->leftJoin('customer', 'customer.id', '=', 'stock_direct.customer_id');
$direct->whereRaw('stock_direct_data.product_id <> 20226 and isnull(product.product_type, 0) = 1');
$direct->whereRaw(sql_year_month('stock_direct.invoice_dt').'=?', [$ym]);
$direct->selectRaw('
COUNT(DISTINCT stock_direct.id) AS count,
SUM(stock_direct_data.quantity) AS quantity,
sum(isnull(stock_direct_data.money, 0) - isnull(stock_direct_data.other_money, 0)) money
');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$direct->whereIn($key, $where);
}
}
$res = $direct->get();
$rows[] = ['title' => '本月直营共发出 <span class="red">'.number_format($res->sum('count')).'</span> 张发货单,<span class="red">'.number_format($res->sum('quantity')).' </span>件,<span class="red">'.number_format($res->sum('money')).'</span> 元'];
/*
// 订单审核状态。
$model = DB::table('customer_order')
->leftJoin('customer', 'customer.id', '=', 'customer_order.customer_id')
->selectRaw('sum(l.xshj_num) AS xshj_num, sum(l.sqjl_num) AS sqjl_num');
// 销售会计审核日期
$model->leftJoin(DB::raw("(select
m.data_id,
sum(case when d.run_name = '销售会计' then 1 else 0 end) as xshj_num,
sum(case when d.run_name = '省区经理' then 1 else 0 end) as sqjl_num
FROM model_run_log as d left join model_run as m on d.run_id = m.id where m.bill_id = 23 and d.updated_id = 0 and d.[option] = 1
GROUP BY m.data_id
) as l
"), 'l.data_id', '=', 'customer_order.id');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$res = $model->first();
$rows[] = ['title' => '订单待审核:销售会计<span class="red">'. $res['xshj_num'].'</span>张,省区经理<span class="red">'.$res['sqjl_num'].'</span>张'];
*/
/*
// 目前在途[]件。
$model = DB::table('customer_order')
->leftJoin('customer_order_data', 'customer_order_data.order_id', '=', 'customer_order.id')
->leftJoin('customer', 'customer.id', '=', 'customer_order.customer_id')
->whereRaw('FROM_UNIXTIME(customer_order.created_at,"%Y") BETWEEN '.$lastYear.' AND '.$nowYear)
->where('customer_order.delivery_time', '>', 0)
->where('customer_order.arrival_time', 0)
->selectRaw('SUM(customer_order_data.amount) AS amount');
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$res = $model->first();
$rows[] = ['title' => '目前在途订单 <span class="red">'.(int)$res['amount'].'</span> 件'];
*/
$json['total'] = sizeof($rows);
$json['data'] = $rows;
return response()->json($json);
}
return $this->render();
}
/**
* 明日预计到货列表
*/
public function goodsAction()
{
if (Request::method() == 'POST') {
$region = regionCustomer();
// 昨天
$lastDay = date("Y-m-d", strtotime("+1 day"));
$model = DB::table('stock_delivery')
->leftJoin('customer', 'customer.id', '=', 'stock_delivery.customer_id')
->whereRaw('stock_delivery.freight_arrival_date = ? and stock_delivery.freight_arrival_date IS NOT NULL', [$lastDay]);
if ($region['authorise']) {
foreach ($region['whereIn'] as $key => $where) {
$model->whereIn($key, $where);
}
}
$rows = $model->selectRaw('stock_delivery.id,stock_delivery.sn,customer.name,stock_delivery.freight_arrival_date')
->get();
$json['total'] = $rows->count();
$json['data'] = $rows;
return response()->json($json);
}
return $this->render();
}
}