Set.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. namespace Cash\Lib;
  3. use Dever;
  4. class Set
  5. {
  6. public function info($audit_type, $audit)
  7. {
  8. $config = Dever::db('cash/order')->config;
  9. return $config['config_audit_type'][$audit_type] . $config['config_audit'][$audit];
  10. }
  11. public function statDate($type, $day)
  12. {
  13. if ($type == 1) {
  14. $string = 'Y年m月';
  15. } elseif ($type == 2) {
  16. $string = 'Y年W周';
  17. } else {
  18. $string = 'Y年m月d日';
  19. }
  20. return date($string, $day);
  21. }
  22. public function statYes($info, $type)
  23. {
  24. $table = 'cash/' . $type;
  25. $info = is_array($info) ? $info : Dever::db($table)->one($info);
  26. $other = Dever::db($type . '/info')->find($info[$type . '_id']);
  27. if ($type == 'store') {
  28. return $this->statDate($info['type'], $info['day']) . '与'.$other['name'].'对账单数量是否正确<br />对账数量' . $info['num'] . '个';
  29. }
  30. return $this->statDate($info['type'], $info['day']) . '与'.$other['name'].'对账单款项是否正确<br />对账金额¥' . $info['cash'] . '元';
  31. }
  32. public function statTime($start, $end)
  33. {
  34. return date('Y-m-d', $start) . ' ~ ' . date('Y-m-d', $end);
  35. }
  36. public function orderUpdate($id, $name, $data)
  37. {
  38. Dever::config('base')->hook = true;
  39. $update = array();
  40. $audit = Dever::param('audit', $data);
  41. $info = Dever::db('cash/order')->one($id);
  42. if ($audit > 1 && $info['refund_id'] && $info['refund_id'] > 0) {
  43. Dever::load('shop/lib/refund')->set('buy')->action($info['refund_id'], $audit, false, false);
  44. if ($audit == 2) {
  45. Dever::db('cash/order')->update(array('where_id' => $id, 'status' => 2, 'operdate' => time(), 'fdate' => time()));
  46. }
  47. }
  48. }
  49. # 审核对账
  50. public function audit_api()
  51. {
  52. $id = Dever::input('id');
  53. $type = Dever::input('type', 'shop');
  54. $table = 'cash/' . $type;
  55. $info = Dever::db($table)->one($id);
  56. if ($info) {
  57. Dever::db($table)->update(array('where_id' => $id, 'status' => 2));
  58. }
  59. return 'reload';
  60. }
  61. # 审核对账
  62. public function audit_other_api()
  63. {
  64. $id = Dever::input('id');
  65. $type = Dever::input('type', 'shop');
  66. $table = 'cash/' . $type;
  67. $info = Dever::db($table)->one($id);
  68. if ($info) {
  69. Dever::db($table)->update(array('where_id' => $id, $type . '_status' => 2));
  70. }
  71. return 'reload';
  72. }
  73. # 查看对账单详情
  74. public function view_api()
  75. {
  76. $id = Dever::input('id');
  77. if (!$id) {
  78. return false;
  79. }
  80. $show = Dever::input('show', 1);
  81. $type = Dever::input('type', 'shop');
  82. if ($type == 'shop') {
  83. $search_option_type = 1;
  84. $name = '门店';
  85. } elseif ($type == 'store') {
  86. $search_option_type = 3;
  87. $name = '仓库';
  88. } elseif ($type == 'factory') {
  89. $search_option_type = 2;
  90. $name = '工厂';
  91. }
  92. $table = 'cash/' . $type;
  93. $config = Dever::db($table)->config;
  94. $info = Dever::db($table)->one($id);
  95. $status = $config['config_status'][$info['status']];
  96. $other_status = $config['config_status'][$info[$type . '_status']];
  97. $other = Dever::db($type . '/info')->find($info[$type . '_id']);
  98. $html = '<div class="layui-col-md12"><div class="layui-card"><div class="layui-card-header">对账单详情</div><div class="layui-card-body">';
  99. $html .= '<table class="layui-table"><tbody>';
  100. $html .= '<tr>
  101. <td width="100">对账'.$name.'</td>
  102. <td>'.$this->table(false, array(array($other['name']))).'</td>
  103. </tr>';
  104. $html .= '<tr>
  105. <td width="80">对账时间</td>
  106. <td>'.$this->table(false, array(array($this->statDate($info['type'], $info['day'])))).'</td>
  107. </tr>';
  108. $html .= '<tr>
  109. <td width="80">对账周期</td>
  110. <td>'.$this->table(false, array(array($this->statTime($info['start'], $info['end'])))).'</td>
  111. </tr>';
  112. if ($type == 'store') {
  113. $html .= '<tr>
  114. <td width="80">对账商品数量</td>
  115. <td>'.$this->table(false, array(array($info['num']))).'</td>
  116. </tr>';
  117. } else {
  118. $html .= '<tr>
  119. <td width="80">对账金额</td>
  120. <td>'.$this->table(false, array(array('¥' . round($info['cash'], 2) . '元'))).'</td>
  121. </tr>';
  122. }
  123. if ($show == 1) {
  124. $html .= '<tr>
  125. <td width="80">'.$name.'对账状态</td>
  126. <td>'.$this->table(false, array(array($other_status))).'</td>
  127. </tr>';
  128. $html .= '<tr>
  129. <td width="100">平台对账状态</td>
  130. <td>'.$this->table(false, array(array($status))).'</td>
  131. </tr>';
  132. } else {
  133. $html .= '<tr>
  134. <td width="80">对账状态</td>
  135. <td>'.$this->table(false, array(array($other_status))).'</td>
  136. </tr>';
  137. }
  138. $button = array();
  139. if ($show == 1) {
  140. if ($info['status'] == 1) {
  141. $url = Dever::url('lib/set.audit&id='.$id.'&type=' . $type, 'cash');
  142. $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $type).'\', \'请确认\')">立即确认</button>';
  143. }
  144. $config['phone'] = '联系人:' . $other['truename'] . ',联系电话:' . $other['mobile'];
  145. $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系'.$name.'</button>';
  146. $start = date('Y-m-d H:i:s', $info['start']);
  147. $end = date('Y-m-d H:i:s', $info['end']);
  148. $out = Dever::url('lib/set.excel?id=' . $info['id'] . '&type=' . $type, 'cash');
  149. $button[] = '<a class="layui-btn layui-btn-primary" href="'.$out.'">导出对账单</a>';
  150. } elseif ($show == 2) {
  151. if ($info[$type . '_status'] == 1 && $show != 1) {
  152. $url = Dever::url('lib/set.audit_other&id='.$id.'&type=' . $type, 'cash');
  153. $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $type).'\', \'请确认\')">立即确认</button>';
  154. }
  155. $config = Dever::load('factory/admin/auth.config');
  156. $config['phone'] = '联系电话:' . $config['dz_phone'];
  157. $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系对账专员</button>';
  158. $print = Dever::url('admin/stat.print?id=' . $info['id'] . '&type=' . $type, $type);
  159. $button[] = '<a class="layui-btn layui-btn-primary" href="'.$print.'" target="_blank">打印对账单</a>';
  160. }
  161. $html .= '<tr>
  162. <td>功能按钮</td>
  163. <td>'.$this->table(false, array($button)).'</td>
  164. </tr>';
  165. $html .= '</tbody></table></div></div>';
  166. $id = $info[$type . '_id'];
  167. if ($type == 'shop') {
  168. $where['type'] = 1;
  169. $where['type_id'] = $id;
  170. $m = 'getAll';
  171. } elseif ($type == 'factory') {
  172. $where['source_type'] = 3;
  173. $where['source_id'] = $id;
  174. $m = 'getAll';
  175. } else {
  176. $where['type'] = 2;
  177. $where['type_id'] = $id;
  178. $where['source_type'] = 2;
  179. $where['source_id'] = $id;
  180. $m = 'getAllByStore';
  181. }
  182. $where['status'] = 2;
  183. $where['start'] = $info['start'];
  184. $where['end'] = $info['end'];
  185. $data = Dever::db('cash/order')->$m($where);
  186. if ($data) {
  187. $body = array();
  188. $config = Dever::db('cash/order')->config;
  189. foreach ($data as $k => $v) {
  190. $cdate = date('Y-m-d H:i', $v['cdate']);
  191. $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
  192. $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
  193. if ($type == 'store') {
  194. $cash = $v['num'];
  195. } elseif ($type == 'factory') {
  196. $cash = '¥' . round($v['p_cash'], 2);
  197. } else {
  198. $cash = '¥' . round($v['cash'], 2);
  199. }
  200. if ($show == 1) {
  201. $url = Dever::url('project/database/list?project=shop&table=buy_order_goods&order_id='.$v['source_order_id'].'&page_type=1&type=' . $search_option_type, 'manage');
  202. $v['source_order_num'] = '<a href="'.$url.'" style="color:blue">'.$v['source_order_num'].'</a>';
  203. $head = array('结算单号', '订货单号', '结算类型', '下单日期', '完成日期', '结算日期', '对账金额', '结算状态');
  204. if ($type == 'store') {
  205. $head[6] = '对账数量';
  206. }
  207. $body[] = array
  208. (
  209. $v['order_num'],
  210. $v['source_order_num'],
  211. $config['config_jstype'][$v['jstype']],
  212. $cdate,
  213. $fdate,
  214. $operdate,
  215. $cash,
  216. '已入账'
  217. );
  218. } else {
  219. $head = array('订货单号', '下单日期', '完成日期', '对账金额', '状态');
  220. if ($type == 'store') {
  221. $head[3] = '对账数量';
  222. }
  223. $body[] = array
  224. (
  225. $v['source_order_num'],
  226. $cdate,
  227. $fdate,
  228. $cash,
  229. '已入账'
  230. );
  231. }
  232. }
  233. $page = Dever::page("current");
  234. $html .= '<div class="layui-card"><div class="layui-card-header">对账清单</div><div class="layui-card-body" style="max-heights: 500px;overflow: auto;">' . $this->table($head, $body) . $page . '</div></div>';
  235. }
  236. $html .= '</div>';
  237. return '<div class="layui-card-body">' . $html . '</div>';
  238. }
  239. private function table($head, $data)
  240. {
  241. $html = '';
  242. if ($head) {
  243. $html = '<table class="layui-table">';
  244. $html .= '<thead><tr>';
  245. foreach ($head as $k => $v) {
  246. $html .= '<th>'.$v.'</th>';
  247. }
  248. $html .= '</tr></thead>';
  249. $html .= '<tbody>';
  250. foreach ($data as $k => $v) {
  251. $html .= '<tr>';
  252. foreach ($v as $k1 => $v1) {
  253. $html .= '<td>'.$v1.'</td>';
  254. }
  255. $html .= '</tr>';
  256. }
  257. $html .= '</tbody>';
  258. $html .= '</table>';
  259. } else {
  260. foreach ($data as $k => $v) {
  261. $html .= '';
  262. foreach ($v as $k1 => $v1) {
  263. $html .= $v1 . '&nbsp;&nbsp;&nbsp;&nbsp;';
  264. }
  265. $html .= '';
  266. }
  267. }
  268. return $html;
  269. }
  270. # 导出对账单
  271. public function excel_api()
  272. {
  273. $type = Dever::input('type');
  274. $id = Dever::input('id');
  275. $table = 'cash/' . $type;
  276. $config = Dever::db($table)->config;
  277. $info = Dever::db($table)->one($id);
  278. $id = $info[$type . '_id'];
  279. if ($type == 'shop') {
  280. $where['type'] = 1;
  281. $where['type_id'] = $id;
  282. $m = 'getAllNoPage';
  283. } elseif ($type == 'factory') {
  284. $where['source_type'] = 3;
  285. $where['source_id'] = $id;
  286. $m = 'getAllNoPage';
  287. } else {
  288. $where['type'] = 2;
  289. $where['type_id'] = $id;
  290. $where['source_type'] = 2;
  291. $where['source_id'] = $id;
  292. $m = 'getAllByStoreNoPage';
  293. }
  294. $where['status'] = 2;
  295. $where['start'] = $info['start'];
  296. $where['end'] = $info['end'];
  297. $data = Dever::db('cash/order')->$m($where);
  298. $stat_type = Dever::db('cash/shop')->config['config_type'];
  299. $other = Dever::db($type . '/info')->find($id);
  300. $status = $config['config_status'][$info['status']];
  301. $other_status = $config['config_status'][$info[$type . '_status']];
  302. $info['name'] = Dever::load('cash/lib/set')->statDate($stat_type, $info['day']);
  303. $info['status_name'] = $status;
  304. $file = $other['name'] . '的' . $info['name'] . '对账单';
  305. $header = $body = array();
  306. $header = array
  307. (
  308. 'top' => array
  309. (
  310. $file . ' ' . $info['status_name'] . ' 对账金额¥' . $info['cash'],
  311. ),
  312. '结算单号',
  313. '订货单号',
  314. '结算类型',
  315. '下单日期',
  316. '完成日期',
  317. '结算日期',
  318. '对账金额',
  319. '结算状态',
  320. );
  321. if ($type == 'store') {
  322. $head[6] = '对账数量';
  323. }
  324. if ($data) {
  325. $body = array();
  326. foreach ($data as $k => $v) {
  327. $cdate = date('Y-m-d H:i', $v['cdate']);
  328. $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
  329. $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
  330. if ($type == 'store') {
  331. $cash = $v['num'];
  332. } elseif ($type == 'factory') {
  333. $cash = '¥' . round($v['p_cash'], 2);
  334. } else {
  335. $cash = '¥' . round($v['cash'], 2);
  336. }
  337. $jstype = Dever::db('cash/order')->config['config_jstype'][$v['jstype']];
  338. $body[$k][0] = $v['order_num'];
  339. $body[$k][1] = $v['source_order_num'];
  340. $body[$k][2] = $jstype;
  341. $body[$k][3] = $cdate;
  342. $body[$k][4] = $operdate;
  343. $body[$k][5] = $fdate;
  344. $body[$k][6] = $cash;
  345. $body[$k][7] = '已入账';
  346. }
  347. }
  348. Dever::excelExport($body, $header, $file);
  349. }
  350. # 打印订单单
  351. public function printer($user)
  352. {
  353. $id = Dever::input('id');
  354. if (!$id) {
  355. return false;
  356. }
  357. $type = Dever::input('type', 'shop');
  358. if ($type == 'shop') {
  359. $name = '门店';
  360. } elseif ($type == 'store') {
  361. $name = '仓库';
  362. } elseif ($type == 'factory') {
  363. $name = '工厂';
  364. }
  365. $table = 'cash/' . $type;
  366. $config = Dever::db($table)->config;
  367. $info = Dever::db($table)->one($id);
  368. $status = $config['config_status'][$info['status']];
  369. $other_status = $config['config_status'][$info[$type . '_status']];
  370. $other = Dever::db($type . '/info')->find($info[$type . '_id']);
  371. $member = Dever::db($type . '/member')->find($user['id']);
  372. $factory_config = Dever::db('main/factory_config')->find();
  373. $main_config = Dever::db('main/config')->find();
  374. $pdf = Dever::load('pdf/lib/base')->init();
  375. $pdf->hr('-', $other['name']);
  376. $pdf->br()->font(20)->center('对账周期:' . $this->statTime($info['start'], $info['end']));
  377. $pdf->font(10);
  378. $pdf->br();
  379. $pdf->br()->left('对账日期:' . $this->statDate($info['type'], $info['day']), 80)->left('制单人:' . $member['name'], 60)->left('制单时间:' . date('Y-m-d H:i'), 40);
  380. $pdf->hr();
  381. if ($type == 'store') {
  382. $where['type'] = 2;
  383. $where['type_id'] = $info[$type . '_id'];
  384. } else {
  385. $where['source_type'] = 3;
  386. $where['source_id'] = $info[$type . '_id'];
  387. }
  388. $where['status'] = 2;
  389. $where['start'] = $info['start'];
  390. $where['end'] = $info['end'];
  391. $data = Dever::db('cash/order')->getAll($where);
  392. $body = array();
  393. $body_total = array();
  394. $body_total['cash'] = 0;
  395. $body_total['num'] = 0;
  396. if ($data) {
  397. foreach ($data as $k => $v) {
  398. $cdate = date('Y-m-d H:i', $v['cdate']);
  399. $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
  400. $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
  401. $prefix = '¥';
  402. if ($type == 'store') {
  403. $cash = $v['num'];
  404. $prefix = '';
  405. } elseif ($type == 'factory') {
  406. $cash = $v['p_cash'];
  407. } else {
  408. $cash = $v['cash'];
  409. }
  410. $cash = round($cash, 2);
  411. $body[] = array
  412. (
  413. $v['source_order_num'],
  414. $cdate,
  415. $fdate,
  416. $prefix . $cash,
  417. '已入账'
  418. );
  419. $body_total['cash'] += $cash;
  420. $body_total['num'] += 1;
  421. }
  422. }
  423. $head = array(array('订单号', 60), array('下单日期', 43), array('完成日期', 43), array('对账金额', 30), array('状态', 20));
  424. if ($type == 'store') {
  425. $head[3][0] = '对账数量';
  426. }
  427. if ($body) {
  428. $pdf->br();
  429. foreach ($head as $k => $v) {
  430. $pdf->left($v[0], $v[1]);
  431. }
  432. foreach ($body as $k => $v) {
  433. $pdf->br();
  434. foreach ($head as $k1 => $v1) {
  435. $pdf->left($v[$k1], $v1[1]);
  436. }
  437. }
  438. $pdf->br();
  439. if ($type == 'store') {
  440. $pdf->right('共'.$body_total['num'].'个订单,合计对账数量' . $body_total['cash'] . '个');
  441. } else {
  442. $pdf->right('共'.$body_total['num'].'个订单,合计对账金额¥' . $body_total['cash'] . '元');
  443. }
  444. $pdf->hr();
  445. }
  446. $pdf->br(1);
  447. //$pdf->SetY(-100);
  448. $pdf->right('如遇任何问题请致电客服');
  449. $pdf->br();
  450. $pdf->font(20);
  451. $pdf->left($main_config['name'], 160);
  452. $pdf->font(10);
  453. $pdf->right('电话:' . $factory_config['phone'], 30);
  454. $pdf->br();
  455. $pdf->left($main_config['site'], 160);
  456. $pdf->font(10);
  457. $pdf->right($main_config['worktime'], 30);
  458. $pdf->out('对账单');
  459. }
  460. }