| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- declare(strict_types=1);
- namespace app\api\service;
- use app\common\model\ShopList;
- use app\common\model\StockConfig;
- use app\common\model\ProductConfig;
- use app\common\model\StockDetail;
- /**
- * 录入发货
- */
- class SpecService{
-
- //判断价格为空
- public static function getIsZeroSpecsPrice(array $data): bool
- {
- $result = false;
- foreach ($data as $item) {
- if(empty($item['price'])) return false;
- }
- return $result;
- }
- //获取规格列表
- public static function getSpecsList(int $type_id, array $data): array
- {
- $result = [];
- foreach ($data as $item) {
-
- if($item['type_id'] == $type_id){
- $result[] = $item;
- }
- }
- return $result;
- }
-
-
- //录入规格列表
- public static function getDeliveryList(int $uid, array $data): array
- {
- $result = [];
- $customer_id = ShopList::where('id', $data['shop_id'])->value('customer_id');
- foreach ($data['variety'] as $item) {
- if(count($item) != 6 || empty(floatval($item['num']))) throw new \Exception('参数有误!');
- $specs = ProductConfig::where('id', $item['spec_id'])->field('weight,box_id')->find();
- if(!$specs) throw new \Exception('参数有误!');
- $weight = bcmul((string)$specs->weight, $item['num'], 2);
- $result[] = [
- 'user_id' => $uid,
- 'customer_id' => $customer_id,
- 'shop_id' => $data['shop_id'],
- 'plat_id' => $data['plat_id'],
- 'variety_id' => $item['variety_id'],
- 'spec_id' => $item['spec_id'],
- 'num' => $item['num'],
- 'weigh' => $weight,
- 'total_price' => bcmul($item['price'], $item['num'], 2)
- ];
-
- //根据品种扣除库存
- StockDetail::setStockConfigNum((int)$item['variety_id'], (string)-$weight, StockConfig::VarietyName);
- //根据规格扣除包装箱
- StockDetail::setStockConfigNum($specs->box_id, (string)-$item['num'], StockConfig::PackingBox);
- }
- return $result;
- }
-
-
- }
|