Set.php 16 KB

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