StoreGoods.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\store\model;
  11. use app\model\BaseModel;
  12. class StoreGoods extends BaseModel
  13. {
  14. /**
  15. * 商品编辑之后
  16. */
  17. public function goodsEditAfter($goods_id, $site_id)
  18. {
  19. // $store_list = model('store')->getList([ [ 'site_id', '=', $site_id ] ], 'store_id');
  20. // if (!empty($store_list)) {
  21. // $goods_sku = model('goods_sku')->getColumn([ [ 'goods_id', '=', $goods_id ] ], 'sku_id');
  22. // model('store_goods_sku')->startTrans();
  23. // try {
  24. // foreach ($store_list as $v) {
  25. // $store_id = $v[ 'store_id' ];
  26. // $store_goods_sku = model('store_goods_sku')->getColumn([ [ 'store_id', '=', $store_id ], [ 'goods_id', '=', $goods_id ] ], 'sku_id');
  27. // if (!empty($store_goods_sku)) {
  28. //
  29. // model('store_goods_sku')->delete([ [ 'store_id', '=', $store_id ], [ 'goods_id', '=', $goods_id ], [ 'sku_id', 'not in', $goods_sku ] ]);
  30. // $stock = model('store_goods_sku')->getSum([ [ 'store_id', '=', $store_id ], [ 'goods_id', '=', $goods_id ] ], 'stock');
  31. // model('store_goods')->update([ 'stock' => $stock ], [ [ 'store_id', '=', $store_id ], [ 'goods_id', '=', $goods_id ] ]);
  32. // }
  33. // }
  34. //
  35. // model('store_goods_sku')->commit();
  36. return $this->success();
  37. // } catch (\Exception $e) {
  38. // model('store_goods_sku')->rollback();
  39. // return $this->error('', $e->getMessage());
  40. // }
  41. // }
  42. }
  43. /**
  44. * 门店详情
  45. * @param $condition
  46. * @param string $fields
  47. * @return array
  48. */
  49. public function getStoreGoodsInfo($condition, $fields = '*')
  50. {
  51. $info = model('store_goods')->getInfo($condition, $fields);
  52. if (!empty($info)) {
  53. if (isset($info[ 'stock' ])) {
  54. $info[ 'stock' ] = numberFormat($info[ 'stock' ]);
  55. }
  56. if (isset($info[ 'sale_num' ])) {
  57. $info[ 'sale_num' ] = numberFormat($info[ 'sale_num' ]);
  58. }
  59. if (isset($info[ 'real_stock' ])) {
  60. $info[ 'real_stock' ] = numberFormat($info[ 'real_stock' ]);
  61. }
  62. }
  63. return $this->success($info);
  64. }
  65. /**
  66. * 获取门店商品列表
  67. * @param array $condition
  68. * @param string $field
  69. * @param string $order
  70. * @param string $limit
  71. */
  72. public function getStoreGoodsList($condition = [], $field = '*', $order = '', $limit = null)
  73. {
  74. $list = model('store_goods')->getList($condition, $field, $order, '', '', '', $limit);
  75. foreach ($list as &$v) {
  76. $v[ 'store_goods_skus' ] = model('store_goods_sku')->getList([
  77. [ 'store_id', '=', $v[ 'store_id' ] ],
  78. [ 'goods_id', '=', $v[ 'goods_id' ] ]
  79. ], 'sku_id,goods_id,stock,sale_num');
  80. if (isset($v[ 'stock' ])) {
  81. $v[ 'stock' ] = numberFormat($v[ 'stock' ]);
  82. }
  83. if (isset($v[ 'sale_num' ])) {
  84. $v[ 'sale_num' ] = numberFormat($v[ 'sale_num' ]);
  85. }
  86. if (isset($v[ 'real_stock' ])) {
  87. $v[ 'real_stock' ] = numberFormat($v[ 'real_stock' ]);
  88. }
  89. }
  90. return $this->success($list);
  91. }
  92. }