Set.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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="80">对账'.$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->statTime($info['start'], $info['end'])))).'</td>
  99. </tr>';
  100. if ($type == 'store') {
  101. $html .= '<tr>
  102. <td width="80">对账商品数量</td>
  103. <td>'.$this->table(false, array(array($info['num']))).'</td>
  104. </tr>';
  105. } else {
  106. $html .= '<tr>
  107. <td width="80">对账金额</td>
  108. <td>'.$this->table(false, array(array('¥' . $info['cash'] . '元'))).'</td>
  109. </tr>';
  110. }
  111. if ($show == 1) {
  112. $html .= '<tr>
  113. <td width="80">'.$name.'对账状态</td>
  114. <td>'.$this->table(false, array(array($other_status))).'</td>
  115. </tr>';
  116. $html .= '<tr>
  117. <td width="100">平台对账状态</td>
  118. <td>'.$this->table(false, array(array($status))).'</td>
  119. </tr>';
  120. } else {
  121. $html .= '<tr>
  122. <td width="80">对账状态</td>
  123. <td>'.$this->table(false, array(array($other_status))).'</td>
  124. </tr>';
  125. }
  126. $button = array();
  127. if ($show == 1) {
  128. if ($info['status'] == 1) {
  129. $url = Dever::url('lib/set.audit&id='.$id.'&type=' . $type, 'cash');
  130. $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $type).'\', \'请确认\')">立即确认</button>';
  131. }
  132. $config['phone'] = '联系人:' . $other['truename'] . ',联系电话:' . $other['mobile'];
  133. $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系'.$name.'</button>';
  134. $info['start'] = date('Y-m-d H:i:s', $info['start']);
  135. $info['end'] = date('Y-m-d H:i:s', $info['end']);
  136. $out = Dever::url('database.list_excel?project=cash&table=order&search_option_status=2&search_option_state=1&search_option_start_cdate=' . $info['start'] . '&search_option_end_cdate=' . $info['end'], 'manage');
  137. $button[] = '<a class="layui-btn layui-btn-primary" href="'.$out.'">导出对账单</a>';
  138. } else {
  139. if ($info[$type . '_status'] == 1 && $show != 1) {
  140. $url = Dever::url('lib/set.audit_other&id='.$id.'&type=' . $type, 'cash');
  141. $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\', \''.$this->statYes($info, $type).'\', \'请确认\')">立即确认</button>';
  142. }
  143. $config = Dever::load('factory/admin/auth.config');
  144. $config['phone'] = '联系电话:' . $config['dz_phone'];
  145. $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系对账专员</button>';
  146. $info['start'] = date('Y-m-d H:i:s', $info['start']);
  147. $info['end'] = date('Y-m-d H:i:s', $info['end']);
  148. $button[] = '<a class="layui-btn layui-btn-primary" onclick="print(\''.$info['id'].'\')">打印对账单</a>';
  149. }
  150. $html .= '<tr>
  151. <td>功能按钮</td>
  152. <td>'.$this->table(false, array($button)).'</td>
  153. </tr>';
  154. $html .= '</tbody></table></div></div>';
  155. $where['type'] = 1;
  156. $where['type_id'] = $info[$type . '_id'];
  157. $where['status'] = 2;
  158. $data = Dever::db('cash/order')->select_page($where);
  159. if ($data) {
  160. $head = array('结算单号', '订货单号', '结算类型', '下单日期', '完成日期', '结算日期', '对账金额', '结算状态');
  161. if ($type == 'store') {
  162. $head[6] = '对账数量';
  163. }
  164. $body = array();
  165. $config = Dever::db('cash/order')->config;
  166. foreach ($data as $k => $v) {
  167. $cdate = date('Y-m-d H:i', $v['cdate']);
  168. $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
  169. $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
  170. if ($type == 'store') {
  171. $cash = $v['num'];
  172. } elseif ($type == 'factory') {
  173. $cash = $v['p_cash'];
  174. } else {
  175. $cash = $v['cash'];
  176. }
  177. if ($show == 1) {
  178. $url = Dever::url('project/database/list?project=shop&table=buy_order_goods&order_id='.$v['source_order_id'].'&page_type=1', 'manage');
  179. $v['source_order_num'] = '<a href="'.$url.'" style="color:blue">'.$v['source_order_num'].'</a>';
  180. }
  181. $body[] = array
  182. (
  183. $v['order_num'],
  184. $v['source_order_num'],
  185. $config['config_jstype'][$v['jstype']],
  186. $cdate,
  187. $fdate,
  188. $operdate,
  189. $cash,
  190. '已入账'
  191. );
  192. }
  193. $page = Dever::page("current");
  194. $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>';
  195. }
  196. $html .= '</div>';
  197. return '<div class="layui-card-body">' . $html . '</div>';
  198. }
  199. private function table($head, $data)
  200. {
  201. $html = '';
  202. if ($head) {
  203. $html = '<table class="layui-table">';
  204. $html .= '<thead><tr>';
  205. foreach ($head as $k => $v) {
  206. $html .= '<th>'.$v.'</th>';
  207. }
  208. $html .= '</tr></thead>';
  209. $html .= '<tbody>';
  210. foreach ($data as $k => $v) {
  211. $html .= '<tr>';
  212. foreach ($v as $k1 => $v1) {
  213. $html .= '<td>'.$v1.'</td>';
  214. }
  215. $html .= '</tr>';
  216. }
  217. $html .= '</tbody>';
  218. $html .= '</table>';
  219. } else {
  220. foreach ($data as $k => $v) {
  221. $html .= '';
  222. foreach ($v as $k1 => $v1) {
  223. $html .= $v1 . '&nbsp;&nbsp;&nbsp;&nbsp;';
  224. }
  225. $html .= '';
  226. }
  227. }
  228. return $html;
  229. }
  230. }