| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/1/20 19:27
- */
- namespace bizGhs\order\traits;
- use biz\ghs\classes\GhsClass;
- use bizGhs\admin\classes\AdminClass;
- use bizGhs\product\classes\ProductClass;
- use common\components\imgUtil;
- trait OrderTrait
- {
- //二维数组拼装admin信息
- public static function groupAdminList($list)
- {
- if (empty($list)) {
- return $list;
- }
- $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
- $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
- foreach ($list as $k => $val) {
- $adminId = $val['adminId'] ?? 0;
- //不能取admin里的nam
- $list[$k]['adminName'] = $val['shopAdminName'] ?? '';
- $list[$k]['nickName'] = $adminInfo[$adminId]['name'] ?? '';
- $list[$k]['avatar'] = $adminInfo[$adminId]['avatar'] ?? '';
- }
- return $list;
- }
- //2021.1.22 lqh 一维数组拼装admin信息
- public static function groupAdmin($data)
- {
- $adminId = $data['adminId'] ?? 0;
- $adminInfo = AdminClass::getAdminById($adminId);
- //不能取admin里的nam
- $data['adminName'] = $data['shopAdminName'] ?? '';
- $data['nickName'] = $adminInfo['name'] ?? '';
- $data['avatar'] = $adminInfo['avatar'] ?? '';
- return $data;
- }
- public static function groupSupplierList($list)
- {
- if (empty($list)) {
- return $list;
- }
- $ghsIds = array_unique(array_filter(array_column($list, 'ghsId')));
- $ghsInfo = GhsClass::getGhsByIds($ghsIds);
- foreach ($list as $k => $val) {
- $ghsId = $val['ghsId'] ?? 0;
- $list[$k]['supplierName'] = $ghsInfo[$ghsId]['name'] ?? '';
- $avatar = imgUtil::groupImg('');
- $list[$k]['supplierAvatar'] = $avatar;
- $list[$k]['supplierMobile'] = $ghsInfo[$ghsId]['mobile'] ?? '';
- $list[$k]['supplierAddress'] = $ghsInfo[$ghsId]['address'] ?? '';
- }
- return $list;
- }
- //通过itemInfo 获取商品ID 对应数据(库存) lqh 2021.1.23
- public static function getProductMapData($itemInfo, $key = 'productId')
- {
- $productIds = array_column($itemInfo, $key);
- $productData = ProductClass::getProductByIds($productIds);
- $productData = array_column($productData, NULL, 'id');
- return $productData;
- }
- //通过itemInfo 求和大、小单位数 lqh 2021.1.25
- public static function sumNumByItemInfo($itemInfo)
- {
- $bigNum = 0; //总共多少扎
- $smallNum = 0; //总共多少支
- if (!empty($itemInfo)) {
- foreach ($itemInfo as $v) {
- $currentBigNum = isset($v['bigNum']) && is_numeric($v['bigNum']) ? $v['bigNum'] : 0;
- $bigNum += $currentBigNum;
- $currentSmallNum = isset($v['smallNum']) && is_numeric($v['smallNum']) ? $v['smallNum'] : 0;
- $smallNum += $currentSmallNum;
- }
- }
- return [
- 'bigNum' => $bigNum,
- 'smallNum' => $smallNum
- ];
- }
- //itemInfo 相同product合并处理 [{"classId":5,"productId":3,"bigNum":1,"smallNum":2},{"classId":4,"productId":3,"bigNum":1,"smallNum":5}]
- public static function mergeItemInfo($itemInfo)
- {
- $newItemInfo = [];
- foreach ($itemInfo as $v) {
- $productId = $v['productId'];
- if (isset($newItemInfo[$productId])) {
- $newItemInfo[$productId]['bigNum'] = bcadd($v['bigNum'], $newItemInfo[$productId]['bigNum'], 2);
- $newItemInfo[$productId]['smallNum'] = bcadd($v['smallNum'], $newItemInfo[$productId]['smallNum'], 2);
- } else {
- $newItemInfo[$productId] = $v;
- }
- }
- $newItemInfo = array_merge($newItemInfo);
- return $newItemInfo;
- }
- //出库时更新统计
- public static function updateStatByStockOut($order)
- {
- }
- //入库时更新统计
- public static function updateStatByStockIn($order)
- {
- }
- //盘点时更新统计
- public static function updateStatCheck($order)
- {
- }
- }
|