Out.php 5.9 KB

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