StoreStockImport.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 StoreStockImport extends BaseModel
  13. {
  14. /**
  15. * 详情
  16. * @param array $condition
  17. * @param string $field
  18. * @return array
  19. */
  20. public function getStoreStockImportInfo($condition = [], $field = '*')
  21. {
  22. $info = model('store_stock_import')->getInfo($condition, $field);
  23. if (!empty($info)) {
  24. if (isset($info[ 'stock' ])) {
  25. $info[ 'stock' ] = numberFormat($info[ 'stock' ]);
  26. }
  27. if (isset($info[ 'error_num' ])) {
  28. $info[ 'error_num' ] = numberFormat($info[ 'error_num' ]);
  29. }
  30. }
  31. return $this->success($info);
  32. }
  33. /**
  34. * 删除
  35. * @param $id
  36. * @param $store_id
  37. * @return array
  38. */
  39. public function deleteStoreStockImport($id, $store_id)
  40. {
  41. model('store_stock_import')->startTrans();
  42. try {
  43. model('store_stock_import')->delete([ [ 'id', '=', $id ], [ 'store_id', '=', $store_id ] ]);
  44. model('store_stock_import_log')->delete([ [ 'file_id', '=', $id ] ]);
  45. model('store_stock_import')->commit();
  46. return $this->success();
  47. } catch (\Exception $e) {
  48. model('store_stock_import')->rollback();
  49. return $this->error('', $e->getMessage());
  50. }
  51. }
  52. /**
  53. * 获取导入文件列表
  54. * @param array $condition
  55. * @param int $page
  56. * @param int $page_size
  57. * @param string $order
  58. * @param string $field
  59. * @return array
  60. */
  61. public function getStoreStockImportPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*')
  62. {
  63. $list = model('store_stock_import')->pageList($condition, $field, $order, $page, $page_size);
  64. foreach ($list as $k => $v) {
  65. if (isset($v[ 'stock' ])) {
  66. $list[ $k ][ 'stock' ] = numberFormat($list[ $k ][ 'stock' ]);
  67. }
  68. if (isset($v[ 'error_num' ])) {
  69. $list[ $k ][ 'error_num' ] = numberFormat($list[ $k ][ 'error_num' ]);
  70. }
  71. }
  72. return $this->success($list);
  73. }
  74. /**
  75. * 获取导入文件列表
  76. * @param array $condition
  77. * @param int $page
  78. * @param int $page_size
  79. * @param string $order
  80. * @param string $field
  81. * @return array
  82. */
  83. public function getStoreStockImportPageLogList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*')
  84. {
  85. $list = model('store_stock_import_log')->pageList($condition, $field, $order, $page, $page_size);
  86. foreach ($list as $k => $v) {
  87. if (isset($v[ 'stock' ])) {
  88. $list[ $k ][ 'stock' ] = numberFormat($list[ $k ][ 'stock' ]);
  89. }
  90. }
  91. return $this->success($list);
  92. }
  93. }