Stock.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace Scm\Lib;
  3. use Dever;
  4. class Stock
  5. {
  6. public function show_api()
  7. {
  8. $goods = Dever::input('value');
  9. list($goods_id, $sku_id) = explode('-', $goods);
  10. $where['goods_id'] = $goods_id;
  11. $where['sku_id'] = $sku_id;
  12. $where['servicer_store_id'] = Dever::input('servicer_store_id');
  13. $info = Dever::db('scm_servicer/store_goods_sku')->getOne($where);
  14. $result = array();
  15. $result['goods_id'] = '暂无';
  16. $result['cash'] = '0.00';
  17. if ($info) {
  18. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
  19. $supplier_id = Dever::input('supplier_id');
  20. if ($supplier_id) {
  21. $where['supplier_id'] = $supplier_id;
  22. $sku = Dever::db('scm_supplier/goods_sku')->getOne($where);
  23. $info['cash'] = isset($sku['cost_price']) && $sku['cost_price'] ? $sku['cost_price'] : $goods_info['cost_price'];
  24. }
  25. $result['goods_id'] = '库存:' . $info['total'] . $goods_info['unit'];
  26. $result['cash'] = $info['cash'];
  27. }
  28. return array('data' => $result, 'html' => '');
  29. }
  30. public function out_check($id, $name, $data)
  31. {
  32. $table = Dever::input('table');
  33. $col = Dever::input('col');
  34. $goods = Dever::param('goods', $data);
  35. list($goods_id, $sku_id) = explode('-', $goods);
  36. $where['goods_id'] = $goods_id;
  37. $where['sku_id'] = $sku_id;
  38. $where[$col] = Dever::input('update_' . $col);
  39. $info = Dever::db($table)->getOne($where);
  40. if ($info) {
  41. $num = Dever::param('num', $data);
  42. if ($info['total'] < $num) {
  43. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
  44. return Dever::alert('【' . $goods_info['aname'] . '】剩余库存:' . $info['total'] . $goods_info['unit'] . ',已不足出库');
  45. }
  46. } else {
  47. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
  48. return Dever::alert('【' . $goods_info['aname'] . '】剩余库存:0' . $goods_info['unit'] . ',已不足出库');
  49. }
  50. }
  51. # 更新库存
  52. public function update_commit($id, $name, $data)
  53. {
  54. $table = Dever::input('table');
  55. $type = Dever::input('type');
  56. $col = Dever::input('col');
  57. $stock = Dever::input('stock');
  58. $info = Dever::db($table)->find($id);
  59. if ($table && $type && $info && $info['status'] == 1) {
  60. $audit = Dever::param('audit', $data);
  61. $admin = Dever::load('manage/auth.info');
  62. if ($admin) {
  63. $update['audit_admin'] = $admin['id'];
  64. }
  65. $update['status'] = $audit;
  66. $update['where_id'] = $id;
  67. Dever::db($table)->update($update);
  68. if ($audit == 2) {
  69. # 审核通过 更新库存
  70. $this->up($table, $type, $col, $stock, $info);
  71. }
  72. Dever::db($table . '_goods')->updates(array('option_order_id' => $info['id'], 'set_status' => $update['status']));
  73. }
  74. }
  75. public function up($table, $type, $col, $stock, $info)
  76. {
  77. if ($col && $stock && isset($info[$col])) {
  78. $order_goods = Dever::db($table . '_goods')->select(array('order_id' => $info['id'], 'status' => 1));
  79. if ($order_goods) {
  80. foreach ($order_goods as $k => $v) {
  81. $update = array('goods_id' => $v['goods_id'], $col => $info[$col]);
  82. $goods = Dever::db($stock)->find($update);
  83. if (!$goods) {
  84. Dever::db($stock)->insert($update);
  85. }
  86. $update['sku_id'] = $v['sku_id'];
  87. $goods = Dever::db($stock . '_sku')->find($update);
  88. if (!$goods) {
  89. if ($type == 'in') {
  90. if (!$v['batch']) {
  91. $v['batch'] = date('Ymd');
  92. }
  93. $where['batch'] = $v['batch'];
  94. $where['cash'] = $v['cash'];
  95. }
  96. $id = Dever::db($stock . '_sku')->insert($update);
  97. $where['where_id'] = $id;
  98. } else {
  99. $where['where_id'] = $goods['id'];
  100. }
  101. $where[$type . '_num'] = $v['num'];
  102. $method = $type . 'Update';
  103. Dever::db($stock . '_sku')->$method($where);
  104. //Dever::db($table . '_goods')->update(array('where_id' => $v['id'], 'status' => 2));
  105. }
  106. }
  107. }
  108. }
  109. }