Set.php 18 KB

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