Goods.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Store\Lib;
  3. use Dever;
  4. class Goods
  5. {
  6. # 处理库存操作 1是增加,2是减少 1是总库存,2是销量
  7. public function oper($type, $col, $data)
  8. {
  9. if (!$data) {
  10. return;
  11. }
  12. if ($type == 1) {
  13. $method = 'inc';
  14. $otherMethod = 'dec';
  15. } else {
  16. $method = 'dec';
  17. $otherMethod = 'inc';
  18. }
  19. if ($col == 1) {
  20. $method .= 'Total';
  21. $otherMethod .= 'Total';
  22. $num = 'total_num';
  23. } else {
  24. $method .= 'Sell';
  25. $otherMethod .= 'Sell';
  26. $num = 'sell_num';
  27. }
  28. foreach ($data as $k => $v) {
  29. if (!$v['sku_id']) {
  30. $v['sku_id'] = -1;
  31. }
  32. $up = array();
  33. $up['where_store_id'] = $v['store_id'];
  34. $up['where_goods_id'] = $v['goods_id'];
  35. $up[$num] = $v['num'];
  36. $state = Dever::db('store/goods')->$method($up);
  37. if ($state) {
  38. $upSku = $up;
  39. $upSku['where_sku_id'] = $v['sku_id'];
  40. $state = Dever::db('store/goods_sku')->$method($upSku);
  41. if (!$state) {
  42. Dever::db('store/goods')->$otherMethod($up);
  43. }
  44. }
  45. }
  46. return $state;
  47. }
  48. }