Stock.php 3.0 KB

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