Out.php 6.7 KB

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