| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- <?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\base\BaseController;
- use app\contract\model\Purchase as PurchaseModel;
- use app\contract\validate\PurchaseValidate;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\View;
- class Purchase extends BaseController
- {
- /**
- * 构造函数
- */
- protected $model;
- public function __construct()
- {
- parent::__construct(); // 调用父类构造函数
- $this->model = new PurchaseModel();
- }
-
- /**
- * 数据列表
- */
- public function datalist()
- {
- $param = get_params();
- if (request()->isAjax()) {
- $tab = isset($param['tab']) ? $param['tab'] : 0;
- $uid = $this->uid;
- $where = [];
- $whereOr = [];
- $where[]=['delete_time','=',0];
- $where[]=['archive_time','=',0];
- $where[]=['stop_time','=',0];
- $where[]=['void_time','=',0];
- if (!empty($param['keywords'])) {
- $where[] = ['id|name|code', 'like', '%' . $param['keywords'] . '%'];
- }
- if (!empty($param['types'])) {
- $where[] = ['types', '=',$param['types']];
- }
- if (!empty($param['cate_id'])) {
- $where[] = ['cate_id', '=',$param['cate_id']];
- }
- if (isset($param['check_status']) && $param['check_status']!='') {
- $where[] = ['check_status', '=',$param['check_status']];
- }
- if (!empty($param['sign_time'])) {
- $sign_time =explode('~', $param['sign_time']);
- $where[] = ['sign_time', 'between',[strtotime(urldecode($sign_time[0])),strtotime(urldecode($sign_time[1].' 23:59:59'))]];
- }
- if (!empty($param['end_time'])) {
- $end_time =explode('~', $param['end_time']);
- $where[] = ['end_time', 'between',[strtotime(urldecode($end_time[0])),strtotime(urldecode($end_time[1].' 23:59:59'))]];
- }
- if($tab == 0){
- if (!empty($param['uid'])) {
- $where[] = ['sign_uid', '=', $param['uid']];
- }
- else{
- //是否是合同管理员
- $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];
- }
- }
- }
- }
- if($tab == 1){
- $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
- }
- if($tab == 2){
- $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
- }
- $list = $this->model->datalist($param,$where,$whereOr);
- return table_assign(0, '', $list);
- }
- else{
- View::assign('is_leader', isLeader($this->uid));
- View::assign('is_auth', isAuth($this->uid,'contract_admin','conf_1'));
- View::assign('delay_num', valueAuth('contract_admin','conf_10'));
- return view();
- }
- }
-
- public function archivelist()
- {
- $param = get_params();
- if (request()->isAjax()) {
- $uid = $this->uid;
- $where = [];
- $whereOr = [];
- $where[]=['delete_time','=',0];
- $where[]=['archive_time','>',0];
- if (!empty($param['keywords'])) {
- $where[] = ['id|name|code', 'like', '%' . $param['keywords'] . '%'];
- }
- if (!empty($param['types'])) {
- $where[] = ['types', '=',$param['types']];
- }
- if (!empty($param['cate_id'])) {
- $where[] = ['cate_id', '=',$param['cate_id']];
- }
- if (!empty($param['sign_time'])) {
- $sign_time =explode('~', $param['sign_time']);
- $where[] = ['sign_time', 'between',[strtotime(urldecode($sign_time[0])),strtotime(urldecode($sign_time[1].' 23:59:59'))]];
- }
- if (!empty($param['end_time'])) {
- $end_time =explode('~', $param['end_time']);
- $where[] = ['end_time', 'between',[strtotime(urldecode($end_time[0])),strtotime(urldecode($end_time[1].' 23:59:59'))]];
- }
- //是否是合同管理员
- $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];
- }
- }
- $list = $this->model->datalist($param,$where,$whereOr);
- return table_assign(0, '', $list);
- }
- else{
- View::assign('delay_num', valueAuth('contract_admin','conf_10'));
- return view();
- }
- }
-
- public function stoplist()
- {
- $param = get_params();
- if (request()->isAjax()) {
- $uid = $this->uid;
- $where = [];
- $whereOr = [];
- $where[]=['delete_time','=',0];
- $where[]=['stop_time','>',0];
- if (!empty($param['keywords'])) {
- $where[] = ['id|name|code', 'like', '%' . $param['keywords'] . '%'];
- }
- if (!empty($param['types'])) {
- $where[] = ['types', '=',$param['types']];
- }
- if (!empty($param['cate_id'])) {
- $where[] = ['cate_id', '=',$param['cate_id']];
- }
- if (!empty($param['sign_time'])) {
- $sign_time =explode('~', $param['sign_time']);
- $where[] = ['sign_time', 'between',[strtotime(urldecode($sign_time[0])),strtotime(urldecode($sign_time[1].' 23:59:59'))]];
- }
- if (!empty($param['end_time'])) {
- $end_time =explode('~', $param['end_time']);
- $where[] = ['end_time', 'between',[strtotime(urldecode($end_time[0])),strtotime(urldecode($end_time[1].' 23:59:59'))]];
- }
- //是否是合同管理员
- $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];
- }
- }
- $list = $this->model->datalist($param,$where,$whereOr);
- return table_assign(0, '', $list);
- }
- else{
- return view();
- }
- }
-
- public function voidlist()
- {
- $param = get_params();
- if (request()->isAjax()) {
- $uid = $this->uid;
- $where = [];
- $whereOr = [];
- $where[]=['delete_time','=',0];
- $where[]=['void_time','>',0];
- if (!empty($param['keywords'])) {
- $where[] = ['id|name|code', 'like', '%' . $param['keywords'] . '%'];
- }
- if (!empty($param['types'])) {
- $where[] = ['types', '=',$param['types']];
- }
- if (!empty($param['cate_id'])) {
- $where[] = ['cate_id', '=',$param['cate_id']];
- }
- if (!empty($param['sign_time'])) {
- $sign_time =explode('~', $param['sign_time']);
- $where[] = ['sign_time', 'between',[strtotime(urldecode($sign_time[0])),strtotime(urldecode($sign_time[1].' 23:59:59'))]];
- }
- if (!empty($param['end_time'])) {
- $end_time =explode('~', $param['end_time']);
- $where[] = ['end_time', 'between',[strtotime(urldecode($end_time[0])),strtotime(urldecode($end_time[1].' 23:59:59'))]];
- }
- //是否是合同管理员
- $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];
- }
- }
- $list = $this->model->datalist($param,$where,$whereOr);
- return table_assign(0, '', $list);
- }
- else{
- return view();
- }
- }
-
- /**
- * 添加/编辑
- */
- public function add()
- {
- $param = get_params();
- if (request()->isAjax()) {
- if (isset($param['sign_time'])) {
- $param['sign_time'] = strtotime($param['sign_time']);
- }
- if (isset($param['start_time'])) {
- $param['start_time'] = strtotime($param['start_time']);
- }
- if (isset($param['end_time'])) {
- $param['end_time'] = strtotime($param['end_time']);
- if ($param['end_time'] <= $param['start_time']) {
- return to_assign(1, "结束时间需要大于开始时间");
- }
- }
- if($param['scene'] == 'add' || $param['scene'] == 'edit'){
- $param['content'] = serialize([]);
- if($param['types']==2){
- $purchased_title_data = isset($param['purchased_title']) ? $param['purchased_title'] : '';
- $purchased_id_data = isset($param['purchased_id']) ? $param['purchased_id'] : 0;
- $purchased_unit_data = isset($param['purchased_unit']) ? $param['purchased_unit'] : '';
- $purchased_specs_data = isset($param['purchased_specs']) ? $param['purchased_specs'] : '';
- $purchased_price_data = isset($param['purchased_price']) ? $param['purchased_price'] : '0.00';
- $purchased_num_data = isset($param['purchased_num']) ? $param['purchased_num'] : 1;
- $purchased_subtotal_data = isset($param['purchased_subtotal']) ? $param['purchased_subtotal'] : '0.00';
- $purchased_remark_data = isset($param['purchased_remark']) ? $param['purchased_remark'] : '';
- $purchased = [];
- if(!empty($purchased_title_data)){
- foreach ($purchased_title_data as $key => $value) {
- if (!$value) {
- continue;
- }
- $data = [];
- $data['purchased_title'] = $purchased_title_data[$key];
- $data['purchased_id'] = $purchased_id_data[$key];
- $data['purchased_unit'] = $purchased_unit_data[$key];
- $data['purchased_specs'] = $purchased_specs_data[$key];
- $data['purchased_price'] = $purchased_price_data[$key];
- $data['purchased_num'] = $purchased_num_data[$key];
- $data['purchased_subtotal'] = $purchased_subtotal_data[$key];
- $data['purchased_remark'] = $purchased_remark_data[$key];
- $purchased[]=$data;
- }
- }
- $param['content'] = serialize($purchased);
- }
- if($param['types']==3){
- $service_title_data = isset($param['service_title']) ? $param['service_title'] : '';
- $service_time_a_data = isset($param['service_time_a']) ? $param['service_time_a'] : '';
- $service_time_b_data = isset($param['service_time_b']) ? $param['service_time_b'] : '';
- $service_date_data = isset($param['service_date']) ? $param['service_date'] : '';
- $service_price_data = isset($param['service_price']) ? $param['service_price'] : '0.00';
- $service_num_data = isset($param['service_num']) ? $param['service_num'] : 1;
- $service_subtotal_data = isset($param['service_subtotal']) ? $param['service_subtotal'] : '0.00';
- $service_remark_data = isset($param['service_remark']) ? $param['service_remark'] : '';
- $service = [];
- if(!empty($service_title_data)){
- foreach ($service_title_data as $key => $value) {
- if (!$value) {
- continue;
- }
- $data = [];
- $data['service_title'] = $service_title_data[$key];
- if(!empty($service_time_a_data)){
- $data['service_date'] = $service_time_a_data[$key].'到'.$service_time_b_data[$key];
- }
- else{
- $data['service_date'] = $service_date_data[$key];
- }
- $data['service_price'] = $service_price_data[$key];
- $data['service_num'] = $service_num_data[$key];
- $data['service_subtotal'] = $service_subtotal_data[$key];
- $data['service_remark'] = $service_remark_data[$key];
- $service[]=$data;
- }
- }
- $param['content'] = serialize($service);
- }
- }
- if (!empty($param['id']) && $param['id'] > 0) {
- try {
- validate(PurchaseValidate::class)->scene($param['scene'])->check($param);
- } catch (ValidateException $e) {
- // 验证失败 输出错误信息
- return to_assign(1, $e->getError());
- }
- $this->model->edit($param);
- } else {
- try {
- validate(PurchaseValidate::class)->scene($param['scene'])->check($param);
- } catch (ValidateException $e) {
- // 验证失败 输出错误信息
- return to_assign(1, $e->getError());
- }
- $param['admin_id'] = $this->uid;
- $this->model->add($param);
- }
- }else{
- $id = isset($param['id']) ? $param['id'] : 0;
- $types = isset($param['types']) ? $param['types'] : 0;
- $is_supplier = Db::name('DataAuth')->where('name','contract_admin')->value('conf_6');
- $is_codeno = Db::name('DataAuth')->where('name','contract_admin')->value('conf_2');
- $is_purchased = Db::name('DataAuth')->where('name','contract_admin')->value('conf_7');
- View::assign('is_supplier', $is_supplier);
- View::assign('is_codeno', $is_codeno);
- View::assign('is_purchased', $is_purchased);
- if ($id>0) {
- $detail = $this->model->getById($id);
- if($detail['check_status'] == 1 || $detail['check_status'] == 2 || $detail['check_status'] == 3){
- return view(EEEOR_REPORTING,['code'=>403,'warning'=>'当前状态不支持编辑']);
- }
- if($detail['types'] > 1){
- $content_array = unserialize($detail['content']);
- if($detail['types']==3){
- foreach ($content_array as $key => &$value) {
- if(!empty($value['service_date'])){
- $service_date = explode('到', $value['service_date']);
- $value['service_time_a'] = $service_date[0];
- $value['service_time_b'] = $service_date[1];
- }
- }
- }
- $detail['content_array'] = $content_array;
- }
- View::assign('types', $detail['types']);
- View::assign('codeno', $detail['code']);
- View::assign('detail', $detail);
- if(is_mobile()){
- return view('qiye@/contract/purchase_add');
- }
- return view('edit');
- }
- $codeno='';
- if($is_codeno==1){
- $codeno = get_codeno(2);
- }
- View::assign('codeno', $codeno);
- View::assign('id', $id);
- View::assign('types', $types);
- if($types == 0){
- return view('add_types');
- }
- if(is_mobile()){
- return view('qiye@/contract/purchase_add');
- }
- return view();
- }
- }
-
- /**
- * 查看
- */
- public function view($id)
- {
- $detail = $this->model->getById($id);
- if (!empty($detail)) {
- if($detail['types'] > 1){
- $content_array = unserialize($detail['content']);
- if($detail['types']==3){
- foreach ($content_array as $key => &$value) {
- if(!empty($value['service_date'])){
- $service_date = explode('到', $value['service_date']);
- $value['service_time_a'] = $service_date[0];
- $value['service_time_b'] = $service_date[1];
- }
- }
- }
- $detail['content_array'] = $content_array;
- }
- $detail['status_name'] = check_status_name($detail['check_status']);
- $detail['cate_title'] = Db::name('ContractCate')->where(['id' => $detail['cate_id']])->value('title');
- $detail['subject_title'] = Db::name('Enterprise')->where(['id' => $detail['subject_id']])->value('title');
- //归档信息
- if($detail['archive_uid'] > 0){
- $detail['archive_name'] = Db::name('Admin')->where(['id' => $detail['archive_uid']])->value('name');
- }
- //中止信息
- if($detail['stop_uid'] > 0){
- $detail['stop_name'] = Db::name('Admin')->where(['id' => $detail['stop_uid']])->value('name');
- }
- //作废信息
- if($detail['void_uid'] > 0){
- $detail['void_name'] = Db::name('Admin')->where(['id' => $detail['void_uid']])->value('name');
- }
-
- //收票和付款信息
- if($detail['check_status'] == 2){
- $detail['ticket'] = Db::name('Ticket')->field('t.*,a.name as admin')
- ->alias('t')
- ->join('Admin a', 'a.id = t.admin_id', 'LEFT')
- ->where([['t.purchase_id','=',$id],['t.open_status','<',2],['t.invoice_type','>',0],['t.delete_time','=',0]])
- ->order('t.create_time desc')
- ->select();
-
- $has_ticket = Db::name('Ticket')->where([['purchase_id','=',$id],['open_status','<',2],['invoice_type','>',0],['delete_time','=',0]])->sum('amount');
- $detail['has_ticket'] = sprintf("%.2f",$has_ticket);
- $detail['no_ticket'] = sprintf("%.2f",($detail['cost']*100 - $has_ticket*100)/100);
-
-
- $ticket_ids = Db::name('Ticket')->where([['purchase_id','=',$id],['open_status','<',2],['delete_time','=',0]])->column('id');
- $detail['payment'] = Db::name('TicketPayment')->field('t.*,a.name as admin')
- ->alias('t')
- ->join('Admin a', 'a.id = t.admin_id', 'LEFT')
- ->where([['t.ticket_id','in',$ticket_ids],['t.status','=',1]])
- ->order('t.pay_time desc')
- ->select();
-
- $has_payment = Db::name('TicketPayment')->where([['ticket_id','in',$ticket_ids],['status','=',1]])->sum('amount');
- $detail['has_payment'] = sprintf("%.2f",$has_payment);
- $detail['no_payment'] = sprintf("%.2f",($detail['cost']*100 - $has_payment*100)/100);
- }
- if($detail['seal_ids'] !=''){
- $file_array = Db::name('File')->where('id','in',$detail['seal_ids'])->select()->toArray();
- $detail['seal_array'] = $file_array;
- }
- else{
- $detail['seal_array'] = [];
- }
- $auth = isAuth($this->uid,'contract_admin','conf_1');
- View::assign('detail', $detail);
- View::assign('auth', $auth);
- if(is_mobile()){
- return view('qiye@/contract/purchase_view');
- }
- return view();
- }
- else{
- return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
- }
- }
-
- /**
- * 删除
- */
- public function del()
- {
- $param = get_params();
- $id = isset($param['id']) ? $param['id'] : 0;
- if (request()->isDelete()) {
- $this->model->delById($id);
- } else {
- return to_assign(1, "错误的请求");
- }
- }
- }
|