Set.php 16 KB

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