Stock.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Scm_product\Lib;
  3. use Dever;
  4. class Stock
  5. {
  6. # 更新库存
  7. public function update_commit($id, $name, $data)
  8. {
  9. $table = Dever::input('table');
  10. $type = Dever::input('type');
  11. $col = Dever::input('col');
  12. $stock = Dever::input('stock');
  13. $info = Dever::db($table)->find($id);
  14. if ($table && $type && $info && $info['status'] == 1) {
  15. $audit = Dever::param('audit', $data);
  16. $admin = Dever::load('manage/auth.info');
  17. if ($admin) {
  18. $update['audit_admin'] = $admin['id'];
  19. }
  20. $update['status'] = $audit;
  21. $update['where_id'] = $id;
  22. Dever::db($table)->update($update);
  23. if ($audit == 2) {
  24. # 审核通过 更新库存
  25. $this->up($table, $type, $col, $stock, $info);
  26. }
  27. }
  28. }
  29. public function up($table, $type, $col, $stock, $info)
  30. {
  31. if ($col && $stock && isset($info[$col])) {
  32. $order_goods = Dever::db($table . '_goods')->select(array('order_id' => $info['id'], 'status' => 1));
  33. if ($order_goods) {
  34. foreach ($order_goods as $k => $v) {
  35. $update = array('goods_id' => $v['goods_id'], $col => $info[$col]);
  36. $goods = Dever::db($stock)->find($update);
  37. if (!$goods) {
  38. Dever::db($stock)->insert($update);
  39. }
  40. $update['sku_id'] = $v['sku_id'];
  41. $goods = Dever::db($stock . '_sku')->find($update);
  42. if (!$goods) {
  43. $id = Dever::db($stock . '_sku')->insert($update);
  44. $where['where_id'] = $id;
  45. } else {
  46. $where['where_id'] = $goods['id'];
  47. }
  48. $where[$type . '_num'] = $v['num'];
  49. $method = $type . 'Update';
  50. Dever::db($stock . '_sku')->$method($where);
  51. }
  52. }
  53. }
  54. }
  55. }