Api.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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\api\BaseController;
  16. use app\finance\model\Loan;
  17. use app\finance\model\Expense;
  18. use app\finance\model\Invoice;
  19. use app\finance\model\InvoiceIncome;
  20. use app\finance\model\Ticket;
  21. use app\finance\model\TicketPayment;
  22. use think\facade\Db;
  23. use think\facade\View;
  24. class Api extends BaseController
  25. {
  26. //获取获取借支
  27. public function get_loan()
  28. {
  29. $param = get_params();
  30. $where = array();
  31. $where[] = ['delete_time', '=', 0];
  32. $where[] = ['admin_id', '=', $this->uid];
  33. $where[] = ['balance_status', '<', 2];
  34. $where[] = ['pay_status', '=', 1];
  35. $where[] = ['check_status', '=', 2];
  36. $where[] = ['back_status', '=', 0];
  37. /*
  38. if(!empty($param['project_id'])){
  39. $where[] = ['project_id', '=', $param['project_id']];
  40. }
  41. else{
  42. $where[] = ['project_id', '=', 0];
  43. }
  44. */
  45. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  46. $list = Db::name('Loan')->where($where)
  47. ->paginate(['list_rows'=> $rows])
  48. ->each(function ($item, $key) {
  49. $item['create_time'] = to_date($item['create_time'],'Y-m-d');
  50. $item['pay_time'] = to_date($item['pay_time'],'Y-m-d');
  51. $item['un_balance_cost'] = ($item['cost']*100 - $item['balance_cost']*100)/100;
  52. if($item['balance_status']==0){
  53. $item['balance_name']='待冲抵';
  54. }
  55. if($item['balance_status']==1){
  56. $item['balance_name']='部分冲抵';
  57. }
  58. return $item;
  59. });
  60. return table_assign(0, '', $list);
  61. }
  62. //删除报销项
  63. public function del_expense_interfix()
  64. {
  65. $id = get_params("id");
  66. $admin_id = Db::name('ExpenseInterfix')->where('id', $id)->value('admin_id');
  67. if ($admin_id == $this->uid) {
  68. if (Db::name('ExpenseInterfix')->where('id', $id)->delete() !== false) {
  69. return to_assign(0, "删除成功");
  70. } else {
  71. return to_assign(1, "删除失败");
  72. }
  73. } else {
  74. return to_assign(1, "您不是申请人,没权限删除该报销数据");
  75. }
  76. }
  77. //报销设置为已打款
  78. public function topay()
  79. {
  80. $param = get_params();
  81. if (request()->isAjax()) {
  82. $auth = isAuthExpense($this->uid);
  83. if($auth == 0){
  84. return to_assign(1, "你没有打款权限,请联系管理员或者HR");
  85. }
  86. //打款,数据操作
  87. $param['pay_status'] = 1;
  88. $param['pay_admin_id'] = $this->uid;
  89. $param['pay_time'] = time();
  90. $res = Expense::where('id', $param['id'])->strict(false)->field(true)->update($param);
  91. if ($res !== false) {
  92. add_log('topay', $param['id'],$param,'报销');
  93. //发送消息通知
  94. $detail = Expense::where(['id' => $param['id']])->find();
  95. $msg=[
  96. 'from_uid'=>$this->uid,//发送人
  97. 'to_uids'=>$detail['admin_id'],//接收人
  98. 'template_id'=>'expense_pay',//消息模板标识
  99. 'content'=>[ //消息内容
  100. 'create_time'=>date('Y-m-d H:i:s'),
  101. 'action_id'=>$detail['id'],
  102. 'title' => '报销'
  103. ]
  104. ];
  105. event('SendMessage',$msg);
  106. return to_assign();
  107. } else {
  108. return to_assign(1, "操作失败");
  109. }
  110. }
  111. }
  112. //借支设置为已打款
  113. public function topay2()
  114. {
  115. $param = get_params();
  116. if (request()->isAjax()) {
  117. $auth = isAuthExpense($this->uid);
  118. if($auth == 0){
  119. return to_assign(1, "你没有打款权限,请联系管理员或者HR");
  120. }
  121. //打款,数据操作
  122. $param['pay_status'] = 1;
  123. $param['pay_admin_id'] = $this->uid;
  124. $param['pay_time'] = time();
  125. $res = Loan::where('id', $param['id'])->strict(false)->field(true)->update($param);
  126. if ($res !== false) {
  127. add_log('topay', $param['id'],$param,'借支');
  128. //发送消息通知
  129. $detail = Loan::where(['id' => $param['id']])->find();
  130. $msg=[
  131. 'from_uid'=>$this->uid,//发送人
  132. 'to_uids'=>$detail['admin_id'],//接收人
  133. 'template_id'=>'loan_pay',//消息模板标识
  134. 'content'=>[ //消息内容
  135. 'create_time'=>date('Y-m-d H:i:s'),
  136. 'action_id'=>$detail['id'],
  137. 'title' => '借支'
  138. ]
  139. ];
  140. event('SendMessage',$msg);
  141. return to_assign();
  142. } else {
  143. return to_assign(1, "操作失败");
  144. }
  145. }
  146. }
  147. //借支设置为已归还
  148. public function topay3()
  149. {
  150. $param = get_params();
  151. if (request()->isAjax()) {
  152. $auth = isAuthExpense($this->uid);
  153. if($auth == 0){
  154. return to_assign(1, "你没有操作权限,请联系管理员或者HR");
  155. }
  156. //打款,数据操作
  157. $param['back_status'] = 1;
  158. $param['back_admin_id'] = $this->uid;
  159. $param['back_time'] = time();
  160. $res = Loan::where('id', $param['id'])->strict(false)->field(true)->update($param);
  161. if ($res !== false) {
  162. add_log('toback', $param['id'],$param,'借支');
  163. //发送消息通知
  164. $detail = Loan::where(['id' => $param['id']])->find();
  165. $msg=[
  166. 'from_uid'=>$this->uid,//发送人
  167. 'to_uids'=>$detail['admin_id'],//接收人
  168. 'template_id'=>'loan_back',//消息模板标识
  169. 'content'=>[ //消息内容
  170. 'create_time'=>date('Y-m-d H:i:s'),
  171. 'action_id'=>$detail['id'],
  172. 'title' => '借支'
  173. ]
  174. ];
  175. event('SendMessage',$msg);
  176. return to_assign();
  177. } else {
  178. return to_assign(1, "操作失败");
  179. }
  180. }
  181. }
  182. //开具发票
  183. public function open()
  184. {
  185. $param = get_params();
  186. if (request()->isAjax()) {
  187. $auth = isAuthInvoice($this->uid);
  188. if($auth == 0){
  189. return to_assign(1, "你没有开票权限,请联系管理员或者HR");
  190. }
  191. $status = Invoice::where(['id' => $param['id']])->value('check_status');
  192. if ($status == 2) {
  193. $param['open_status'] = 1;
  194. $param['open_admin_id'] = $this->uid;
  195. }
  196. if(isset($param['open_time'])){
  197. $param['open_time'] = strtotime(urldecode($param['open_time']));
  198. }
  199. $res = Invoice::where('id', $param['id'])->strict(false)->field('code,open_status,open_time,open_admin_id,delivery')->update($param);
  200. if ($res !== false) {
  201. add_log('open', $param['id'],$param,'发票');
  202. return to_assign();
  203. } else {
  204. return to_assign(1, "操作失败");
  205. }
  206. }
  207. }
  208. //作废发票
  209. public function tovoid()
  210. {
  211. $param = get_params();
  212. if (request()->isAjax()) {
  213. $auth = isAuthInvoice($this->uid);
  214. if($auth == 0){
  215. return to_assign(1, "你没有作废发票权限,请联系管理员或者HR");
  216. }
  217. $count = InvoiceIncome::where(['invoice_id'=>$param['id'],'status'=>1])->count();
  218. if($count>0){
  219. return to_assign(1, "发票已经新增有回款记录,请先反回款后再作废发票");
  220. }
  221. else{
  222. $param['update_time'] = time();
  223. $param['open_status'] = 2;
  224. }
  225. $res = Invoice::where('id', $param['id'])->strict(false)->field('update_time,open_status')->update($param);
  226. if ($res !== false) {
  227. return to_assign();
  228. add_log('tovoid', $param['id'],$param,'发票');
  229. } else {
  230. return to_assign(1, "操作失败");
  231. }
  232. }
  233. }
  234. //反作废发票
  235. public function novoid()
  236. {
  237. $param = get_params();
  238. if (request()->isAjax()) {
  239. $auth = isAuthInvoice($this->uid);
  240. if($auth == 0){
  241. return to_assign(1, "你没有反作废发票权限,请联系管理员或者HR");
  242. }
  243. $param['open_status'] = 1;
  244. $param['update_time'] = time();
  245. $res = Invoice::where('id', $param['id'])->strict(false)->field('update_time,open_status')->update($param);
  246. if ($res !== false) {
  247. return to_assign();
  248. add_log('novoid', $param['id'],$param,'发票');
  249. } else {
  250. return to_assign(1, "操作失败");
  251. }
  252. }
  253. }
  254. //上传电子发票
  255. public function upload_invoice()
  256. {
  257. $param = get_params();
  258. if (request()->isAjax()) {
  259. $auth = isAuthInvoice($this->uid);
  260. if($auth == 0){
  261. return to_assign(1, "你没有开票权限,请联系管理员或者HR");
  262. }
  263. $param['update_time'] = time();
  264. $res = Invoice::where('id', $param['id'])->strict(false)->field('update_time,other_file_ids')->update($param);
  265. if ($res !== false) {
  266. return to_assign();
  267. } else {
  268. return to_assign(1, "操作失败");
  269. }
  270. }
  271. }
  272. //作废收票
  273. public function tovoid_ticket()
  274. {
  275. $param = get_params();
  276. if (request()->isAjax()) {
  277. $auth = isAuthInvoice($this->uid);
  278. if($auth == 0){
  279. return to_assign(1, "你没有作废发票权限,请联系管理员或者HR");
  280. }
  281. $count = TicketPayment::where(['ticket_id'=>$param['id'],'status'=>1])->count();
  282. if($count>0){
  283. return to_assign(1, "发票已经新增有付款记录,请先反付款后再作废发票");
  284. }
  285. else{
  286. $param['update_time'] = time();
  287. $param['open_status'] = 2;
  288. }
  289. $res = Ticket::where('id', $param['id'])->strict(false)->field('update_time,open_status')->update($param);
  290. if ($res !== false) {
  291. return to_assign();
  292. add_log('tovoid', $param['id'],$param,'发票');
  293. } else {
  294. return to_assign(1, "操作失败");
  295. }
  296. }
  297. }
  298. //反作废收票
  299. public function novoid_ticket()
  300. {
  301. $param = get_params();
  302. if (request()->isAjax()) {
  303. $auth = isAuthInvoice($this->uid);
  304. if($auth == 0){
  305. return to_assign(1, "你没有反作废发票权限,请联系管理员或者HR");
  306. }
  307. $param['open_status'] = 1;
  308. $param['update_time'] = time();
  309. $res = Ticket::where('id', $param['id'])->strict(false)->field('update_time,open_status')->update($param);
  310. if ($res !== false) {
  311. return to_assign();
  312. add_log('novoid', $param['id'],$param,'发票');
  313. } else {
  314. return to_assign(1, "操作失败");
  315. }
  316. }
  317. }
  318. //上传
  319. public function upload_ticket()
  320. {
  321. $param = get_params();
  322. if (request()->isAjax()) {
  323. $auth = isAuthInvoice($this->uid);
  324. if($auth == 0){
  325. return to_assign(1, "你没有发票权限,请联系管理员或者HR");
  326. }
  327. $param['update_time'] = time();
  328. $res = Ticket::where('id', $param['id'])->strict(false)->field('update_time,other_file_ids')->update($param);
  329. if ($res !== false) {
  330. return to_assign();
  331. } else {
  332. return to_assign(1, "操作失败");
  333. }
  334. }
  335. }
  336. }