Goods.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Goods
  5. {
  6. # 根据店铺获取商品列表
  7. public function getList()
  8. {
  9. $shop_id = Dever::input('shop_id');
  10. $lng = Dever::input('lng');
  11. $lat = Dever::input('lat');
  12. $column = Dever::db('goods/column')->select();
  13. $data = array();
  14. # 这里要加一下缓存
  15. $data['shop'] = Dever::load('shop/lib/info')->getOne($shop_id, $lng, $lat);
  16. if ($column) {
  17. foreach ($column as $k => $v) {
  18. $v['data'] = Dever::load('shop/lib/info')->getGoods($shop_id, $v['id']);
  19. $data['cate'][] = $v;
  20. }
  21. }
  22. return $data;
  23. }
  24. # 处理库存操作 1是增加,2是减少 1是总库存,2是销量
  25. public function oper($order, $type, $col, $data)
  26. {
  27. if (!$data) {
  28. return;
  29. }
  30. if ($type == 1) {
  31. $method = 'inc';
  32. $otherMethod = 'dec';
  33. } else {
  34. $method = 'dec';
  35. $otherMethod = 'inc';
  36. }
  37. if ($col == 1) {
  38. $method .= 'Total';
  39. $otherMethod .= 'Total';
  40. $num = 'total_num';
  41. } else {
  42. $method .= 'Sell';
  43. $otherMethod .= 'Sell';
  44. $num = 'sell_num';
  45. }
  46. $up = array();
  47. $table = 'shop';
  48. if (isset($order['shop_id'])) {
  49. $up['where_shop_id'] = $order['shop_id'];
  50. } elseif (isset($order['type'])) {
  51. if ($order['type'] == 1) {
  52. $up['where_shop_id'] = $order['type_id'];
  53. } elseif ($order['type'] == 2) {
  54. $table = 'store';
  55. $up['where_store_id'] = $order['type_id'];
  56. }
  57. } else {
  58. return false;
  59. }
  60. foreach ($data as $k => $v) {
  61. if (!$v['sku_id']) {
  62. $v['sku_id'] = -1;
  63. }
  64. $up['where_goods_id'] = $v['goods_id'];
  65. $up[$num] = $v['num'];
  66. $state = Dever::db($table . '/goods')->$method($up);
  67. if ($state) {
  68. $upSku = $up;
  69. $upSku['where_sku_id'] = $v['sku_id'];
  70. $state = Dever::db($table . '/goods_sku')->$method($upSku);
  71. if (!$state) {
  72. Dever::db($table . '/goods')->$otherMethod($up);
  73. }
  74. if (isset($order['source_type']) && $order['source_type'] == 2 && $type == 1 && $col == 1) {
  75. # 如果是仓库发货的,要减少仓库库存
  76. $sup['where_store_id'] = $order['source_id'];
  77. $sup['where_goods_id'] = $v['goods_id'];
  78. $sup[$num] = $v['num'];
  79. $state = Dever::db('store/goods')->$otherMethod($sup);
  80. if ($state) {
  81. $supSku = $sup;
  82. $supSku['where_sku_id'] = $v['sku_id'];
  83. $state = Dever::db('store/goods_sku')->$otherMethod($supSku);
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }