Ticket.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\finance\controller;
  15. use app\base\BaseController;
  16. use app\finance\model\Ticket as TicketModel;
  17. use app\finance\validate\TicketValidate;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Ticket extends BaseController
  22. {
  23. /**
  24. * 构造函数
  25. */
  26. protected $model;
  27. public function __construct()
  28. {
  29. parent::__construct(); // 调用父类构造函数
  30. $this->model = new TicketModel();
  31. }
  32. /**
  33. * 数据列表
  34. */
  35. public function datalist()
  36. {
  37. $param = get_params();
  38. if (request()->isAjax()) {
  39. $tab = isset($param['tab']) ? $param['tab'] : 0;
  40. $uid=$this->uid;
  41. $where = array();
  42. $whereOr = array();
  43. $where[]=['delete_time','=',0];
  44. $where[]=['invoice_type','>',0];
  45. if($tab == 0){
  46. $auth = isAuthInvoice($uid);
  47. if($auth == 0){
  48. $whereOr[] = ['admin_id', '=', $this->uid];
  49. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  50. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  51. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  52. $dids_a = get_leader_departments($uid);
  53. $dids_b = get_role_departments($uid);
  54. $dids = array_merge($dids_a, $dids_b);
  55. if(!empty($dids)){
  56. $whereOr[] = ['did','in',$dids];
  57. }
  58. }
  59. }
  60. if($tab == 1){
  61. //我创建的
  62. $where[] = ['admin_id', '=', $this->uid];
  63. }
  64. if($tab == 2){
  65. //待我审核的
  66. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  67. }
  68. if($tab == 3){
  69. //我已审核的
  70. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  71. }
  72. if($tab == 4){
  73. //抄送给我的
  74. $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  75. }
  76. //按时间检索
  77. if (!empty($param['diff_time'])) {
  78. $diff_time =explode('~', $param['diff_time']);
  79. $where[] = ['open_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
  80. }
  81. if (isset($param['open_status']) && $param['open_status'] != "") {
  82. $where[] = ['open_status', '=', $param['open_status']];
  83. }
  84. if (isset($param['pay_status']) && $param['pay_status'] != "") {
  85. $where[] = ['pay_status', '=', $param['pay_status']];
  86. }
  87. if (isset($param['check_status']) && $param['check_status'] != "") {
  88. $where[] = ['check_status', '=', $param['check_status']];
  89. }
  90. $list = $this->model->datalist($param,$where,$whereOr);
  91. return table_assign(0, '', $list);
  92. }
  93. else{
  94. return view();
  95. }
  96. }
  97. /**
  98. * 添加/编辑
  99. */
  100. public function add()
  101. {
  102. $param = get_params();
  103. if (request()->isAjax()) {
  104. $param['admin_id'] = $this->uid;
  105. $param['did'] = $this->did;
  106. if (!empty($param['open_time'])) {
  107. $param['open_time'] = strtotime(urldecode($param['open_time']));
  108. }
  109. if (!empty($param['id']) && $param['id'] > 0) {
  110. try {
  111. validate(TicketValidate::class)->scene('edit')->check($param);
  112. } catch (ValidateException $e) {
  113. // 验证失败 输出错误信息
  114. return to_assign(1, $e->getError());
  115. }
  116. $this->model->edit($param);
  117. } else {
  118. try {
  119. validate(TicketValidate::class)->scene('add')->check($param);
  120. } catch (ValidateException $e) {
  121. // 验证失败 输出错误信息
  122. return to_assign(1, $e->getError());
  123. }
  124. $this->model->add($param);
  125. }
  126. }else{
  127. $id = isset($param['id']) ? $param['id'] : 0;
  128. if ($id>0) {
  129. $detail = $this->model->getById($id);
  130. View::assign('detail', $detail);
  131. if(is_mobile()){
  132. return view('qiye@/finance/add_ticket');
  133. }
  134. return view('edit');
  135. }
  136. if(is_mobile()){
  137. return view('qiye@/finance/add_ticket');
  138. }
  139. return view();
  140. }
  141. }
  142. /**
  143. * 查看
  144. */
  145. public function view($id)
  146. {
  147. $detail = $this->model->getById($id);
  148. if (!empty($detail)) {
  149. View::assign('detail', $detail);
  150. View::assign('create_user', get_admin($detail['admin_id']));
  151. if(is_mobile()){
  152. return view('qiye@/finance/view_ticket');
  153. }
  154. return view();
  155. }
  156. else{
  157. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  158. }
  159. }
  160. /**
  161. * 删除
  162. */
  163. public function del()
  164. {
  165. $param = get_params();
  166. $id = isset($param['id']) ? $param['id'] : 0;
  167. if (request()->isDelete()) {
  168. $this->model->delById($id);
  169. } else {
  170. return to_assign(1, "错误的请求");
  171. }
  172. }
  173. //收票记录
  174. public function record()
  175. {
  176. $uid = $this->uid;
  177. $auth = isAuthInvoice($uid);
  178. if (request()->isAjax()) {
  179. $param = get_params();
  180. $tab = isset($param['tab']) ? $param['tab'] : 0;
  181. $where = [];
  182. $where[]=['delete_time','=',0];
  183. $where[]=['check_status','=',2];
  184. $where[]=['invoice_type','>',0];
  185. if($auth == 0){
  186. $dids_a = get_leader_departments($uid);
  187. $dids_b = get_role_departments($uid);
  188. $dids = array_merge($dids_a, $dids_b);
  189. if(!empty($dids)){
  190. $whereOr[] = ['did','in',$dids];
  191. }
  192. }
  193. if($tab == 0){
  194. //正常的
  195. $where[] = ['open_status', '<', 2];
  196. }
  197. if($tab == 1){
  198. //已作废的
  199. $where[] = ['open_status', '=', 2];
  200. }
  201. //按时间检索
  202. if (!empty($param['diff_time'])) {
  203. $diff_time =explode('~', $param['diff_time']);
  204. $where[] = ['open_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
  205. }
  206. if (isset($param['open_status']) && $param['open_status'] != "") {
  207. $where[] = ['open_status', '=', $param['open_status']];
  208. }
  209. $list = $this->model->datalist($param,$where);
  210. $amount = $this->model::where($where)->sum('amount');
  211. $totalRow['amount'] = sprintf("%.2f",$amount);
  212. return table_assign(0, '', $list);
  213. } else {
  214. View::assign('authInvoice',$auth);
  215. return view();
  216. }
  217. }
  218. /**
  219. * 无发票付款列表
  220. */
  221. public function datalist_a()
  222. {
  223. $param = get_params();
  224. if (request()->isAjax()) {
  225. $uid=$this->uid;
  226. $where = array();
  227. $whereOr = array();
  228. $where[]=['delete_time','=',0];
  229. $where[]=['invoice_type','=',0];
  230. $whereOr[] = ['admin_id', '=', $this->uid];
  231. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  232. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  233. $whereOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_copy_uids)")];
  234. //按时间检索
  235. if (!empty($param['diff_time'])) {
  236. $diff_time =explode('~', $param['diff_time']);
  237. $where[] = ['pay_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1].' 23:59:59'))]];
  238. }
  239. if (isset($param['pay_status']) && $param['pay_status'] != "") {
  240. $where[] = ['pay_status', '=', $param['pay_status']];
  241. }
  242. if (isset($param['check_status']) && $param['check_status'] != "") {
  243. $where[] = ['check_status', '=', $param['check_status']];
  244. }
  245. $list = $this->model->datalist($param,$where,$whereOr);
  246. return table_assign(0, '', $list);
  247. }
  248. else{
  249. View::assign('auth', isAuthPayment($this->uid));
  250. return view();
  251. }
  252. }
  253. /**
  254. * 无发票付款添加/编辑
  255. */
  256. public function add_a()
  257. {
  258. $param = get_params();
  259. if (request()->isAjax()) {
  260. $param['admin_id'] = $this->uid;
  261. $param['did'] = $this->did;
  262. if (!empty($param['open_time'])) {
  263. $param['open_time'] = strtotime(urldecode($param['open_time']));
  264. }
  265. if (!empty($param['id']) && $param['id'] > 0) {
  266. try {
  267. validate(TicketValidate::class)->scene('edit')->check($param);
  268. } catch (ValidateException $e) {
  269. // 验证失败 输出错误信息
  270. return to_assign(1, $e->getError());
  271. }
  272. $this->model->edit($param);
  273. } else {
  274. try {
  275. validate(TicketValidate::class)->scene('add')->check($param);
  276. } catch (ValidateException $e) {
  277. // 验证失败 输出错误信息
  278. return to_assign(1, $e->getError());
  279. }
  280. $this->model->add($param);
  281. }
  282. }else{
  283. $id = isset($param['id']) ? $param['id'] : 0;
  284. if ($id>0) {
  285. $detail = $this->model->getById($id);
  286. View::assign('detail', $detail);
  287. if(is_mobile()){
  288. return view('qiye@/finance/add_ticket_a');
  289. }
  290. return view('edit_a');
  291. }
  292. if(is_mobile()){
  293. return view('qiye@/finance/add_ticket_a');
  294. }
  295. return view();
  296. }
  297. }
  298. /**
  299. * 无发票付款查看
  300. */
  301. public function view_a($id)
  302. {
  303. $detail = $this->model->getById($id);
  304. if (!empty($detail)) {
  305. $detail['subject'] = Db::name('Enterprise')->where(['id' =>$detail['invoice_subject']])->value('title');
  306. $other_file_array = Db::name('File')->where('id','in',$detail['other_file_ids'])->select();
  307. $detail['other_file_array'] = $other_file_array;
  308. View::assign('detail', $detail);
  309. View::assign('create_user', get_admin($detail['admin_id']));
  310. if(is_mobile()){
  311. return view('qiye@/finance/view_ticket_a');
  312. }
  313. return view();
  314. }
  315. else{
  316. return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
  317. }
  318. }
  319. /**
  320. * 无发票付款删除
  321. */
  322. public function del_a()
  323. {
  324. $param = get_params();
  325. if (request()->isDelete()) {
  326. $this->model->delById($param['id']);
  327. } else {
  328. return to_assign(1, "错误的请求");
  329. }
  330. }
  331. }