123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <?php
  2. /**
  3. * 发票控制器
  4. *
  5. * @author qifan
  6. * @date 2020-12-07
  7. */
  8. namespace app\crm\controller;
  9. use app\admin\controller\ApiCommon;
  10. use app\admin\model\Message;
  11. use app\admin\model\User;
  12. use app\crm\logic\InvoiceLogic;
  13. use app\crm\model\NumberSequence;
  14. use app\crm\traits\AutoNumberTrait;
  15. use think\Db;
  16. use think\Hook;
  17. use think\Request;
  18. class Invoice extends ApiCommon
  19. {
  20. use AutoNumberTrait;
  21. /**
  22. * 用于判断权限
  23. * @permission 无限制
  24. * @allow 登录用户可访问
  25. * @other 其他根据系统设置
  26. **/
  27. public function _initialize()
  28. {
  29. $action = [
  30. 'permission' => [],
  31. 'allow' => ['check', 'revokecheck', 'count', 'read']
  32. ];
  33. Hook::listen('check_auth',$action);
  34. $request = Request::instance();
  35. $a = strtolower($request->action());
  36. if (!in_array($a, $action['permission'])) {
  37. parent::_initialize();
  38. }
  39. }
  40. /**
  41. * 列表
  42. *
  43. * @param InvoiceLogic $invoiceLogic
  44. * @return \think\response\Json
  45. * @throws \think\exception\DbException
  46. */
  47. public function index(InvoiceLogic $invoiceLogic)
  48. {
  49. $param = $this->param;
  50. $param['user_id'] = $this->userInfo['id'];
  51. $data = $invoiceLogic->index($param, true);
  52. return resultArray(['data' => $data]);
  53. }
  54. /**
  55. * 创建
  56. *
  57. * @param InvoiceLogic $invoiceLogic
  58. * @return \think\response\Json
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. * @throws \think\exception\DbException
  62. */
  63. public function save(InvoiceLogic $invoiceLogic)
  64. {
  65. if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择客户!']);
  66. if (empty($this->param['contract_id'])) return resultArray(['error' => '请选择合同!']);
  67. if (empty($this->param['invoice_money'])) return resultArray(['error' => '请填写开票金额!']);
  68. if (empty($this->param['invoice_type'])) return resultArray(['error' => '请选择开票类型!']);
  69. if (empty($this->param['title_type'])) return resultArray(['error' => '请选择抬头类型!']);
  70. if (empty($this->param['examineStatus'])) return resultArray(['error' => '缺少审批状态!']);
  71. $param = $this->param;
  72. $userId = $this->userInfo['id'];
  73. # 审批是否停用
  74. $examineStatus = $param['examineStatus'];
  75. # 删除无用参数
  76. unset($param['examineStatus']);
  77. unset($param['customer_name']);
  78. unset($param['contract_money']);
  79. unset($param['contract_number']);
  80. # 设置创建人负责人ID
  81. $param['create_user_id'] = $userId;
  82. $param['owner_user_id'] = $userId;
  83. # 创建更新日期
  84. $param['create_time'] = time();
  85. $param['update_time'] = time();
  86. # 自动设置发票编号
  87. $numberInfo = [];
  88. if (empty($param['invoice_apple_number'])) {
  89. $numberInfo = $this->getAutoNumbers(4);
  90. if (empty($numberInfo['number'])) return resultArray(['error' => '请填写发票编号!']);
  91. $param['invoice_apple_number'] = $numberInfo['number'];
  92. }
  93. # 检查发票编号是否重复
  94. if ($invoiceLogic->getInvoiceId(['invoice_apple_number' => $param['invoice_apple_number']])) {
  95. return resultArray(['error' => '发票编号重复!']);
  96. }
  97. if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
  98. $examineStepModel = new \app\admin\model\ExamineStep();
  99. # 审核判断(是否有符合条件的审批流)
  100. $examineFlowModel = new \app\admin\model\ExamineFlow();
  101. if (!$examineFlowModel->checkExamine($userId, 'crm_invoice')) {
  102. return resultArray(['error' => '暂无审批人,无法创建']);
  103. }
  104. # 添加审批相关信息
  105. $examineFlowData = $examineFlowModel->getFlowByTypes($userId, 'crm_invoice');
  106. if (!$examineFlowData) {
  107. return resultArray(['error' => '无可用审批流,请联系管理员']);
  108. }
  109. $param['flow_id'] = $examineFlowData['flow_id'];
  110. # 获取审批人信息
  111. if ($examineFlowData['config'] == 1) {
  112. # 固定审批流
  113. $nextStepData = $examineStepModel->nextStepUser($userId, $examineFlowData['flow_id'], 'crm_invoice', 0, 0, 0);
  114. $next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : '';
  115. $check_user_id = $next_user_ids ? : [];
  116. $param['order_id'] = 1;
  117. } else {
  118. # 授权审批流
  119. $check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
  120. }
  121. if (!$check_user_id) {
  122. return resultArray(['error' => '无可用审批人,请联系管理员']);
  123. }
  124. $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
  125. } else {
  126. # 审批流停用,将状态改为审核通过
  127. $param['check_status'] = 2;
  128. }
  129. if (!$invoice_id = $invoiceLogic->save($param)) {
  130. return resultArray(['error' => '创建失败!']);
  131. }
  132. # 更新crm_number_sequence表中的last_date、create_time字段
  133. if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']);
  134. updateActionLog($param['create_user_id'], 'crm_invoice', $invoice_id, '', '', '创建了发票');
  135. return resultArray(['data' => '创建成功!']);
  136. }
  137. /**
  138. * 详情
  139. *
  140. * @param InvoiceLogic $invoiceLogic
  141. * @return \think\response\Json
  142. * @throws \think\Exception
  143. * @throws \think\db\exception\DataNotFoundException
  144. * @throws \think\db\exception\ModelNotFoundException
  145. * @throws \think\exception\DbException
  146. */
  147. public function read(InvoiceLogic $invoiceLogic)
  148. {
  149. $invoiceId = $this->param['id'];
  150. $isUpdate = !empty($this->param['is_update']) ? $this->param['is_update'] : 0;
  151. $userInfo = $this->userInfo;
  152. $data = $invoiceLogic->read($invoiceId, $isUpdate);
  153. $readStatus = false;
  154. # 角色权限
  155. $authArray = db('admin_access')->alias('access')
  156. ->join('__ADMIN_GROUP__ group', 'group.id = access.group_id', 'left')
  157. ->where('access.user_id', $userInfo['id'])->column('group.rules');
  158. # 详情权限ID
  159. $invoiceAuthId = db('admin_rule')->where(['types' => 2, 'name' => 'invoice', 'level' => 2])->value('id');
  160. $invoiceReadAuthId = db('admin_rule')->where(['types' => 2, 'name' => 'read', 'level' => 3, 'pid' => $invoiceAuthId])->value('id');
  161. foreach ($authArray AS $key => $value) {
  162. if (!empty($value) && in_array($invoiceReadAuthId, stringToArray($value))) $readStatus = true;
  163. }
  164. if (!isSuperAdministrators($userInfo['id']) && $readStatus === false) {
  165. $authData['dataAuth'] = 0;
  166. return resultArray(['data' => $authData]);
  167. }
  168. return resultArray(['data' => $data]);
  169. }
  170. /**
  171. * 编辑
  172. *
  173. * @param InvoiceLogic $invoiceLogic
  174. * @return \think\response\Json
  175. * @throws \think\db\exception\DataNotFoundException
  176. * @throws \think\db\exception\ModelNotFoundException
  177. * @throws \think\exception\DbException
  178. */
  179. public function update(InvoiceLogic $invoiceLogic)
  180. {
  181. $param = $this->param;
  182. if (empty($param['invoice_id'])) return resultArray(['error' => '缺少发票ID!']);
  183. // if (empty($param['customer_id'])) return resultArray(['error' => '请选择客户!']);
  184. // if (empty($param['contract_id'])) return resultArray(['error' => '请选择合同!']);
  185. // if (empty($param['invoice_money'])) return resultArray(['error' => '请填写开票金额!']);
  186. if (empty($param['invoice_type'])) return resultArray(['error' => '请选择开票类型!']);
  187. if (empty($param['title_type'])) return resultArray(['error' => '请选择抬头类型!']);
  188. if (empty($param['examineStatus'])) return resultArray(['error' => '缺少审批状态!']);
  189. $userId = $this->userInfo['id'];
  190. # 审批是否停用
  191. $examineStatus = $param['examineStatus'];
  192. # 删除无用参数
  193. unset($param['examineStatus']);
  194. unset($param['customer_name']);
  195. unset($param['contract_money']);
  196. unset($param['contract_number']);
  197. # 设置负责人ID
  198. $param['update_time'] = time();
  199. # 已进行审批,不能编辑
  200. // $dataInfo = $invoiceLogic->read($param['invoice_id'], '');
  201. // if (!$dataInfo) {
  202. // $this->error = '数据不存在或已删除';
  203. // return false;
  204. // }
  205. $checkStatus = $invoiceLogic->getExamineStatus($param['invoice_id']);
  206. if (!in_array($checkStatus, ['3', '4', '5', '6'])) return resultArray(['error' => '当前状态为审批中或已审批通过,不可编辑']);
  207. # 自动设置发票编号
  208. $numberInfo = [];
  209. if (empty($param['invoice_apple_number'])) {
  210. $numberInfo = $this->getAutoNumbers(4);
  211. if (empty($numberInfo['number'])) return resultArray(['error' => '请填写发票编号!']);
  212. $param['invoice_apple_number'] = $numberInfo['number'];
  213. }
  214. # 检查发票编号是否重复
  215. $invoiceWhere['invoice_apple_number'] = $param['invoice_apple_number'];
  216. $invoiceWhere['invoice_id'] = ['neq', $this->param['invoice_id']];
  217. if ($invoiceLogic->getInvoiceId($invoiceWhere)) return resultArray(['error' => '发票编号重复!']);
  218. if ($param['is_draft'] || (!empty($param['check_status']) && $param['check_status'] == 5)) {
  219. //保存为草稿
  220. $param['check_status'] = 5; //草稿(未提交)
  221. $param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
  222. } else {
  223. # 将合同审批状态至为待审核,提交后重新进行审批
  224. if (($examineStatus != false && $examineStatus != 'false') || $examineStatus == 1) {
  225. # 审核判断(是否有符合条件的审批流)
  226. $examineFlowModel = new \app\admin\model\ExamineFlow();
  227. $examineStepModel = new \app\admin\model\ExamineStep();
  228. if (!$examineFlowModel->checkExamine($userId, 'crm_invoice')) {
  229. return resultArray(['error' => '暂无审批人,无法创建']);
  230. }
  231. # 添加审批相关信息
  232. $examineFlowData = $examineFlowModel->getFlowByTypes($userId, 'crm_invoice');
  233. if (!$examineFlowData) {
  234. return resultArray(['error' => '无可用审批流,请联系管理员']);
  235. }
  236. $param['flow_id'] = $examineFlowData['flow_id'];
  237. # 获取审批人信息
  238. if ($examineFlowData['config'] == 1) {
  239. # 固定审批流
  240. $nextStepData = $examineStepModel->nextStepUser($userId, $examineFlowData['flow_id'], 'crm_invoice', 0, 0, 0);
  241. $next_user_ids = arrayToString($nextStepData['next_user_ids']) ? : '';
  242. $check_user_id = $next_user_ids ? : [];
  243. $param['order_id'] = 1;
  244. } else {
  245. # 授权审批流
  246. $check_user_id = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
  247. }
  248. if ($param['is_draft']) {
  249. //保存为草稿
  250. $param['check_status'] = 5;
  251. $param['check_user_id'] = $param['check_user_id'] ? ','.$param['check_user_id'].',' : '';
  252. } else {
  253. if (!$check_user_id) {
  254. return resultArray(['error' => '无可用审批人,请联系管理员']);
  255. }
  256. $param['check_user_id'] = is_array($check_user_id) ? ','.implode(',',$check_user_id).',' : $check_user_id;
  257. $param['check_status'] = 0;
  258. }
  259. $param['flow_user_id'] = '';
  260. }
  261. }
  262. if (!$invoiceLogic->update($param)) {
  263. return resultArray(['error' => '编辑失败!']);
  264. }
  265. //将审批记录至为无效
  266. $examineRecordModel = new \app\admin\model\ExamineRecord();
  267. $examineRecordModel->setEnd(['types' => 'crm_invoice','types_id' => $param['invoice_id']]);
  268. # 更新crm_number_sequence表中的last_date、create_time字段
  269. if (!empty($numberInfo['data'])) (new NumberSequence())->batchUpdate($numberInfo['data']);
  270. //修改记录
  271. // updateActionLog($param['user_id'], 'crm_invoice', $param['invoice_id'], $dataInfo, $param);
  272. return resultArray(['data' => '编辑成功!']);
  273. }
  274. /**
  275. * 删除
  276. *
  277. * @param InvoiceLogic $invoiceLogic
  278. * @return \think\response\Json
  279. * @throws \think\db\exception\DataNotFoundException
  280. * @throws \think\db\exception\ModelNotFoundException
  281. * @throws \think\exception\DbException
  282. */
  283. public function delete(InvoiceLogic $invoiceLogic)
  284. {
  285. $actionRecordModel = new \app\admin\model\ActionRecord();
  286. $fileModel = new \app\admin\model\File();
  287. $idArray = $this->param['id'];
  288. $userinfo = $this->userInfo['id'];
  289. if (!is_array($idArray)) return resultArray(['error' => '发票ID类型错误!']);
  290. $idString = implode(',', $idArray);
  291. $status = true;
  292. if (!isSuperAdministrators($userinfo['id'])) {
  293. $list = $invoiceLogic->getExamineStatus($idString, true);
  294. foreach ($list AS $key => $value) {
  295. if (!in_array($value['check_status'], [4, 5])) {
  296. $status = false;
  297. break;
  298. }
  299. }
  300. }
  301. if (!$status) return resultArray(['error' => '不能删除审批中或审批结束的发票信息!']);
  302. if (!$invoiceLogic->delete($idArray)) return resultArray(['error' => '删除失败!']);
  303. # 删除附件
  304. $fileModel->delRFileByModule('crm_invoice', $idArray);
  305. //删除关联操作记录
  306. $actionRecordModel->delDataById(['types'=>'crm_invoice','action_id'=>$idArray]);
  307. return resultArray(['data' => '删除成功!']);
  308. }
  309. /**
  310. * 转移(变更负责人)
  311. *
  312. * @param InvoiceLogic $invoiceLogic
  313. * @return \think\response\Json
  314. */
  315. public function transfer(InvoiceLogic $invoiceLogic)
  316. {
  317. $ownerUserId = $this->param['owner_user_id'];
  318. $invoiceIds = $this->param['invoice_id'];
  319. if (empty($ownerUserId)) return resultArray(['error' => '请选择负责人!']);
  320. if (empty($invoiceIds)) return resultArray(['error' => '请选择发票!']);
  321. if (!is_array($invoiceIds)) return resultArray(['error' => '发票ID类型错误!']);
  322. if ($invoiceLogic->transfer($invoiceIds, $ownerUserId) === false) return resultArray(['error' => '操作失败!']);
  323. return resultArray(['data' => '操作成功!']);
  324. }
  325. /**
  326. * 设置开票
  327. *
  328. * @param InvoiceLogic $invoiceLogic
  329. * @return \think\response\Json
  330. */
  331. public function setInvoice(InvoiceLogic $invoiceLogic)
  332. {
  333. if (empty($this->param['invoice_id'])) return resultArray(['error' => '参数错误!']);
  334. // if (empty($this->param['invoice_number'])) return resultArray(['error' => '请填写发票号码!']);
  335. // if (empty($this->param['logistics_number'])) return resultArray(['error' => '请填写物流单号!']);
  336. // if (empty($this->param['real_invoice_date'])) return resultArray(['error' => '请选择开票日期!']);
  337. $this->param['real_invoice_date'] = !empty($this->param['real_invoice_date']) ? $this->param['real_invoice_date'] : date('Y-m-d');
  338. # 开票状态
  339. $this->param['invoice_status'] = 1;
  340. # 设置开票信息
  341. if (!$invoiceLogic->setInvoice($this->param)) return resultArray(['error' => '操作失败!']);
  342. return resultArray(['data' => '操作成功!']);
  343. }
  344. /**
  345. * 审核
  346. *
  347. * @param InvoiceLogic $invoiceLogic
  348. * @return \think\response\Json
  349. * @throws \think\db\exception\DataNotFoundException
  350. * @throws \think\db\exception\ModelNotFoundException
  351. * @throws \think\exception\DbException
  352. */
  353. public function check(InvoiceLogic $invoiceLogic)
  354. {
  355. $param = $this->param;
  356. $user_id = $this->userInfo['id'];
  357. $examineStepModel = new \app\admin\model\ExamineStep();
  358. $examineRecordModel = new \app\admin\model\ExamineRecord();
  359. $examineFlowModel = new \app\admin\model\ExamineFlow();
  360. $invoiceData = [];
  361. $invoiceData['invoice_id'] = $param['id'];
  362. $invoiceData['update_time'] = time();
  363. $invoiceData['check_status'] = 1;
  364. # 权限判断
  365. if (!$examineStepModel->checkExamine($user_id, 'crm_invoice', $param['id'])) {
  366. return resultArray(['error' => $examineStepModel->getError()]);
  367. }
  368. # 审批主体详情
  369. $dataInfo = $invoiceLogic->getExamineInfo($param['id']);
  370. $flowInfo = $examineFlowModel->getDataById($dataInfo['flow_id']);
  371. # 1审批结束
  372. $is_end = 0;
  373. # 1通过,0驳回
  374. $status = !empty($param['status']) && $param['status'] == 1 ? 1 : 0;
  375. # 审批记录
  376. $checkData = [];
  377. $checkData['check_user_id'] = $user_id;
  378. $checkData['types'] = 'crm_invoice';
  379. $checkData['types_id'] = $param['id'];
  380. $checkData['check_time'] = time();
  381. $checkData['content'] = $param['content'];
  382. $checkData['flow_id'] = $dataInfo['flow_id'];
  383. $checkData['order_id'] = $dataInfo['order_id'] ? : 1;
  384. $checkData['status'] = $status;
  385. if ($status == 1) {
  386. if ($flowInfo['config'] == 1) {
  387. # 固定流程
  388. # 获取下一审批信息
  389. $nextStepData = $examineStepModel->nextStepUser($dataInfo['owner_user_id'], $dataInfo['flow_id'], 'crm_invoice', $param['id'], $dataInfo['order_id'], $user_id);
  390. $next_user_ids = $nextStepData['next_user_ids'] ? : [];
  391. $invoiceData['order_id'] = $nextStepData['order_id'] ? : '';
  392. if (!$next_user_ids) {
  393. $is_end = 1;
  394. # 审批结束
  395. $checkData['check_status'] = !empty($status) ? 2 : 3;
  396. $invoiceData['check_user_id'] = '';
  397. } else {
  398. # 修改主体相关审批信息
  399. $invoiceData['check_user_id'] = arrayToString($next_user_ids);
  400. }
  401. } else {
  402. # 自选流程
  403. $is_end = $param['is_end'] ? 1 : '';
  404. $check_user_id = $param['check_user_id'] ? : '';
  405. if ($is_end !== 1 && empty($check_user_id)) {
  406. return resultArray(['error' => '请选择下一审批人']);
  407. }
  408. $invoiceData['check_user_id'] = arrayToString($param['check_user_id']);
  409. }
  410. if ($is_end == 1) {
  411. $checkData['check_status'] = !empty($status) ? 2 : 3;
  412. $invoiceData['check_user_id'] = '';
  413. $invoiceData['check_status'] = 2;
  414. }
  415. } else {
  416. # 审批驳回
  417. $is_end = 1;
  418. $invoiceData['check_status'] = 3;
  419. }
  420. # 已审批人ID
  421. $invoiceData['flow_user_id'] = stringToArray($dataInfo['flow_user_id']) ? arrayToString(array_merge(stringToArray($dataInfo['flow_user_id']),[$user_id])) : arrayToString([$user_id]);
  422. $resContract = $invoiceLogic->setExamineInfo($invoiceData);
  423. if ($resContract) {
  424. # 审批记录
  425. $examineRecordModel->createData($checkData);
  426. # 发送站内信
  427. if ($is_end == 1 && !empty($status)) {
  428. # 审批流程结束,将审批通过消息告知负责人
  429. (new Message())->send(
  430. Message::INVOICE_PASS,
  431. [
  432. 'title' => $dataInfo['invoice_apple_number'],
  433. 'action_id' => $param['id']
  434. ],
  435. $dataInfo['owner_user_id']
  436. );
  437. } else {
  438. if (!empty($status)) {
  439. # 审批流程未结束,将待审批提醒发送给下一级负责人
  440. (new Message())->send(
  441. Message::INVOICE_TO_DO,
  442. [
  443. 'from_user' => User::where(['id' => $dataInfo['owner_user_id']])->value('realname'),
  444. 'title' => $dataInfo['invoice_apple_number'],
  445. 'action_id' => $param['id']
  446. ],
  447. stringToArray($invoiceData['check_user_id'])
  448. );
  449. } else {
  450. # 将审批被驳回的消息告知负责人
  451. (new Message())->send(
  452. Message::INVOICE_REJECT,
  453. [
  454. 'title' => $dataInfo['invoice_apple_number'],
  455. 'action_id' => $param['id']
  456. ],
  457. $dataInfo['owner_user_id']
  458. );
  459. }
  460. }
  461. return resultArray(['data' => '审批成功']);
  462. } else {
  463. return resultArray(['error' => '审批失败,请重试!']);
  464. }
  465. }
  466. /**
  467. * 撤销审核
  468. *
  469. * @param InvoiceLogic $invoiceLogic
  470. * @return \think\response\Json
  471. * @throws \think\db\exception\DataNotFoundException
  472. * @throws \think\db\exception\ModelNotFoundException
  473. * @throws \think\exception\DbException
  474. */
  475. public function revokeCheck(InvoiceLogic $invoiceLogic)
  476. {
  477. $invoiceId = $this->param['id'];
  478. $content = $this->param['content'];
  479. $realname = $this->userInfo['realname'];
  480. $userInfo = $this->userInfo;
  481. $user_id = $userInfo['id'];
  482. if (empty($invoiceId)) return resultArray(['error' => '请选择要撤回审核的发票!']);
  483. $examineInfo = $invoiceLogic->getExamineInfo($invoiceId);
  484. if ($examineInfo['check_status'] == 2) {
  485. return resultArray(['error' => '已审批结束,不能撤销']);
  486. }
  487. if ($examineInfo['check_status'] == 4) {
  488. return resultArray(['error' => '无需撤销']);
  489. }
  490. $userModel = new \app\admin\model\User();
  491. $admin_user_ids = $userModel->getAdminId();
  492. if ($examineInfo['owner_user_id'] !== $user_id && !in_array($user_id, $admin_user_ids)) {
  493. return resultArray(['error' => '没有权限']);
  494. }
  495. # 修改发票审核状态
  496. if (!$invoiceLogic->update(['invoice_id' => $invoiceId, 'check_status' => 4, 'check_user_id' => '', 'flow_user_id' => ''])) {
  497. return resultArray(['error' => '操作失败!']);
  498. }
  499. # 添加撤销审核的记录
  500. $invoiceLogic->createExamineRecord($invoiceId, $examineInfo, $realname, $content, $user_id);
  501. return resultArray(['data' => '操作成功!']);
  502. }
  503. /**
  504. * table栏数量统计
  505. *
  506. * @return \think\response\Json
  507. * @throws \think\Exception
  508. */
  509. public function count()
  510. {
  511. if (empty($this->param['invoice_id'])) return resultArray(['error' => '参数错误!']);
  512. # 附件
  513. $fileCount = Db::name('crm_invoice_file')->alias('invoice')->join('__ADMIN_FILE__ file', 'file.file_id = invoice.file_id', 'LEFT')->where('invoice_id', $this->param['invoice_id'])->count();
  514. return resultArray(['data' => ['fileCount' => $fileCount]]);
  515. }
  516. /**
  517. * 重置开票信息
  518. *
  519. * @param InvoiceLogic $invoiceLogic
  520. * @return \think\response\Json
  521. */
  522. public function resetInvoiceStatus(InvoiceLogic $invoiceLogic)
  523. {
  524. if (empty($this->param['invoice_id'])) resultArray(['error' => '参数错误!']);
  525. $this->param['real_invoice_date'] = !empty($this->param['real_invoice_date']) ? $this->param['real_invoice_date'] : date('Y-m-d');
  526. # 开票状态
  527. $this->param['invoice_status'] = 1;
  528. if (!$invoiceLogic->setInvoice($this->param)) return resultArray(['error' => '操作失败!']);
  529. return resultArray(['data' => '操作成功!']);
  530. }
  531. }