98 lines
3.9 KiB
PHP
98 lines
3.9 KiB
PHP
<?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_code'])) {
|
||
$contract_ids2 = MarketingContract::where('contract_code', 'like', '%' . $params['contract_code'] . '%')->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)
|
||
->where('contract_type',0)
|
||
->page($page_no, $page_size)
|
||
->order('id desc')
|
||
->select()
|
||
->each(function ($data) {
|
||
$custom = MarketingCustom::field('name')->where('id', $data['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 = MarketingContract::where($where)->where('contract_type',0)->where('reflux_status', 0)->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::create([
|
||
'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());
|
||
}
|
||
}
|
||
|
||
} |