Set.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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. } elseif ($type == 'factory') {
  283. $where['source_type'] = 3;
  284. $where['source_id'] = $id;
  285. } else {
  286. $where['type'] = 2;
  287. $where['type_id'] = $id;
  288. //$where['source_type_or'] = 2;
  289. //$where['source_id_or'] = $id;
  290. }
  291. $where['status'] = 2;
  292. $where['start'] = $info['start'];
  293. $where['end'] = $info['end'];
  294. $data = Dever::db('cash/order')->getAll($where);
  295. $stat_type = Dever::db('cash/shop')->config['config_type'];
  296. $other = Dever::db($type . '/info')->find($id);
  297. $status = $config['config_status'][$info['status']];
  298. $other_status = $config['config_status'][$info[$type . '_status']];
  299. $info['name'] = Dever::load('cash/lib/set')->statDate($stat_type, $info['day']);
  300. $info['status_name'] = $status;
  301. $file = $other['name'] . '的' . $info['name'] . '对账单';
  302. $header = $body = array();
  303. $header = array
  304. (
  305. 'top' => array
  306. (
  307. $file . ' ' . $info['status_name'] . ' 对账金额¥' . $info['cash'],
  308. ),
  309. '结算单号',
  310. '订货单号',
  311. '结算类型',
  312. '下单日期',
  313. '完成日期',
  314. '结算日期',
  315. '对账金额',
  316. '结算状态',
  317. );
  318. if ($type == 'store') {
  319. $head[6] = '对账数量';
  320. }
  321. if ($data) {
  322. $body = array();
  323. foreach ($data as $k => $v) {
  324. $cdate = date('Y-m-d H:i', $v['cdate']);
  325. $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
  326. $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
  327. if ($type == 'store') {
  328. $cash = $v['num'];
  329. } elseif ($type == 'factory') {
  330. $cash = '¥' . round($v['p_cash'], 2);
  331. } else {
  332. $cash = '¥' . round($v['cash'], 2);
  333. }
  334. $jstype = Dever::db('cash/order')->config['config_jstype'][$v['jstype']];
  335. $body[$k][0] = $v['order_num'];
  336. $body[$k][1] = $v['source_order_num'];
  337. $body[$k][2] = $jstype;
  338. $body[$k][3] = $cdate;
  339. $body[$k][4] = $operdate;
  340. $body[$k][5] = $fdate;
  341. $body[$k][6] = $cash;
  342. $body[$k][7] = '已入账';
  343. }
  344. }
  345. Dever::excelExport($body, $header, $file);
  346. }
  347. # 打印订单单
  348. public function printer($user)
  349. {
  350. $id = Dever::input('id');
  351. if (!$id) {
  352. return false;
  353. }
  354. $type = Dever::input('type', 'shop');
  355. if ($type == 'shop') {
  356. $name = '门店';
  357. } elseif ($type == 'store') {
  358. $name = '仓库';
  359. } elseif ($type == 'factory') {
  360. $name = '工厂';
  361. }
  362. $table = 'cash/' . $type;
  363. $config = Dever::db($table)->config;
  364. $info = Dever::db($table)->one($id);
  365. $status = $config['config_status'][$info['status']];
  366. $other_status = $config['config_status'][$info[$type . '_status']];
  367. $other = Dever::db($type . '/info')->find($info[$type . '_id']);
  368. $member = Dever::db($type . '/member')->find($user['id']);
  369. $factory_config = Dever::db('main/factory_config')->find();
  370. $main_config = Dever::db('main/config')->find();
  371. $pdf = Dever::load('pdf/lib/base')->init();
  372. $pdf->hr('-', $other['name']);
  373. $pdf->br()->font(20)->center('对账周期:' . $this->statTime($info['start'], $info['end']));
  374. $pdf->font(10);
  375. $pdf->br();
  376. $pdf->br()->left('对账日期:' . $this->statDate($info['type'], $info['day']), 80)->left('制单人:' . $member['name'], 60)->left('制单时间:' . date('Y-m-d H:i'), 40);
  377. $pdf->hr();
  378. if ($type == 'store') {
  379. $where['type'] = 2;
  380. $where['type_id'] = $info[$type . '_id'];
  381. } else {
  382. $where['source_type'] = 3;
  383. $where['source_id'] = $info[$type . '_id'];
  384. }
  385. $where['status'] = 2;
  386. $where['start'] = $info['start'];
  387. $where['end'] = $info['end'];
  388. $data = Dever::db('cash/order')->getAll($where);
  389. $body = array();
  390. $body_total = array();
  391. $body_total['cash'] = 0;
  392. $body_total['num'] = 0;
  393. if ($data) {
  394. foreach ($data as $k => $v) {
  395. $cdate = date('Y-m-d H:i', $v['cdate']);
  396. $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
  397. $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
  398. $prefix = '¥';
  399. if ($type == 'store') {
  400. $cash = $v['num'];
  401. $prefix = '';
  402. } elseif ($type == 'factory') {
  403. $cash = $v['p_cash'];
  404. } else {
  405. $cash = $v['cash'];
  406. }
  407. $cash = round($cash, 2);
  408. $body[] = array
  409. (
  410. $v['source_order_num'],
  411. $cdate,
  412. $fdate,
  413. $prefix . $cash,
  414. '已入账'
  415. );
  416. $body_total['cash'] += $cash;
  417. $body_total['num'] += 1;
  418. }
  419. }
  420. $head = array(array('订单号', 60), array('下单日期', 43), array('完成日期', 43), array('对账金额', 30), array('状态', 20));
  421. if ($type == 'store') {
  422. $head[3][0] = '对账数量';
  423. }
  424. if ($body) {
  425. $pdf->br();
  426. foreach ($head as $k => $v) {
  427. $pdf->left($v[0], $v[1]);
  428. }
  429. foreach ($body as $k => $v) {
  430. $pdf->br();
  431. foreach ($head as $k1 => $v1) {
  432. $pdf->left($v[$k1], $v1[1]);
  433. }
  434. }
  435. $pdf->br();
  436. if ($type == 'store') {
  437. $pdf->right('共'.$body_total['num'].'个订单,合计对账数量' . $body_total['cash'] . '个');
  438. } else {
  439. $pdf->right('共'.$body_total['num'].'个订单,合计对账金额¥' . $body_total['cash'] . '元');
  440. }
  441. $pdf->hr();
  442. }
  443. $pdf->br(1);
  444. //$pdf->SetY(-100);
  445. $pdf->right('如遇任何问题请致电客服');
  446. $pdf->br();
  447. $pdf->font(20);
  448. $pdf->left($main_config['name'], 160);
  449. $pdf->font(10);
  450. $pdf->right('电话:' . $factory_config['phone'], 30);
  451. $pdf->br();
  452. $pdf->left($main_config['site'], 160);
  453. $pdf->font(10);
  454. $pdf->right($main_config['worktime'], 30);
  455. $pdf->out('对账单');
  456. }
  457. }