Set.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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. $noprice = 2;
  194. if ($type == 'store') {
  195. $cash = $v['num'];
  196. $noprice = 1;
  197. } elseif ($type == 'factory') {
  198. $cash = '¥' . round($v['p_cash'], 2);
  199. } else {
  200. $cash = '¥' . round($v['cash'], 2);
  201. }
  202. if ($show == 1) {
  203. $url = Dever::url('project/database/list?project=shop&table=buy_order_goods&order_id='.$v['source_order_id'].'&page_type=1&noprice=' . $noprice, 'manage');
  204. $v['source_order_num'] = '<a href="'.$url.'" style="color:blue">'.$v['source_order_num'].'</a>';
  205. $head = array('结算单号', '订货单号', '结算类型', '下单日期', '完成日期', '结算日期', '对账金额', '结算状态');
  206. if ($type == 'store') {
  207. $head[6] = '对账数量';
  208. }
  209. $body[] = array
  210. (
  211. $v['order_num'],
  212. $v['source_order_num'],
  213. $config['config_jstype'][$v['jstype']],
  214. $cdate,
  215. $fdate,
  216. $operdate,
  217. $cash,
  218. '已入账'
  219. );
  220. } else {
  221. $head = array('订货单号', '下单日期', '完成日期', '对账金额', '状态');
  222. if ($type == 'store') {
  223. $head[3] = '对账数量';
  224. }
  225. $body[] = array
  226. (
  227. $v['source_order_num'],
  228. $cdate,
  229. $fdate,
  230. $cash,
  231. '已入账'
  232. );
  233. }
  234. }
  235. $page = Dever::page("current");
  236. $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>';
  237. }
  238. $html .= '</div>';
  239. return '<div class="layui-card-body">' . $html . '</div>';
  240. }
  241. private function table($head, $data)
  242. {
  243. $html = '';
  244. if ($head) {
  245. $html = '<table class="layui-table">';
  246. $html .= '<thead><tr>';
  247. foreach ($head as $k => $v) {
  248. $html .= '<th>'.$v.'</th>';
  249. }
  250. $html .= '</tr></thead>';
  251. $html .= '<tbody>';
  252. foreach ($data as $k => $v) {
  253. $html .= '<tr>';
  254. foreach ($v as $k1 => $v1) {
  255. $html .= '<td>'.$v1.'</td>';
  256. }
  257. $html .= '</tr>';
  258. }
  259. $html .= '</tbody>';
  260. $html .= '</table>';
  261. } else {
  262. foreach ($data as $k => $v) {
  263. $html .= '';
  264. foreach ($v as $k1 => $v1) {
  265. $html .= $v1 . '&nbsp;&nbsp;&nbsp;&nbsp;';
  266. }
  267. $html .= '';
  268. }
  269. }
  270. return $html;
  271. }
  272. # 导出对账单
  273. public function excel_api()
  274. {
  275. $type = Dever::input('type');
  276. $id = Dever::input('id');
  277. $table = 'cash/' . $type;
  278. $config = Dever::db($table)->config;
  279. $info = Dever::db($table)->one($id);
  280. $id = $info[$type . '_id'];
  281. if ($type == 'shop') {
  282. $where['type'] = 1;
  283. $where['type_id'] = $id;
  284. $m = 'getAllNoPage';
  285. } elseif ($type == 'factory') {
  286. $where['source_type'] = 3;
  287. $where['source_id'] = $id;
  288. $m = 'getAllNoPage';
  289. } else {
  290. $where['type'] = 2;
  291. $where['type_id'] = $id;
  292. $where['source_type'] = 2;
  293. $where['source_id'] = $id;
  294. $m = 'getAllByStoreNoPage';
  295. }
  296. $where['status'] = 2;
  297. $where['start'] = $info['start'];
  298. $where['end'] = $info['end'];
  299. $data = Dever::db('cash/order')->$m($where);
  300. $stat_type = Dever::db('cash/shop')->config['config_type'];
  301. $other = Dever::db($type . '/info')->find($id);
  302. $status = $config['config_status'][$info['status']];
  303. $other_status = $config['config_status'][$info[$type . '_status']];
  304. $info['name'] = Dever::load('cash/lib/set')->statDate($stat_type, $info['day']);
  305. $info['status_name'] = $status;
  306. $file = $other['name'] . '的' . $info['name'] . '对账单';
  307. $header = $body = array();
  308. $header = array
  309. (
  310. 'top' => array
  311. (
  312. $file . ' ' . $info['status_name'] . ' 对账金额¥' . $info['cash'],
  313. ),
  314. '结算单号',
  315. '订货单号',
  316. '结算类型',
  317. '下单日期',
  318. '完成日期',
  319. '结算日期',
  320. '对账金额',
  321. '结算状态',
  322. );
  323. if ($type == 'store') {
  324. $head[6] = '对账数量';
  325. }
  326. if ($data) {
  327. $body = array();
  328. foreach ($data as $k => $v) {
  329. $cdate = date('Y-m-d H:i', $v['cdate']);
  330. $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
  331. $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
  332. if ($type == 'store') {
  333. $cash = $v['num'];
  334. } elseif ($type == 'factory') {
  335. $cash = '¥' . round($v['p_cash'], 2);
  336. } else {
  337. $cash = '¥' . round($v['cash'], 2);
  338. }
  339. $jstype = Dever::db('cash/order')->config['config_jstype'][$v['jstype']];
  340. $body[$k][0] = $v['order_num'];
  341. $body[$k][1] = $v['source_order_num'];
  342. $body[$k][2] = $jstype;
  343. $body[$k][3] = $cdate;
  344. $body[$k][4] = $operdate;
  345. $body[$k][5] = $fdate;
  346. $body[$k][6] = $cash;
  347. $body[$k][7] = '已入账';
  348. }
  349. }
  350. Dever::excelExport($body, $header, $file);
  351. }
  352. # 打印订单单
  353. public function printer($user)
  354. {
  355. $id = Dever::input('id');
  356. if (!$id) {
  357. return false;
  358. }
  359. $type = Dever::input('type', 'shop');
  360. if ($type == 'shop') {
  361. $name = '门店';
  362. } elseif ($type == 'store') {
  363. $name = '仓库';
  364. } elseif ($type == 'factory') {
  365. $name = '工厂';
  366. }
  367. $table = 'cash/' . $type;
  368. $config = Dever::db($table)->config;
  369. $info = Dever::db($table)->one($id);
  370. $status = $config['config_status'][$info['status']];
  371. $other_status = $config['config_status'][$info[$type . '_status']];
  372. $other = Dever::db($type . '/info')->find($info[$type . '_id']);
  373. $member = Dever::db($type . '/member')->find($user['id']);
  374. $factory_config = Dever::db('main/factory_config')->find();
  375. $main_config = Dever::db('main/config')->find();
  376. $pdf = Dever::load('pdf/lib/base')->init();
  377. $pdf->hr('-', $other['name']);
  378. $pdf->br()->font(20)->center('对账周期:' . $this->statTime($info['start'], $info['end']));
  379. $pdf->font(10);
  380. $pdf->br();
  381. $pdf->br()->left('对账日期:' . $this->statDate($info['type'], $info['day']), 80)->left('制单人:' . $member['name'], 60)->left('制单时间:' . date('Y-m-d H:i'), 40);
  382. $pdf->hr();
  383. if ($type == 'store') {
  384. $where['type'] = 2;
  385. $where['type_id'] = $info[$type . '_id'];
  386. } else {
  387. $where['source_type'] = 3;
  388. $where['source_id'] = $info[$type . '_id'];
  389. }
  390. $where['status'] = 2;
  391. $where['start'] = $info['start'];
  392. $where['end'] = $info['end'];
  393. $data = Dever::db('cash/order')->getAll($where);
  394. $body = array();
  395. $body_total = array();
  396. $body_total['cash'] = 0;
  397. $body_total['num'] = 0;
  398. if ($data) {
  399. foreach ($data as $k => $v) {
  400. $cdate = date('Y-m-d H:i', $v['cdate']);
  401. $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
  402. $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
  403. $prefix = '¥';
  404. if ($type == 'store') {
  405. $cash = $v['num'];
  406. $prefix = '';
  407. } elseif ($type == 'factory') {
  408. $cash = $v['p_cash'];
  409. } else {
  410. $cash = $v['cash'];
  411. }
  412. $cash = round($cash, 2);
  413. $body[] = array
  414. (
  415. $v['source_order_num'],
  416. $cdate,
  417. $fdate,
  418. $prefix . $cash,
  419. '已入账'
  420. );
  421. $body_total['cash'] += $cash;
  422. $body_total['num'] += 1;
  423. }
  424. }
  425. $head = array(array('订单号', 60), array('下单日期', 43), array('完成日期', 43), array('对账金额', 30), array('状态', 20));
  426. if ($type == 'store') {
  427. $head[3][0] = '对账数量';
  428. }
  429. if ($body) {
  430. $pdf->br();
  431. foreach ($head as $k => $v) {
  432. $pdf->left($v[0], $v[1]);
  433. }
  434. foreach ($body as $k => $v) {
  435. $pdf->br();
  436. foreach ($head as $k1 => $v1) {
  437. $pdf->left($v[$k1], $v1[1]);
  438. }
  439. }
  440. $pdf->br();
  441. if ($type == 'store') {
  442. $pdf->right('共'.$body_total['num'].'个订单,合计对账数量' . $body_total['cash'] . '个');
  443. } else {
  444. $pdf->right('共'.$body_total['num'].'个订单,合计对账金额¥' . $body_total['cash'] . '元');
  445. }
  446. $pdf->hr();
  447. }
  448. $pdf->br(1);
  449. //$pdf->SetY(-100);
  450. $pdf->right('如遇任何问题请致电客服');
  451. $pdf->br();
  452. $pdf->font(20);
  453. $pdf->left($main_config['name'], 160);
  454. $pdf->font(10);
  455. $pdf->right('电话:' . $factory_config['phone'], 30);
  456. $pdf->br();
  457. $pdf->left($main_config['site'], 160);
  458. $pdf->font(10);
  459. $pdf->right($main_config['worktime'], 30);
  460. $pdf->out('对账单');
  461. }
  462. }