Out.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace store\Admin;
  3. use Dever;
  4. class Out extends Core
  5. {
  6. # 订单列表
  7. public function getList()
  8. {
  9. $data = Dever::load('mshop/lib/out')->set(2, 1)->getList($this->id);
  10. $html = '';
  11. $excel = Dever::input('excel', 1);
  12. if ($data && $data['order']) {
  13. if ($excel == 2) {
  14. Dever::load('mshop/lib/out')->set(2, 1)->excel($data['order']);
  15. die;
  16. return;
  17. }
  18. foreach ($data['order'] as $k => $v) {
  19. $view = Dever::url('out_view?order_id=' . $v['id'] . '&type=2', 'store');
  20. $button = '<a href="'.$view.'"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">查看详情</button></a>';
  21. if ($v['status'] == 1) {
  22. $url = Dever::url('admin/out.cancel&order_id='.$v['id'], 'store');
  23. $button .= '&nbsp;&nbsp;<a href="javascript:;" onclick="load(\''.$url.'\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">取消</button></a>';
  24. }
  25. $url = Dever::url('lib/out.excel_one?type='.$v['type'].'&id='.$v['id'], 'mshop');
  26. $button .= '&nbsp;&nbsp;<a href="'.$url.'"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 layui-btn layui-btn-xs">导出</button></a>';
  27. $html .= '<tr><td>'.$v['order_num'].'</td><td>'.$v['cdate'].'</td><td>'.$v['type_name'].'</td><td>'.$v['price'].'</td><td>'.$v['num'].'</td><td>'.$v['status_name'].'</td><td>'.$button.'</td></tr>';
  28. }
  29. }
  30. return $html;
  31. }
  32. # 获取列表页搜索信息
  33. public function getStatus()
  34. {
  35. $type = Dever::db('shop/out_order')->config['config_status'];
  36. $config = array
  37. (
  38. array('value' => '0', 'name' => '全部')
  39. );
  40. foreach ($type as $k => $v) {
  41. $config[] = array('value' => $k, 'name' => $v);
  42. }
  43. $status = Dever::input('status');
  44. $html = '';
  45. foreach ($config as $k => $v) {
  46. $selected = '';
  47. if ((!$status && $k == 0) || $status == $v['value']) {
  48. $selected = 'selected=""';
  49. }
  50. $html .= '<option value="'.$v['value'].'" '.$selected.'>'.$v['name'].'</option>';
  51. }
  52. return $html;
  53. }
  54. # 获取列表页搜索信息
  55. public function getType($state = 1)
  56. {
  57. $type = Dever::db('shop/out_order')->config['config_type'];
  58. $type = $type();
  59. $config = array
  60. (
  61. array('value' => '0', 'name' => '全部'),
  62. );
  63. foreach ($type as $k => $v) {
  64. if ($v['type'] != 1) {
  65. $config[] = array('value' => $k, 'name' => $v['name']);
  66. }
  67. }
  68. if ($state == 2) {
  69. unset($config[0]);
  70. }
  71. $out_type = Dever::input('out_type');
  72. $html = '';
  73. foreach ($config as $k => $v) {
  74. $selected = '';
  75. if ((!$out_type && $k == 0) || $out_type == $v['value']) {
  76. $selected = 'selected=""';
  77. }
  78. $html .= '<option value="'.$v['value'].'" '.$selected.'>'.$v['name'].'</option>';
  79. }
  80. return $html;
  81. }
  82. # 获取基本信息
  83. public function getConfig()
  84. {
  85. $data['search'] = Dever::url('out', 'store');
  86. # 取消
  87. $data['cancel'] = Dever::url('admin/out.cancel', 'store');
  88. # 新增出库单
  89. $data['add'] = Dever::url('admin/out.add', 'store');
  90. return $data;
  91. }
  92. # 取消
  93. public function cancel_api()
  94. {
  95. $order_id = Dever::input('order_id');
  96. Dever::load('mshop/lib/out')->set(2,1)->cancel($this->id, $order_id);
  97. return 'reload';
  98. }
  99. # 获取商品列表
  100. public function getGoods_api()
  101. {
  102. $store_id = $this->id;
  103. return Dever::outDiy(Dever::load('store/lib/goods')->getSkuList($store_id));
  104. }
  105. # 设置生产能力
  106. public function add_api()
  107. {
  108. $data = array();
  109. $data['store_id'] = $this->id;
  110. $data['host'] = Dever::url('admin/out.add', 'store');
  111. $data['url'] = Dever::url('admin/out.getGoods', 'store');
  112. $data['submit'] = Dever::url('admin/out.action_cmmmit?json=1', 'store');
  113. $data['out_type'] = $this->getType(2);
  114. $data['user'] = $this->user['name'];
  115. return Dever::render('setGoods', $data);
  116. }
  117. # 得到商品和总价
  118. private function goods()
  119. {
  120. $goods = Dever::input('goods');
  121. if (!$goods) {
  122. Dever::alert('请传入商品');
  123. }
  124. $goods = Dever::json_decode($goods);
  125. $this->data['price'] = 0;
  126. $this->data['num'] = 0;
  127. $this->data['name'] = array();
  128. $store_id = $this->id;
  129. # 计算总价格
  130. foreach ($goods as $k => $v) {
  131. if (strstr($v['id'], '-')) {
  132. $t = explode('-', $v['id']);
  133. $v['id'] = $t[0];
  134. $s = $t[1];
  135. } else {
  136. $s = -1;
  137. }
  138. $n = $v['num'];
  139. $this->data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v['id'], $s, 2);
  140. $this->data['list'][$k]['num'] = $n;
  141. # 2是库存不足
  142. $this->data['list'][$k]['ku_state'] = 1;
  143. # 验证是否有货
  144. $total = Dever::load('store/lib/goods')->checkTotal($n, $v['id'], $store_id, $s);
  145. if ($total <= 0) {
  146. $this->data['list'][$k]['ku_state'] = 2;
  147. $this->data['list'][$k]['buy_num'] = 0;
  148. }
  149. if ($this->data['list'][$k]['ku_state'] == 1) {
  150. $this->data['list'][$k]['buy_num'] = $n;
  151. $this->data['num'] += $n;
  152. $this->data['price'] += $this->data['list'][$k]['price'] * $n;
  153. $this->data['name'][] = $this->data['list'][$k]['name'];
  154. }
  155. }
  156. $this->data['name'] = implode(',', $this->data['name']);
  157. }
  158. # 生成出库单
  159. public function action_cmmmit_api()
  160. {
  161. $info = Dever::input('info');
  162. $out_type = Dever::input('out_type', 1);
  163. $this->goods();
  164. Dever::load('mshop/lib/out')->set(2,1)->action($this->id, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $this->user['id'], $out_type, $info, 1);
  165. return Dever::url('out', 'store');
  166. }
  167. public function print_api()
  168. {
  169. return Dever::load('mshop/lib/out')->printer($this->user);
  170. }
  171. }