| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- <?php
- /**
- +-----------------------------------------------------------------------------------------------
- * GouGuOPEN [ 左手研发,右手开源,未来可期!]
- +-----------------------------------------------------------------------------------------------
- * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
- +-----------------------------------------------------------------------------------------------
- * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
- +-----------------------------------------------------------------------------------------------
- * @Author 勾股工作室 <hdm58@qq.com>
- +-----------------------------------------------------------------------------------------------
- */
- declare (strict_types = 1);
- namespace app\contract\controller;
- use app\api\BaseController;
- use app\contract\model\Contract;
- use app\contract\model\Purchase;
- use app\contract\model\SupplierContact;
- use think\facade\Db;
- use think\facade\View;
- class Api extends BaseController
- {
- //获取销售合同协议
- public function get_contract()
- {
- $param = get_params();
- $uid = $this->uid;
- $where = array();
- $whereOr = array();
- if (!empty($param['keywords'])) {
- $where[] = ['id|name|code', 'like', '%' . $param['keywords'] . '%'];
- }
- $where[] = ['delete_time', '=', 0];
- $where[] = ['check_status', '=', 2];
- //是否是合同管理员
- $auth = isAuth($uid,'contract_admin','conf_1');
- if($auth == 0){
- $whereOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid];
- $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
- $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
- $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
- $dids_a = get_leader_departments($uid);
- $dids_b = get_role_departments($uid);
- $dids = array_merge($dids_a, $dids_b);
- if(!empty($dids)){
- $whereOr[] = ['did','in',$dids];
- }
- }
- $model = new Contract();
- $list = $model->datalist($param,$where,$whereOr);
- return table_assign(0, '', $list);
- }
- //销售合同归档操作
- public function contract_archive()
- {
- if (request()->isPost()) {
- $param = get_params();
- $tips='操作成功,合同已转入到归档合同列表';
- if($param['archive_status'] == 1){
- $param['archive_uid'] = $this->uid;
- $param['archive_time'] = time();
- }
- else{
- $param['archive_uid'] = 0;
- $param['archive_time'] = 0;
- $tips='操作成功,合同已从归档合同列表转出';
- }
- if (Db::name('Contract')->strict(false)->update($param) !== false) {
- return to_assign(0, $tips);
- } else {
- return to_assign(1, "操作失败");
- }
- } else {
- return to_assign(1, "错误的请求");
- }
- }
-
- //销售合同中止等操作
- public function contract_stop()
- {
- if (request()->isPost()) {
- $param = get_params();
- $tips='操作成功,合同已转入到中止合同列表';
- if($param['stop_status'] == 1){
- $param['stop_uid'] = $this->uid;
- $param['stop_time'] = time();
- }
- else{
- $param['stop_uid'] = 0;
- $param['stop_time'] = 0;
- $tips='操作成功,合同已从中止合同列表转出';
- }
- if (Db::name('Contract')->strict(false)->update($param) !== false) {
- return to_assign(0, $tips);
- } else {
- return to_assign(1, "操作失败");
- }
- } else {
- return to_assign(1, "错误的请求");
- }
- }
- //销售合同作废等操作
- public function contract_tovoid()
- {
- if (request()->isPost()) {
- $param = get_params();
- $tips='操作成功,合同已转入到作废合同列表';
- if($param['void_status'] == 1){
- $param['void_uid'] = $this->uid;
- $param['void_time'] = time();
- }
- else{
- $param['void_uid'] = 0;
- $param['void_time'] = 0;
- $tips='操作成功,合同已从作废合同列表转出';
- }
- if (Db::name('Contract')->strict(false)->update($param) !== false) {
- return to_assign(0, $tips);
- } else {
- return to_assign(1, "操作失败");
- }
- } else {
- return to_assign(1, "错误的请求");
- }
- }
-
- //获取产品分类数据
- public function get_productcate_tree()
- {
- $cate = get_base_data('ProductCate');
- $list = get_tree($cate, 0, 2);
- $data['trees'] = $list;
- return json($data);
- }
-
- //获取销售产品列表
- public function get_product()
- {
- $param = get_params();
- $where = array();
- if (!empty($param['keywords'])) {
- $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
- }
- $where[] = ['delete_time', '=', 0];
- $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
- $list = Db::name('Product')->field('id,title,sale_price,purchase_price,base_price,unit,specs')->order('id asc')->where($where)->paginate(['list_rows'=> $rows]);
- table_assign(0, '', $list);
- }
-
- //更新合同电子文件
- public function contract_seal_ids()
- {
- if (request()->isPost()) {
- $param = get_params();
- if (Db::name('Contract')->strict(false)->update($param) !== false) {
- return to_assign();
- } else {
- return to_assign(1, "操作失败");
- }
- } else {
- return to_assign(1, "错误的请求");
- }
- }
-
-
-
- /*
- -------------------------------------------------分割线---------------------------------------------------------
- */
- //获取采购合同协议
- public function get_purchase()
- {
- $param = get_params();
- $uid = $this->uid;
- $where = array();
- $whereOr = array();
- if (!empty($param['keywords'])) {
- $where[] = ['id|name|code', 'like', '%' . $param['keywords'] . '%'];
- }
- $where[] = ['delete_time', '=', 0];
- $where[] = ['check_status', '=', 2];
- $auth = isAuth($uid,'contract_admin','conf_1');
- if($auth == 0){
- $whereOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid];
- $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
- $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
- $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
- $dids_a = get_leader_departments($uid);
- $dids_b = get_role_departments($uid);
- $dids = array_merge($dids_a, $dids_b);
- if(!empty($dids)){
- $whereOr[] = ['did','in',$dids];
- }
- }
- $model = new Purchase();
- $list = $model->datalist($param,$where,$whereOr);
- return table_assign(0, '', $list);
- }
- //采购合同归档操作
- public function purchase_archive()
- {
- if (request()->isPost()) {
- $param = get_params();
- $tips='操作成功,合同已转入到归档合同列表';
- if($param['archive_status'] == 1){
- $param['archive_uid'] = $this->uid;
- $param['archive_time'] = time();
- }
- else{
- $param['archive_uid'] = 0;
- $param['archive_time'] = 0;
- $tips='操作成功,合同已从归档合同列表转出';
- }
- if (Db::name('Purchase')->strict(false)->update($param) !== false) {
- return to_assign(0, $tips);
- } else {
- return to_assign(1, "操作失败");
- }
- } else {
- return to_assign(1, "错误的请求");
- }
- }
-
- //采购合同中止等操作
- public function purchase_stop()
- {
- if (request()->isPost()) {
- $param = get_params();
- $tips='操作成功,合同已转入到中止合同列表';
- if($param['stop_status'] == 1){
- $param['stop_uid'] = $this->uid;
- $param['stop_time'] = time();
- }
- else{
- $param['stop_uid'] = 0;
- $param['stop_time'] = 0;
- $tips='操作成功,合同已从中止合同列表转出';
- }
- if (Db::name('Purchase')->strict(false)->update($param) !== false) {
- return to_assign(0, $tips);
- } else {
- return to_assign(1, "操作失败");
- }
- } else {
- return to_assign(1, "错误的请求");
- }
- }
- //采购合同作废等操作
- public function purchase_tovoid()
- {
- if (request()->isPost()) {
- $param = get_params();
- $tips='操作成功,合同已转入到作废合同列表';
- if($param['void_status'] == 1){
- $param['void_uid'] = $this->uid;
- $param['void_time'] = time();
- }
- else{
- $param['void_uid'] = 0;
- $param['void_time'] = 0;
- $tips='操作成功,合同已从作废合同列表转出';
- }
- if (Db::name('Purchase')->strict(false)->update($param) !== false) {
- return to_assign(0, $tips);
- } else {
- return to_assign(1, "操作失败");
- }
- } else {
- return to_assign(1, "错误的请求");
- }
- }
-
- //获取采购品分类数据
- public function get_purchasedcate_tree()
- {
- $cate = get_base_data('PurchasedCate');
- $list = get_tree($cate, 0, 2);
- $data['trees'] = $list;
- return json($data);
- }
-
- //获取供应商列表
- public function get_supplier()
- {
- $param = get_params();
- $where = array();
- if (!empty($param['keywords'])) {
- $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
- }
- $where[] = ['delete_time', '=', 0];
- $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
- $list = Db::name('Supplier')->field('id,title,address')->order('id asc')->where($where)->paginate(['list_rows'=> $rows])->each(function($item, $key){
- $contact = Db::name('SupplierContact')->where(['sid'=>$item['id'],'is_default'=>1])->find();
- if(!empty($contact)){
- $item['contact_name'] = $contact['name'];
- $item['contact_mobile'] = $contact['mobile'];
- }
- else{
- $item['contact_name'] = '';
- $item['contact_mobile'] = '';
- }
- return $item;
- });
- table_assign(0, '', $list);
- }
-
- //获取采购物品列表
- public function get_purchased()
- {
- $param = get_params();
- $where = array();
- if (!empty($param['keywords'])) {
- $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
- }
- $where[] = ['delete_time', '=', 0];
- $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
- $list = Db::name('Purchased')->field('id,title,purchase_price,sale_price,unit,specs')->order('id asc')->where($where)->paginate(['list_rows'=> $rows]);
- table_assign(0, '', $list);
- }
-
- //获取供应商联系人数据
- public function get_supplier_contact()
- {
- $param = get_params();
- $where = array();
- $where[] = ['delete_time', '=', 0];
- $where[] = ['sid', '=', $param['supplier_id']];
- $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
- $content = SupplierContact::where($where)
- ->order('create_time desc')
- ->paginate(['list_rows'=> $rows])
- ->each(function ($item, $key) {
- $item->admin_name = Db::name('Admin')->where(['id' => $item->admin_id])->value('name');
- $item->create_time = date('Y-m-d H:i:s', (int) $item->create_time);
- });
- return table_assign(0, '', $content);
- }
-
- //设置供应商联系人
- public function set_supplier_contact()
- {
- if (request()->isAjax()) {
- $param = get_params();
- $detail= SupplierContact::where(['id' => $param['id']])->find();
- SupplierContact::where(['sid' => $detail['sid']])->strict(false)->field(true)->update(['is_default'=>0]);
- $res = SupplierContact::where(['id' => $param['id']])->update(['is_default'=>1]);
- if ($res) {
- add_log('edit', $param['id'], $param,'供应商联系人');
- return to_assign();
- } else {
- return to_assign(1, '操作失败');
- }
- } else {
- return to_assign(1, '参数错误');
- }
- }
-
- //更新合同电子文件
- public function purchase_seal_ids()
- {
- if (request()->isPost()) {
- $param = get_params();
- if (Db::name('Purchase')->strict(false)->update($param) !== false) {
- return to_assign();
- } else {
- return to_assign(1, "操作失败");
- }
- } else {
- return to_assign(1, "错误的请求");
- }
- }
- }
|