This commit is contained in:
weiz 2024-04-13 10:55:31 +08:00
parent ff4c4d55b7
commit d5bf964c21
5 changed files with 211 additions and 1 deletions

View File

@ -59,7 +59,7 @@
$where[] = ['contract_id', 'in', $contract_ids1];
}
if (!empty($params['contract_num'])) {
$contract_ids2 = MarketingContract::where('contract_num', 'like', '%' . $params['contract_num'] . '%')->column('id');
$contract_ids2 = MarketingContract::where('contract_code', 'like', '%' . $params['contract_num'] . '%')->column('id');
$where[] = ['contract_id', 'in', $contract_ids2];
}
if (!empty($params['part_b'])) {

View File

@ -0,0 +1,97 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\marketing;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\validate\marketing\MarketingContractRefluxValidate;
use app\common\model\dept\Dept;
use app\common\model\marketing\MarketingContract;
use app\common\model\marketing\MarketingContractReflux;
use app\common\model\marketing\MarketingCustom;
use think\facade\Db;
use think\response\Json;
/**
* 市场经营--合同信息控制器
* Class MarketingContractController
* @package app\adminapi\controller\marketing
*/
class MarketingContractRefluxController extends BaseAdminController
{
public function lists(): Json
{
$params = $this->request->get();
$where = [];
$page_no = !empty($params['page_no']) ? $params['page_no'] : 1;
$page_size = !empty($params['page_size']) ? $params['page_size'] : 15;
if (!empty($params['contract_name'])) {
$contract_ids1 = MarketingContract::where('contract_name', 'like', '%' . $params['contract_name'] . '%')->column('id');
$where[] = ['contract_id', 'in', $contract_ids1];
}
if (!empty($params['contract_num'])) {
$contract_ids2 = MarketingContract::where('contract_code', 'like', '%' . $params['contract_num'] . '%')->column('id');
$where[] = ['contract_id', 'in', $contract_ids2];
}
if (!empty($params['part_b'])) {
$contract_ids3 = MarketingContract::where('part_b', 'like', '%' . $params['part_b'] . '%')->column('id');
$where[] = ['contract_id', 'in', $contract_ids3];
}
if (!empty($params['contract_type'])) {
$where[] = ['contract_type', '=', $params['contract_type']];
}
$lists = MarketingContract::field('id,contract_code,contract_name,contract_type,business_nature,part_a,signed_amount,signed_dept,create_time')
->where($where)->where('reflux_status', 0)
->page($page_no, $page_size)
->order('id desc')
->select()
->each(function ($data) {
$custom = MarketingCustom::field('name')->where('id', 'part_a')->findOrEmpty();
$dept = Dept::field('name')->where('id', $data['signed_dept'])->findOrEmpty();
$data['part_a_name'] = $custom['name'];
$data['signed_dept_name'] = $dept['name'];
$data['contract_type_text'] = $data->contract_type_text;
$data['business_nature_text'] = $data->business_nature_text;
})
->toArray();
$count = MarketingCustom::where($where)->where('status', 1)->count();
return $this->success('成功', compact('count', 'lists', 'page_no', 'page_size'));
}
public function reflux(): bool|Json
{
$params = (new MarketingContractRefluxValidate())->post()->goCheck('reflux');
Db::startTrans();
try {
MarketingContractReflux::where('id', $params['id'])->update([
'contract_id' => $params['contract_id'],
'reflux_date' => !empty($params['reflux_date']) ? strtotime($params['reflux_date']) : 0,
'annex' => $params['annex'] ? json_encode($params['annex']) : null,
]);
MarketingContract::where('id', $params['contract_id'])->update([
'reflux_status' => 1
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
return $this->fail($e->getMessage());
}
}
}

View File

@ -0,0 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\marketing;
use app\common\model\marketing\MarketingContract;
use app\common\validate\BaseValidate;
/**
* 市场经营--合同信息验证器
* Class MarketingContractValidate
* @package app\adminapi\validate\marketing
*/
class MarketingContractRefluxValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'contract_id' => 'require|checkContract',
'reflux_date' => 'require|dateFormat:Y-m-d',
'annex' => 'checkAnnex',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'contract_id' => '关联合同',
'reflux_date' => '回流日期',
];
/**
* @notes 添加场景
* @return MarketingContractRefluxValidate
* @author likeadmin
* @date 2024/04/03 09:19
*/
public function sceneReflux()
{
return $this->only(['contract_id', 'reflux_date', 'annex']);
}
public function checkContract($value): bool|string
{
$data = MarketingContract::where('id', $value)->findOrEmpty();
return $data->isEmpty() ? '合同数据不存在' : true;
}
}

View File

@ -104,6 +104,12 @@
return $arr[$data['review_status']];
}
public function getRefluxStatusTextAttr($value, $data): string
{
$arr = [0 => '未回流', 1 => '已回流'];
return $arr[$data['reflux_status']];
}
public function getStartDateAttr($value): string
{

View File

@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\marketing;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 市场经营--合同信息模型
* Class MarketingContract
* @package app\common\model\marketing
*/
class MarketingContractReflux extends BaseModel
{
use SoftDelete;
protected $name = 'marketing_contract_reflux';
protected $deleteTime = 'delete_time';
public function getRefluxDateAttr($value): string
{
return !empty($value) ? date('Y-m-d', $value) : '';
}
}