PaymentReceiptService.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. <?php
  2. namespace App\Service;
  3. use App\Model\BasicType;
  4. use App\Model\Employee;
  5. use App\Model\PaymentReceipt;
  6. use App\Model\PaymentReceiptInfo;
  7. use App\Model\PurchaseOrder;
  8. use App\Model\PurchaseOrderSpecial;
  9. use App\Model\ReturnExchangeOrder;
  10. use App\Model\SalesOrder;
  11. use Carbon\Carbon;
  12. use Illuminate\Database\Eloquent\Builder;
  13. use Illuminate\Support\Facades\DB;
  14. class PaymentReceiptService extends Service
  15. {
  16. public function paymentReceiptGet($data,$user){
  17. $order_number = (new OrderNoService())->createOrderNumber(PaymentReceipt::prefix);
  18. if(! $order_number) return [false,'工单编号生成失败!'];
  19. return [true,['order_number' => $order_number]];
  20. }
  21. public function customerEdit($data,$user){
  22. list($status,$msg) = $this->customerRule($data,$user, false);
  23. if(!$status) return [$status,$msg];
  24. try {
  25. DB::beginTransaction();
  26. $model = PaymentReceipt::where('id',$data['id'])->first();
  27. // $model->data_order_no = $data['data_order_no'];
  28. // $model->data_type = $data['data_type'];
  29. $model->type = $data['type'];
  30. $model->account = $data['account'] ?? 0;
  31. $model->pay_way = $data['pay_way'] ?? 0;
  32. // $model->amount = $data['amount'] ?? 0;
  33. $model->mark = $data['mark'] ?? '';
  34. $model->payment_receipt_date = $data['payment_receipt_date'] ?? 0;
  35. $model->save();
  36. $time = time();
  37. $old = PaymentReceiptInfo::where('del_time',0)
  38. ->where('payment_receipt_id',$data['id'])
  39. ->select('file')
  40. ->get()->toArray();
  41. $old = array_column($old,'file');
  42. PaymentReceiptInfo::where('del_time',0)
  43. ->where('payment_receipt_id',$data['id'])
  44. ->update(['del_time' => $time]);
  45. $new = [];
  46. if(! empty($data['file'])){
  47. $insert = [];
  48. foreach ($data['file'] as $value){
  49. $insert[] = [
  50. 'payment_receipt_id' => $model->id,
  51. 'file' => $value['url'],
  52. 'type' => PaymentReceiptInfo::type_one,
  53. 'name' => $value['name'],
  54. 'crt_time' => $time,
  55. ];
  56. if(in_array($value['url'], $old)) {
  57. foreach ($old as $o_k => $o_v){
  58. if($o_v == $value['url']) unset($old[$o_k]);
  59. }
  60. }else{
  61. $new[] = $value['url'];
  62. }
  63. }
  64. PaymentReceiptInfo::insert($insert);
  65. }
  66. if(! empty($data['employee_one'])){
  67. $insert = [];
  68. foreach ($data['employee_one'] as $value){
  69. $insert[] = [
  70. 'payment_receipt_id' => $model->id,
  71. 'data_id' => $value,
  72. 'type' => PaymentReceiptInfo::type_two,
  73. 'crt_time' => $time,
  74. ];
  75. }
  76. PaymentReceiptInfo::insert($insert);
  77. }
  78. if(! empty($data['amount_list'])){
  79. $insert = [];
  80. foreach ($data['amount_list'] as $value){
  81. $insert[] = [
  82. 'payment_receipt_id' => $model->id,
  83. 'data_type' => $data['type'],
  84. 'data_order_no' => $value['data_order_no'],
  85. 'data_order_type' => $data['data_type'],
  86. 'amount' => $value['amount'],
  87. 'type' => PaymentReceiptInfo::type_three,
  88. 'crt_time' => $time,
  89. ];
  90. }
  91. PaymentReceiptInfo::insert($insert);
  92. }
  93. DB::commit();
  94. }catch (\Exception $exception){
  95. DB::rollBack();
  96. return [false,$exception->getMessage()];
  97. }
  98. if(! empty($data['check'])) {
  99. list($status,$msg) = (new CheckService())->checkAll([
  100. "id" => $data['id'],
  101. "order_number" => $data['order_number'],
  102. "opt_case" => CheckService::ten,
  103. "menu_id" => $data['menu_id']
  104. ],$user);
  105. // if(! $status) return [true, '保存成功,收付款确认失败,异常信息:' . $msg];
  106. }
  107. return [true, ['file' => ['new' => $new, 'old' => $old]]];
  108. }
  109. public function customerAdd($data,$user){
  110. list($status,$msg) = $this->customerRule($data,$user);
  111. if(!$status) return [$status,$msg];
  112. try {
  113. DB::beginTransaction();
  114. $model = new PaymentReceipt();
  115. $model->order_number = $data['order_number'];
  116. // $model->data_order_no = $data['data_order_no'];
  117. $model->data_type = $data['data_type'];
  118. $model->type = $data['type'];
  119. $model->account = $data['account'] ?? 0;
  120. $model->pay_way = $data['pay_way'] ?? 0;
  121. // $model->amount = $data['amount'] ?? 0;
  122. $model->mark = $data['mark'] ?? '';
  123. $model->crt_id = $user['id'];
  124. $model->depart_id = $data['depart_id'];
  125. $model->top_depart_id = $data['top_depart_id'];
  126. $model->payment_receipt_date = $data['payment_receipt_date'] ?? 0;
  127. $model->save();
  128. $time = time();
  129. $new = [];
  130. if(! empty($data['file'])){
  131. $insert = [];
  132. foreach ($data['file'] as $value){
  133. $insert[] = [
  134. 'payment_receipt_id' => $model->id,
  135. 'file' => $value['url'],
  136. 'type' => PaymentReceiptInfo::type_one,
  137. 'name' => $value['name'],
  138. 'crt_time' => $time,
  139. ];
  140. if(! empty($value['url'])) $new[] = $value['url'];
  141. }
  142. PaymentReceiptInfo::insert($insert);
  143. }
  144. if(! empty($data['employee_one'])){
  145. $insert = [];
  146. foreach ($data['employee_one'] as $value){
  147. $insert[] = [
  148. 'payment_receipt_id' => $model->id,
  149. 'data_id' => $value,
  150. 'type' => PaymentReceiptInfo::type_two,
  151. 'crt_time' => $time,
  152. ];
  153. }
  154. PaymentReceiptInfo::insert($insert);
  155. }
  156. if(! empty($data['amount_list'])){
  157. $insert = [];
  158. foreach ($data['amount_list'] as $value){
  159. $insert[] = [
  160. 'payment_receipt_id' => $model->id,
  161. 'data_type' => $data['type'],
  162. 'data_order_no' => $value['data_order_no'],
  163. 'data_order_type' => $data['data_type'],
  164. 'amount' => $value['amount'],
  165. 'type' => PaymentReceiptInfo::type_three,
  166. 'crt_time' => $time,
  167. ];
  168. }
  169. PaymentReceiptInfo::insert($insert);
  170. }
  171. DB::commit();
  172. }catch (\Exception $exception){
  173. DB::rollBack();
  174. if (str_contains($exception->getMessage(), '1062') || str_contains($exception->getMessage(), 'Duplicate entry')) {
  175. return [false, '收付款单编号已存在,请重新获取!'];
  176. }
  177. return [false,$exception->getMessage()];
  178. }
  179. if(! empty($data['check'])) {
  180. list($status,$msg) = (new CheckService())->checkAll([
  181. "id" => $model->id,
  182. "order_number" => $data['order_number'],
  183. "opt_case" => CheckService::ten,
  184. "menu_id" => $data['menu_id']
  185. ],$user);
  186. // if(! $status) return [true, '保存成功,收付款确认失败,异常信息:' . $msg];
  187. }
  188. return [true, ['file' => ['new' => $new]]];
  189. }
  190. public function customerDel($data){
  191. if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
  192. $booking = PaymentReceipt::where('del_time',0)->where('id',$data['id'])->first();
  193. if(empty($booking)) return [false,'收付款单不存在或已被删除'];
  194. $booking = $booking->toArray();
  195. if($booking['state'] > PaymentReceipt::STATE_ZERO) return [false,'请确认收付款单状态,删除失败'];
  196. try {
  197. DB::beginTransaction();
  198. $time = time();
  199. $old = PaymentReceiptInfo::where('del_time',0)
  200. ->where('payment_receipt_id',$data['id'])
  201. ->select('file')
  202. ->get()->toArray();
  203. $old = array_column($old,'file');
  204. PaymentReceipt::where('id',$data['id'])->update([
  205. 'del_time'=> $time
  206. ]);
  207. PaymentReceiptInfo::where('del_time',0)
  208. ->where('payment_receipt_id',$data['id'])
  209. ->update(['del_time' => $time]);
  210. DB::commit();
  211. }catch (\Exception $exception){
  212. DB::rollBack();
  213. return [false,$exception->getMessage()];
  214. }
  215. return [true, ['file' => ['old' => $old]]];
  216. }
  217. public function customerDetail($data){
  218. if(empty($data['id']) && empty($data['order_number'])) return [false,'请选择数据!'];
  219. if(! empty($data['id'])){
  220. $customer = PaymentReceipt::where('del_time',0)
  221. ->where('id',$data['id'])
  222. ->first();
  223. }else{
  224. $customer = PaymentReceipt::where('del_time',0)
  225. ->where('order_number',$data['order_number'])
  226. ->first();
  227. $data['id'] = empty($customer->id) ? 0 : $customer->id;
  228. }
  229. if(empty($customer)) return [false,'收付款记录不存在或已被删除'];
  230. $customer = $customer->toArray();
  231. $array = [
  232. $customer['account'],
  233. $customer['pay_way'],
  234. ];
  235. $basic_map = BasicType::whereIn('id',$array)
  236. ->pluck('title','id')
  237. ->toArray();
  238. $customer['account_title'] = $basic_map[$customer['account']] ?? "";
  239. $customer['pay_way_title'] = $basic_map[$customer['pay_way']] ?? "";
  240. $customer['type_title'] = PaymentReceipt::$model_type[$customer['type']] ?? "";
  241. $customer['data_type_title'] = PaymentReceipt::$data_type[$customer['data_type']] ?? "";
  242. $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
  243. $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
  244. $customer['payment_receipt_date'] = $customer['payment_receipt_date'] ? date("Y-m-d",$customer['payment_receipt_date']): '';
  245. //订单状态数据组织
  246. $state_array = $this->getStateMake([$customer]);
  247. $customer['state_title'] = $this->makeState($customer,$state_array);
  248. $file = PaymentReceiptInfo::where('del_time',0)
  249. ->whereIn('type',[PaymentReceiptInfo::type_one,PaymentReceiptInfo::type_two])
  250. ->where('payment_receipt_id',$data['id'])
  251. ->get()->toArray();
  252. $emp_id = [];
  253. foreach ($file as $value){
  254. if(in_array($value['type'],PaymentReceiptInfo::$man)){
  255. $emp_id[] = $value['data_id'];
  256. }
  257. }
  258. $emp_map = Employee::whereIn('id',array_unique($emp_id))
  259. ->pluck('emp_name','id')
  260. ->toArray();
  261. $customer['file'] = $customer['employee_one'] = [];
  262. $fileUploadService = new FileUploadService();
  263. foreach ($file as $value){
  264. if($value['type'] == PaymentReceiptInfo::type_one){
  265. $tmp = [
  266. 'url' => $value['file'],
  267. 'name' => $value['name'],
  268. 'show_url' => $fileUploadService->getFileShow($value['file']),
  269. ];
  270. $customer['file'][] = $tmp;
  271. }elseif (in_array($value['type'],PaymentReceiptInfo::$man)){
  272. $tt = $emp_map[$value['data_id']] ?? '';
  273. if(! empty($tt)){
  274. $tmp = [
  275. 'id' => $value['data_id'],
  276. 'name' => $emp_map[$value['data_id']] ?? '',
  277. ];
  278. if($value['type'] == PaymentReceiptInfo::type_two){
  279. $customer['employee_one'][] = $tmp;
  280. }
  281. }
  282. }
  283. }
  284. //组织金额
  285. $customer['amount_list'] = $this->makeDetail($customer);
  286. return [true, $customer];
  287. }
  288. public function makeDetail($data){
  289. $return = [];
  290. $info = PaymentReceiptInfo::where('del_time',0)
  291. ->where('type',PaymentReceiptInfo::type_three)
  292. ->where('payment_receipt_id', $data['id'])
  293. ->select('payment_receipt_id','data_order_type','data_type','amount','data_order_no')
  294. ->get()->toArray();
  295. $order_no = array_column($info,'data_order_no');
  296. //退换货金额
  297. if($data['type'] == PaymentReceipt::type_one){
  298. if($data['data_type'] == PaymentReceipt::data_type_one){
  299. $order = SalesOrder::where('del_time',0)
  300. ->whereIn('order_number',$order_no)
  301. ->pluck('contract_fee','order_number')
  302. ->toArray();
  303. $getDifferentAmountALL = (new ReturnExchangeOrderService())->getDifferentAmountALL2(array_keys($order));
  304. }else{
  305. $order = PurchaseOrder::where('del_time',0)
  306. ->whereIn('order_number',$order_no)
  307. ->pluck('purchase_total','order_number')
  308. ->toArray();
  309. $getDifferentAmountALL = (new ReturnExchangeOrderService())->getDifferentAmountALL2(array_keys($order), ReturnExchangeOrder::Order_type2);
  310. }
  311. }
  312. //除自己这个收付款单外 所有订单已填的金额
  313. $infos = PaymentReceiptInfo::where('del_time',0)
  314. ->where('type',PaymentReceiptInfo::type_three)
  315. ->where('data_type',$data['type'])
  316. ->where('payment_receipt_id','<>',$data['id'])
  317. ->whereIn('data_order_no',$order_no)
  318. ->get()->toArray();
  319. $infos_map = [];
  320. foreach ($infos as $value){
  321. if(isset($infos_map[$value['data_order_no']])){
  322. $infos_map[$value['data_order_no']] += $value['amount'];
  323. }else{
  324. $infos_map[$value['data_order_no']] = $value['amount'];
  325. }
  326. }
  327. //收款金额(审核后)
  328. $info_one_array = [];
  329. if($data['type'] == PaymentReceipt::type_three){
  330. $info_one = PaymentReceiptInfo::from('payment_receipt_info as a')
  331. ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
  332. ->where('b.state',PaymentReceipt::STATE_TWO)
  333. ->where('b.del_time',0)
  334. ->where('a.del_time',0)
  335. ->where('a.type',PaymentReceiptInfo::type_three)
  336. ->where('a.data_order_type',PaymentReceipt::data_type_one)
  337. ->whereIn('a.data_order_no',$order_no)
  338. ->where('a.data_type',PaymentReceipt::type_one)
  339. ->select('a.data_order_no','a.amount')
  340. ->get()->toArray();
  341. $info_one_array = [];
  342. foreach ($info_one as $value){
  343. if(isset($info_one_array[$value['data_order_no']])){
  344. $info_one_array[$value['data_order_no']] += $value['amount'];
  345. }else{
  346. $info_one_array[$value['data_order_no']] = $value['amount'];
  347. }
  348. }
  349. }
  350. foreach ($info as $value){
  351. $total = $tmp_receipt = 0;
  352. if($data['type'] == PaymentReceipt::type_one){
  353. //收款 = 总金额 - 已收 - 退货退款
  354. //总金额
  355. $total_amount = $order[$value['data_order_no']] ?? 0;
  356. //已收
  357. $tmp_receipt = $infos_map[$value['data_order_no']] ?? 0;
  358. //退货退款
  359. $tmp_return = $getDifferentAmountALL[$value['data_order_no']] ?? 0;
  360. //收款
  361. $total = bcsub(bcsub($total_amount, $tmp_receipt,2), $tmp_return, 2);
  362. }elseif($data['type'] == PaymentReceipt::type_three){
  363. //红冲 = 审核后的收款金额 - 已红冲
  364. //总金额 收款金额(审核后)
  365. $total_amount = $info_one_array[$value['data_order_no']] ?? 0;
  366. //已红冲
  367. $tmp_receipt = $infos_map[$value['data_order_no']] ?? 0;
  368. //红冲
  369. $total = bcsub($total_amount, $tmp_receipt, 2);
  370. }
  371. $tmp = [
  372. 'data_order_no' => $value['data_order_no'],
  373. 'total_amount' => $total,//总共能填的金额
  374. 'has_amount' => $tmp_receipt,//已经填的金额
  375. 'amount' => $value['amount'],//本单金额
  376. 'receipt_amount' => $value['amount'],//本单金额
  377. ];
  378. $return[] = $tmp;
  379. }
  380. return $return;
  381. }
  382. public function customerCommon($data,$user,$field = []){
  383. if(empty($field)){
  384. $field = ['type','id','data_type','order_number','data_order_no','amount','account','pay_way','crt_id','crt_time','mark','state','payment_receipt_date'];
  385. }
  386. $model = PaymentReceipt::Clear($user,$data);
  387. $model = $model->where('del_time',0)
  388. ->select($field)
  389. ->orderby('id', 'desc');
  390. if(isset($data['state'])) $model->where('state', $data['state']);
  391. if(! empty($data['data_order_no'])) {
  392. $id = $this->searchForDataOrder($data['data_order_no']);
  393. $model->whereIn('id', $id);
  394. }
  395. if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
  396. if(! empty($data['data_type'])) $model->where('data_type', $data['data_type']);
  397. if(! empty($data['type'])) $model->where('type', $data['type']);
  398. if(! empty($data['account'])) $model->where('account',$data['account']);
  399. if(! empty($data['account_title'])){
  400. $id = (new BasicTypeService())->basicTypeSearch($data['account_title']);
  401. $model->whereIn('account',$id);
  402. }
  403. if(! empty($data['pay_way'])) $model->where('pay_way',$data['pay_way']);
  404. if(! empty($data['mark'])) $model->where('mark', 'LIKE', '%'.$data['mark'].'%');
  405. if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
  406. $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
  407. $model->where('crt_time','>=',$return[0]);
  408. $model->where('crt_time','<=',$return[1]);
  409. }
  410. if(! empty($data['payment_receipt_date'][0]) && ! empty($data['payment_receipt_date'][1])){
  411. $return = $this->changeDateToTimeStampAboutRange($data['payment_receipt_date']);
  412. $model->where('payment_receipt_date','>=',$return[0]);
  413. $model->where('payment_receipt_date','<=',$return[1]);
  414. }
  415. if(! empty($data['belong'])){
  416. $id = (new RangeService())->paymentReceiptSearch($data);
  417. $model->whereIn('id',$id);
  418. }
  419. if(! empty($data['smart_search'])){
  420. $id = $this->searchForDataOrder($data['smart_search']);
  421. $model->where(function (Builder $query) use ($data, $id) {
  422. $query->where('order_number', 'LIKE', '%'.$data['smart_search'].'%')
  423. ->OrWhereIn('id',$id);
  424. });
  425. }
  426. if(! empty($data['wx_crt_time'][0]) && ! empty($data['wx_crt_time'][1])) {
  427. $model->where('crt_time','>=',$data['wx_crt_time'][0]);
  428. $model->where('crt_time','<=',$data['wx_crt_time'][1]);
  429. }
  430. return $model;
  431. }
  432. public function searchForDataOrder($message){
  433. $info = PaymentReceiptInfo::where('del_time',0)
  434. ->where('type',PaymentReceiptInfo::type_three)
  435. ->where('data_order_no', 'LIKE', '%'.$message.'%')
  436. ->select('payment_receipt_id')
  437. ->get()->toArray();
  438. return array_unique(array_column($info,'payment_receipt_id'));
  439. }
  440. public function customerList($data,$user){
  441. $model = $this->customerCommon($data, $user);
  442. $list = $this->limit($model,'',$data);
  443. $list = $this->fillData($list, $data);
  444. $count = $this->countData("crt_time", $data, $user);
  445. $list['today'] = $count[0] ?? 0;
  446. $list['yesterday'] = $count[1] ?? 0;
  447. return [true, $list];
  448. }
  449. public function customerRule(&$data, $user, $is_add = true){
  450. if(empty($data['order_number'])) return [false,'收付款单编号不能为空'];
  451. if(empty($data['data_type'])) return [false,'关联单号类型不能为空'];
  452. if(! isset(PaymentReceipt::$data_type[$data['data_type']])) return [false, '关联单号类型不存在'];
  453. if(empty($data['type'])) return [false,'收付款类型不能为空'];
  454. if(! isset(PaymentReceipt::$model_type[$data['type']])) return [false, '收付款类型不存在'];
  455. if(empty($data['amount_list']) || ! is_array($data['amount_list'])) return [false,'关联单号与金额不能为空'];
  456. foreach ($data['amount_list'] as $value){
  457. if(empty($value['data_order_no'])) return [false,'关联单号不能为空'];
  458. if(empty($value['amount'])) return [false,'金额不能为空'];
  459. if(floatval($value['amount']) == 0) return [false, '金额请输入大于0的数值'];
  460. $res = $this->checkNumber($value['amount']);
  461. if(! $res) return [false, '金额请输入不超过两位小数并且大于0的数值'];
  462. }
  463. if(! empty($data['payment_receipt_date'])) $data['payment_receipt_date'] = $this->changeDateToDate($data['payment_receipt_date']);
  464. //所属部门 以及 顶级部门
  465. if(empty($data['depart_id'])) {
  466. $data['depart_id'] = $this->getDepart($user);
  467. $data['top_depart_id'] = $user['depart_map'][$data['depart_id']] ?? 0;
  468. }
  469. if($is_add){
  470. $bool = PaymentReceipt::where('del_time',0)
  471. ->where('order_number',$data['order_number'])
  472. ->exists();
  473. if($bool) return [false,'收付款单编号已存在,请重新获取'];
  474. }else{
  475. if(empty($data['id'])) return [false,'ID不能为空'];
  476. $booking = PaymentReceipt::where('del_time',0)->where('id',$data['id'])->first();
  477. if(empty($booking)) return [false,'收付款单不存在或已被删除'];
  478. $booking = $booking->toArray();
  479. if(! in_array($booking['state'],[PaymentReceipt::STATE_ZERO,PaymentReceipt::State_minus_one])) return [false,'请确认收付款单状态,编辑失败'];
  480. //订单编辑提交限制
  481. $current_top_depart_id = $this->getMyTopDepart($user);
  482. list($status, $msg) = $this->returnOrderEditErrorCommon($current_top_depart_id, $booking['top_depart_id']);
  483. if(! $status) return [false, $msg];
  484. }
  485. list($status,$msg) = $this->checkRule($data);
  486. if(! $status) return [false, $msg];
  487. return [true, ''];
  488. }
  489. public function checkRule($data){
  490. $payment_receipt_id = $data['id'] ?? 0;
  491. $map = [];
  492. foreach ($data['amount_list'] as $value){
  493. $map[$value['data_order_no']] = $value['amount'];
  494. }
  495. $search = array_keys($map);
  496. if($data['data_type'] == PaymentReceipt::data_type_one){ //合同逻辑
  497. //总金额
  498. $result = SalesOrder::where('del_time',0)
  499. ->whereIn('order_number',$search)
  500. ->select('id','order_number','contract_fee as total_amount')
  501. ->get()->toArray();
  502. $result_map = array_column($result,null,'order_number');
  503. if(count($search) != count($result)) {
  504. foreach ($search as $value){
  505. if(! isset($result_map[$value])) return [false, $value . '不存在或已被删除'];
  506. }
  507. }
  508. $result_map = array_column($result,'order_number','id');
  509. //收付款金额
  510. $info = PaymentReceiptInfo::where('del_time',0)
  511. ->where('type',PaymentReceiptInfo::type_three)
  512. ->where('data_order_type',PaymentReceipt::data_type_one)
  513. ->whereIn('data_order_no',$search)
  514. // ->where('data_type',$data['type'])
  515. ->select('payment_receipt_id','data_order_no','amount','data_type')
  516. ->get()->toArray();
  517. $info_array = $red = [];
  518. foreach ($info as $value){
  519. if($payment_receipt_id > 0 && $value['payment_receipt_id'] == $payment_receipt_id) continue;
  520. if($value['data_type'] == PaymentReceipt::type_one){
  521. if(isset($info_array[$value['data_order_no']])){
  522. $info_array[$value['data_order_no']] += $value['amount'];
  523. }else{
  524. $info_array[$value['data_order_no']] = $value['amount'];
  525. }
  526. }elseif($value['data_type'] == PaymentReceipt::type_three){
  527. if(isset($red[$value['data_order_no']])){
  528. $red[$value['data_order_no']] += $value['amount'];
  529. }else{
  530. $red[$value['data_order_no']] = $value['amount'];
  531. }
  532. }
  533. }
  534. //退货退款金额
  535. $return_exchange = (new ReturnExchangeOrderService())->getDifferentAmountALL(array_column($result,'id'));
  536. if($data['type'] == PaymentReceipt::type_one){
  537. // order_number => amount
  538. $return_exchange_array = [];
  539. foreach ($result_map as $key => $value){
  540. if(isset($return_exchange[$key])) $return_exchange_array[$value] = $return_exchange[$key];
  541. }
  542. foreach ($result as $value){
  543. //收款 = 总金额 - (已收 - 红冲) - 退货退款
  544. //$max = $value['total_amount'] - $tmp_receipt - $tmp_return;
  545. $tmp_receipt = $info_array[$value['order_number']] ?? 0;
  546. $tmp_red = $red[$value['order_number']] ?? 0;
  547. $tmp_return = $return_exchange_array[$value['order_number']] ?? 0;
  548. $max = bcsub(bcsub($value['total_amount'], bcsub($tmp_receipt,$tmp_red,2),2), $tmp_return, 2);
  549. if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
  550. }
  551. }elseif($data['type'] == PaymentReceipt::type_three){
  552. //收款金额(审核后)
  553. $info_one = PaymentReceiptInfo::from('payment_receipt_info as a')
  554. ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
  555. ->where('b.state',PaymentReceipt::STATE_TWO)
  556. ->where('b.del_time',0)
  557. ->where('a.del_time',0)
  558. ->where('a.type',PaymentReceiptInfo::type_three)
  559. ->where('a.data_order_type',PaymentReceipt::data_type_one)
  560. ->whereIn('a.data_order_no',$search)
  561. ->where('a.data_type',PaymentReceipt::type_one)
  562. ->select('a.payment_receipt_id','a.data_order_no','a.amount')
  563. ->get()->toArray();
  564. $info_one_array = [];
  565. foreach ($info_one as $value){
  566. if(isset($info_one_array[$value['data_order_no']])){
  567. $info_one_array[$value['data_order_no']] += $value['amount'];
  568. }else{
  569. $info_one_array[$value['data_order_no']] = $value['amount'];
  570. }
  571. }
  572. foreach ($result as $value){
  573. //红冲 = 审核后的收款单金额 - 已红冲
  574. $tmp_receipt = $info_one_array[$value['order_number']] ?? 0;
  575. $tmp_return = $red[$value['order_number']] ?? 0;
  576. $max = bcsub($tmp_receipt, $tmp_return, 2);
  577. if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
  578. }
  579. }
  580. }elseif ($data['data_type'] == PaymentReceipt::data_type_two){//采购逻辑
  581. //总金额
  582. $result = PurchaseOrder::where('del_time',0)
  583. ->whereIn('order_number',$search)
  584. ->select('id','order_number','purchase_total as total_amount')
  585. ->get()->toArray();
  586. $result_map = array_column($result,null,'order_number');
  587. if(count($search) != count($result)) {
  588. foreach ($search as $value){
  589. if(! isset($result_map[$value])) return [false, $value . '不存在或已被删除'];
  590. }
  591. }
  592. $result_map = array_column($result,'order_number','id');
  593. //收付款金额
  594. $info = PaymentReceiptInfo::where('del_time',0)
  595. ->where('type',PaymentReceiptInfo::type_three)
  596. ->where('data_order_type',PaymentReceipt::data_type_two)
  597. ->whereIn('data_order_no',$search)
  598. // ->where('data_type',$data['type'])
  599. ->select('payment_receipt_id','data_order_no','amount','data_type')
  600. ->get()->toArray();
  601. $info_array = $red = [];
  602. foreach ($info as $value){
  603. if($payment_receipt_id > 0 && $value['payment_receipt_id'] == $payment_receipt_id) continue;
  604. if($value['data_type'] == PaymentReceipt::type_one){
  605. if(isset($info_array[$value['data_order_no']])){
  606. $info_array[$value['data_order_no']] += $value['amount'];
  607. }else{
  608. $info_array[$value['data_order_no']] = $value['amount'];
  609. }
  610. }elseif($value['data_type'] == PaymentReceipt::type_three){
  611. if(isset($red[$value['data_order_no']])){
  612. $red[$value['data_order_no']] += $value['amount'];
  613. }else{
  614. $red[$value['data_order_no']] = $value['amount'];
  615. }
  616. }
  617. }
  618. //退货退款金额
  619. $return_exchange = (new ReturnExchangeOrderService())->getDifferentAmountALL(array_column($result,'id'),1);
  620. if($data['type'] == PaymentReceipt::type_one){
  621. $return_exchange_array = [];
  622. foreach ($result_map as $key => $value){
  623. // order_number => amount
  624. if(isset($return_exchange[$key])) $return_exchange_array[$value] = $return_exchange[$key];
  625. }
  626. foreach ($result as $value){
  627. //收款 = 总金额 - (已收 - 红冲) - 退货退款
  628. //$max = $value['total_amount'] - $tmp_receipt - $tmp_return;
  629. $tmp_receipt = $info_array[$value['order_number']] ?? 0;
  630. $tmp_red = $red[$value['order_number']] ?? 0;
  631. $tmp_return = $return_exchange_array[$value['order_number']] ?? 0;
  632. $max = bcsub(bcsub($value['total_amount'], bcsub($tmp_receipt,$tmp_red,2),2), $tmp_return, 2);
  633. if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
  634. }
  635. }elseif($data['type'] == PaymentReceipt::type_three){
  636. //收款金额(审核后)
  637. $info_one = PaymentReceiptInfo::from('payment_receipt_info as a')
  638. ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
  639. ->where('b.state',PaymentReceipt::STATE_TWO)
  640. ->where('b.del_time',0)
  641. ->where('a.del_time',0)
  642. ->where('a.type',PaymentReceiptInfo::type_three)
  643. ->where('a.data_order_type',PaymentReceipt::data_type_one)
  644. ->whereIn('a.data_order_no',$search)
  645. ->where('a.data_type',PaymentReceipt::type_one)
  646. ->select('a.payment_receipt_id','a.data_order_no','a.amount')
  647. ->get()->toArray();
  648. $info_one_array = [];
  649. foreach ($info_one as $value){
  650. if(isset($info_one_array[$value['data_order_no']])){
  651. $info_one_array[$value['data_order_no']] += $value['amount'];
  652. }else{
  653. $info_one_array[$value['data_order_no']] = $value['amount'];
  654. }
  655. }
  656. foreach ($result as $value){
  657. //红冲 = 审核后的收款单金额 - 已红冲
  658. $tmp_receipt = $info_one_array[$value['order_number']] ?? 0;
  659. $tmp_return = $red[$value['order_number']] ?? 0;
  660. $max = bcsub($tmp_receipt, $tmp_return, 2);
  661. if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
  662. }
  663. }
  664. }elseif ($data['data_type'] == PaymentReceipt::data_type_three){//虚拟采购
  665. //总金额
  666. $result = PurchaseOrderSpecial::where('del_time',0)
  667. ->whereIn('order_number',$search)
  668. ->select('id','order_number','purchase_total as total_amount','other_fee','sales_order_id')
  669. ->get()->toArray();
  670. $result_map = array_column($result,null,'order_number');
  671. if(count($search) != count($result)) {
  672. foreach ($search as $value){
  673. if(! isset($result_map[$value])) return [false, $value . '不存在或已被删除'];
  674. }
  675. }
  676. $result_map = array_column($result,'order_number','sales_order_id');
  677. //收付款金额
  678. $info = PaymentReceiptInfo::where('del_time',0)
  679. ->where('type',PaymentReceiptInfo::type_three)
  680. ->where('data_order_type',PaymentReceipt::data_type_three)
  681. ->whereIn('data_order_no',$search)
  682. // ->where('data_type',$data['type'])
  683. ->select('payment_receipt_id','data_order_no','amount','data_type')
  684. ->get()->toArray();
  685. $info_array = $red = [];
  686. foreach ($info as $value){
  687. if($payment_receipt_id > 0 && $value['payment_receipt_id'] == $payment_receipt_id) continue;
  688. if($value['data_type'] == PaymentReceipt::type_one){
  689. if(isset($info_array[$value['data_order_no']])){
  690. $info_array[$value['data_order_no']] += $value['amount'];
  691. }else{
  692. $info_array[$value['data_order_no']] = $value['amount'];
  693. }
  694. }elseif($value['data_type'] == PaymentReceipt::type_three){
  695. if(isset($red[$value['data_order_no']])){
  696. $red[$value['data_order_no']] += $value['amount'];
  697. }else{
  698. $red[$value['data_order_no']] = $value['amount'];
  699. }
  700. }
  701. }
  702. //退货退款金额
  703. $return_exchange = (new ReturnExchangeOrderService())->getDifferentAmountALL(array_column($result,'sales_order_id'));
  704. if($data['type'] == PaymentReceipt::type_one){
  705. // order_number => amount
  706. $return_exchange_array = [];
  707. foreach ($result_map as $key => $value){
  708. if(isset($return_exchange[$key])) $return_exchange_array[$value] = $return_exchange[$key];
  709. }
  710. foreach ($result as $value){
  711. //收款 = 总金额(订单金额 + 其他费用) - (已收 - 红冲) - 退换货
  712. $tmp_receipt = $info_array[$value['order_number']] ?? 0;
  713. $tmp_red = $red[$value['order_number']] ?? 0;
  714. $total = bcadd($value['total_amount'],$value['other_fee'],2);
  715. $tmp_return = $return_exchange_array[$value['order_number']] ?? 0;
  716. $max = bcsub($total, bcsub($tmp_receipt,$tmp_red,2), 2);
  717. $max = bcsub($max, $tmp_return, 2);
  718. if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
  719. }
  720. }elseif($data['type'] == PaymentReceipt::type_three){
  721. //收款金额(审核后)
  722. $info_one = PaymentReceiptInfo::from('payment_receipt_info as a')
  723. ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
  724. ->where('b.state',PaymentReceipt::STATE_TWO)
  725. ->where('b.del_time',0)
  726. ->where('a.del_time',0)
  727. ->where('a.type',PaymentReceiptInfo::type_three)
  728. ->where('a.data_order_type',PaymentReceipt::data_type_three)
  729. ->whereIn('a.data_order_no',$search)
  730. ->where('a.data_type',PaymentReceipt::type_one)
  731. ->select('a.payment_receipt_id','a.data_order_no','a.amount')
  732. ->get()->toArray();
  733. $info_one_array = [];
  734. foreach ($info_one as $value){
  735. if(isset($info_one_array[$value['data_order_no']])){
  736. $info_one_array[$value['data_order_no']] += $value['amount'];
  737. }else{
  738. $info_one_array[$value['data_order_no']] = $value['amount'];
  739. }
  740. }
  741. foreach ($result as $value){
  742. //红冲 = 审核后的收款单金额 - 已红冲
  743. $tmp_receipt = $info_one_array[$value['order_number']] ?? 0;
  744. $tmp_return = $red[$value['order_number']] ?? 0;
  745. $max = bcsub($tmp_receipt, $tmp_return, 2);
  746. if($map[$value['order_number']] > $max) return [false, $value['order_number'] . '的金额填写上限是' . $max];
  747. }
  748. }
  749. }
  750. return [true, ''];
  751. }
  752. public function fillData($data, $ergs){
  753. if(empty($data['data'])) return $data;
  754. $emp = Employee::whereIn('id',array_unique(array_column($data['data'],'crt_id')))
  755. ->pluck('emp_name','id')
  756. ->toArray();
  757. $array = array_unique(array_merge_recursive(array_column($data['data'],'account'),array_column($data['data'],'pay_way')));
  758. $basic_map = BasicType::whereIn('id',$array)
  759. ->pluck('title','id')
  760. ->toArray();
  761. $map = [];
  762. $info = PaymentReceiptInfo::where('del_time',0)
  763. ->where('type',PaymentReceiptInfo::type_three)
  764. ->whereIn('payment_receipt_id', array_unique(array_column($data['data'],'id')))
  765. ->select('payment_receipt_id','data_order_no')
  766. ->get()->toArray();
  767. foreach ($info as $value){
  768. $map[$value['payment_receipt_id']][] = $value['data_order_no'];
  769. }
  770. //订单状态数据组织
  771. $state_array = $this->getStateMake($data['data']);
  772. foreach ($data['data'] as $key => $value){
  773. $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
  774. $data['data'][$key]['payment_receipt_date'] = $value['payment_receipt_date'] ? date('Y-m-d',$value['payment_receipt_date']) : '';
  775. $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
  776. $data['data'][$key]['state_title'] = $this->makeState($data['data'][$key], $state_array);
  777. $data['data'][$key]['type_title'] = PaymentReceipt::$model_type[$value['type']] ?? '';
  778. $data['data'][$key]['data_type_title'] = PaymentReceipt::$data_type[$value['data_type']] ?? '';
  779. $data['data'][$key]['account_title'] = $basic_map[$value['account']] ?? '';
  780. $data['data'][$key]['pay_way_title'] = $basic_map[$value['pay_way']] ?? '';
  781. $data['data'][$key]['data_order_no'] = $map[$value['id']] ?? [];
  782. }
  783. return $data;
  784. }
  785. public function countData($column = "", $data, $user){
  786. if(empty($column) || empty($data['from_wx'])) return [0, 0];
  787. // 获取今天的开始和结束时间戳
  788. $todayStart = Carbon::today()->startOfDay()->timestamp;
  789. $todayEnd = Carbon::today()->endOfDay()->timestamp;
  790. // 获取昨天的开始和结束时间戳
  791. $yesterdayStart = Carbon::yesterday()->startOfDay()->timestamp;
  792. $yesterdayEnd = Carbon::yesterday()->endOfDay()->timestamp;
  793. $data['wx_' . $column] = [$todayStart, $todayEnd];
  794. $model = $this->customerCommon($data, $user);
  795. // 查询今天的数据条数
  796. $todayCount = $model->count();
  797. $data['wx_' . $column] = [$yesterdayStart, $yesterdayEnd];
  798. $model = $this->customerCommon($data, $user);
  799. // 查询昨天的数据条数
  800. $yesterdayCount = $model->count();
  801. return [$todayCount, $yesterdayCount];
  802. }
  803. public function getStateMake($data){
  804. if(empty($data)) return [];
  805. $order_no = [];
  806. foreach ($data as $value){
  807. if(! in_array($value['state'], [PaymentReceipt::State_minus_one,PaymentReceipt::STATE_ONE])) continue;
  808. $order_no[] = $value['order_number'];
  809. }
  810. return (new OaService())->getOaTeamDetailList($order_no);
  811. }
  812. public function makeState($value, $state_array){
  813. if(! empty($state_array[$value['order_number']])){
  814. $return = $state_array[$value['order_number']];
  815. if($value['state'] == PaymentReceipt::State_minus_one){
  816. $state = "驳回:" . $return;
  817. }else{
  818. $state = "待" . $return . "审核";
  819. }
  820. }elseif($value['state'] == PaymentReceipt::STATE_ZERO){
  821. $state = "待" . $value['crt_name'] . "提交";
  822. }else{
  823. $state = PaymentReceipt::$name[$value['state']] ?? '';
  824. }
  825. return $state;
  826. }
  827. //详情里
  828. public function getPaymentReceiptDataList($data,$type){
  829. $data['data_order_no'] = $data['order_number'];
  830. $info_array = PaymentReceiptInfo::from('payment_receipt_info as a')
  831. ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
  832. ->where('b.del_time',0)
  833. ->where('a.del_time',0)
  834. ->where('a.type',PaymentReceiptInfo::type_three)
  835. ->where('a.data_order_type',$type)
  836. ->where('a.data_order_no',$data['data_order_no'])
  837. ->select('a.payment_receipt_id','a.data_order_no','a.amount','a.data_type','b.state','b.payment_receipt_date','b.crt_time','b.order_number','b.account','b.pay_way')
  838. ->get()->toArray();
  839. $array = array_unique(array_merge_recursive(array_column($info_array,'account'),array_column($info_array,'pay_way')));
  840. $basic_map = BasicType::whereIn('id',$array)
  841. ->pluck('title','id')
  842. ->toArray();
  843. $emp_id = PaymentReceiptInfo::where('del_time',0)
  844. ->whereIn('payment_receipt_id',array_column($info_array,'payment_receipt_id'))
  845. ->where('type',PaymentReceiptInfo::type_two)
  846. ->get()->toArray();
  847. $info = [];
  848. if(! empty($emp_id)){
  849. $emp_map = Employee::whereIn('id',array_unique(array_column($emp_id,'data_id')))
  850. ->pluck('emp_name','id')
  851. ->toArray();
  852. foreach ($emp_id as $value){
  853. $name = $emp_map[$value['data_id']] ?? "";
  854. if(isset($info[$value['payment_receipt_id']])){
  855. $info[$value['payment_receipt_id']] .= ',' . $name;
  856. }else{
  857. $info[$value['payment_receipt_id']] = $name;
  858. }
  859. }
  860. }
  861. //四个金额类型
  862. $one = $two = $three = $four = $not_confirm_receipt_amount = 0;
  863. foreach ($info_array as $key => $value){
  864. //归属人
  865. $info_array[$key]['belong'] = $info[$value['payment_receipt_id']] ?? '';
  866. $info_array[$key]['account'] = $basic_map[$value['account']] ?? '';
  867. $info_array[$key]['pay_way'] = $basic_map[$value['pay_way']] ?? '';
  868. $info_array[$key]['state_title'] = PaymentReceipt::$name[$value['state']] ?? '';
  869. $info_array[$key]['type_title'] = PaymentReceipt::$model_type[$value['data_type']] ?? '';
  870. $info_array[$key]['payment_receipt_date'] = $value['payment_receipt_date'] ? date('Y-m-d',$value['payment_receipt_date']) : '';
  871. if($value['data_type'] == PaymentReceipt::type_one) $not_confirm_receipt_amount += $value['amount'];
  872. if($value['data_type'] == PaymentReceipt::type_one && $value['state'] == PaymentReceipt::STATE_TWO){
  873. $one += $value['amount'];
  874. }elseif ($value['data_type'] == PaymentReceipt::type_three && $value['state'] == PaymentReceipt::STATE_TWO){
  875. $three += $value['amount'];
  876. }
  877. }
  878. $return['receipt_amount'] = bcsub($one, $three, 2); // 已回款金额
  879. $return['not_receipt_amount'] = 0;
  880. $return['red_amount'] = $three;// 已红冲金额
  881. $return['bad_amount'] = $four;
  882. $return['all_count'] = count($info_array);
  883. $return['not_confirm_receipt_amount'] = $not_confirm_receipt_amount;
  884. $return['list'] = $info_array;
  885. return $return;
  886. }
  887. //列表里 默认:(收款)
  888. public function getPaymentReceiptDataCountList($data){
  889. $data_order_no = $data;
  890. if(empty($data_order_no)) return [];
  891. $order = PaymentReceiptInfo::from('payment_receipt_info as a')
  892. ->leftJoin('payment_receipt as b','b.id','a.payment_receipt_id')
  893. ->where('b.del_time',0)
  894. ->where('a.del_time',0)
  895. ->where('a.type',PaymentReceiptInfo::type_three)
  896. ->whereIn('a.data_order_no',$data_order_no)
  897. ->select('a.payment_receipt_id','a.data_order_no','a.amount','a.data_type','b.state','b.payment_receipt_date')
  898. ->get()->toArray();
  899. // $order = PaymentReceiptInfo::where('del_time',0)
  900. // ->where('type',PaymentReceiptInfo::type_three)
  901. // ->whereIn('data_order_no',$data_order_no)
  902. // ->get()->toArray();
  903. // 所有状态都统计 审核成功的统计
  904. $return = $return1 = [];
  905. foreach ($order as $value){
  906. $key = $value['data_order_no'] . $value['data_type'];
  907. if(isset($return[$key])){
  908. $return[$key] += $value['amount'];
  909. }else{
  910. $return[$key] = $value['amount'];
  911. }
  912. if($value['state'] == PaymentReceipt::STATE_TWO){
  913. if(isset($return1[$key])){
  914. $return1[$key] += $value['amount'];
  915. }else{
  916. $return1[$key] = $value['amount'];
  917. }
  918. }
  919. }
  920. return [$return, $return1];
  921. }
  922. public function maked(){
  923. $payment = PaymentReceipt::where('del_time',0)
  924. ->where('data_order_no','LIKE', '%'."T9SO.".'%')
  925. ->where('amount','>',0)
  926. ->get()->toArray();
  927. $insert = [];
  928. foreach ($payment as $value){
  929. $insert[] = [
  930. 'payment_receipt_id' => $value['id'],
  931. 'crt_time' => $value['crt_time'],
  932. 'type' => PaymentReceiptInfo::type_three,
  933. 'data_order_no' => $value['data_order_no'],
  934. 'amount' => $value['amount'],
  935. 'data_order_type' => $value['type'],
  936. 'data_type' => PaymentReceipt::type_one,
  937. ];
  938. }
  939. if(! empty($insert)) PaymentReceiptInfo::insert($insert);
  940. }
  941. public function checkForEdit($data_order_no = ""){
  942. if(empty($data_order_no)) return [false, '校验参数异常'];
  943. $bool = PaymentReceipt::where('data_order_no', $data_order_no)
  944. ->where('del_time',0)
  945. ->exists();
  946. if(! $bool) return [true, ''];
  947. return [false, "单号:" . $data_order_no . "已建收付款单,编辑操作有可能改变单据原始总金额导致收付款金额错乱,请先删除收付款单据!"];
  948. }
  949. }