Set.php 16 KB

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