OrderTrait.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * User: admin
  4. * Date Time: 2021/1/20 19:27
  5. */
  6. namespace bizGhs\order\traits;
  7. use biz\ghs\classes\GhsClass;
  8. use bizGhs\admin\classes\AdminClass;
  9. use bizGhs\product\classes\ProductClass;
  10. use common\components\imgUtil;
  11. trait OrderTrait
  12. {
  13. //二维数组拼装admin信息
  14. public static function groupAdminList($list)
  15. {
  16. if (empty($list)) {
  17. return $list;
  18. }
  19. $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
  20. $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
  21. foreach ($list as $k => $val) {
  22. $adminId = $val['adminId'] ?? 0;
  23. //不能取admin里的nam
  24. $list[$k]['adminName'] = $val['shopAdminName'] ?? '';
  25. $list[$k]['nickName'] = $adminInfo[$adminId]['name'] ?? '';
  26. $list[$k]['avatar'] = $adminInfo[$adminId]['avatar'] ?? '';
  27. }
  28. return $list;
  29. }
  30. //2021.1.22 lqh 一维数组拼装admin信息
  31. public static function groupAdmin($data)
  32. {
  33. $adminId = $data['adminId'] ?? 0;
  34. $adminInfo = AdminClass::getAdminById($adminId);
  35. //不能取admin里的nam
  36. $data['adminName'] = $data['shopAdminName'] ?? '';
  37. $data['nickName'] = $adminInfo['name'] ?? '';
  38. $data['avatar'] = $adminInfo['avatar'] ?? '';
  39. return $data;
  40. }
  41. public static function groupSupplierList($list)
  42. {
  43. if (empty($list)) {
  44. return $list;
  45. }
  46. $ghsIds = array_unique(array_filter(array_column($list, 'ghsId')));
  47. $ghsInfo = GhsClass::getGhsByIds($ghsIds);
  48. foreach ($list as $k => $val) {
  49. $ghsId = $val['ghsId'] ?? 0;
  50. $list[$k]['supplierName'] = $ghsInfo[$ghsId]['name'] ?? '';
  51. $avatar = imgUtil::groupImg('');
  52. $list[$k]['supplierAvatar'] = $avatar;
  53. $list[$k]['supplierMobile'] = $ghsInfo[$ghsId]['mobile'] ?? '';
  54. $list[$k]['supplierAddress'] = $ghsInfo[$ghsId]['address'] ?? '';
  55. }
  56. return $list;
  57. }
  58. //通过itemInfo 获取商品ID 对应数据(库存) lqh 2021.1.23
  59. public static function getProductMapData($itemInfo, $key = 'productId')
  60. {
  61. $productIds = array_column($itemInfo, $key);
  62. $productData = ProductClass::getProductByIds($productIds);
  63. $productData = array_column($productData, NULL, 'id');
  64. return $productData;
  65. }
  66. //通过itemInfo 求和大、小单位数 lqh 2021.1.25
  67. public static function sumNumByItemInfo($itemInfo)
  68. {
  69. $bigNum = 0; //总共多少扎
  70. $smallNum = 0; //总共多少支
  71. if (!empty($itemInfo)) {
  72. foreach ($itemInfo as $v) {
  73. $currentBigNum = isset($v['bigNum']) && is_numeric($v['bigNum']) ? $v['bigNum'] : 0;
  74. $bigNum += $currentBigNum;
  75. $currentSmallNum = isset($v['smallNum']) && is_numeric($v['smallNum']) ? $v['smallNum'] : 0;
  76. $smallNum += $currentSmallNum;
  77. }
  78. }
  79. return [
  80. 'bigNum' => $bigNum,
  81. 'smallNum' => $smallNum
  82. ];
  83. }
  84. //itemInfo 相同product合并处理 [{"classId":5,"productId":3,"bigNum":1,"smallNum":2},{"classId":4,"productId":3,"bigNum":1,"smallNum":5}]
  85. public static function mergeItemInfo($itemInfo)
  86. {
  87. $newItemInfo = [];
  88. foreach ($itemInfo as $v) {
  89. $productId = $v['productId'];
  90. if (isset($newItemInfo[$productId])) {
  91. $newItemInfo[$productId]['bigNum'] = bcadd($v['bigNum'], $newItemInfo[$productId]['bigNum'], 2);
  92. $newItemInfo[$productId]['smallNum'] = bcadd($v['smallNum'], $newItemInfo[$productId]['smallNum'], 2);
  93. } else {
  94. $newItemInfo[$productId] = $v;
  95. }
  96. }
  97. $newItemInfo = array_merge($newItemInfo);
  98. return $newItemInfo;
  99. }
  100. //出库时更新统计
  101. public static function updateStatByStockOut($order)
  102. {
  103. }
  104. //入库时更新统计
  105. public static function updateStatByStockIn($order)
  106. {
  107. }
  108. //盘点时更新统计
  109. public static function updateStatCheck($order)
  110. {
  111. }
  112. }