|
@@ -11,10 +11,12 @@ use App\Model\ProductActivityPrice;
|
|
|
use App\Model\ProductCategory;
|
|
|
use App\Model\ProductInfo;
|
|
|
use App\Model\ProductIntroduction;
|
|
|
+use App\Model\ProductInventoryOfTop;
|
|
|
use App\Model\ProductPriceDetail;
|
|
|
use App\Model\Role;
|
|
|
use App\Model\RoleMenuButton;
|
|
|
use App\Model\SeeRange;
|
|
|
+use App\Model\Storehouse;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
@@ -629,6 +631,7 @@ class ProductService extends Service
|
|
|
$model->whereIn('product_category_id',array_unique(array_column($product_category,'id')));
|
|
|
}
|
|
|
if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
|
|
|
+ if(! empty($data['item_code'])) $model->where('item_code', 'LIKE', '%'.$data['item_code'].'%');
|
|
|
if(! empty($data['bar_code'])) $model->where('bar_code', 'LIKE', '%'.$data['bar_code'].'%');
|
|
|
if(! empty($data['size'])) $model->where('size', 'LIKE', '%'.$data['size'].'%');
|
|
|
if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
@@ -1228,7 +1231,8 @@ class ProductService extends Service
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
|
|
|
- $basic_map = BasicType::where('type',BasicType::type_22)
|
|
|
+ $basic_map = BasicType::whereIn('id',array_unique(array_column($product, 'unit')))
|
|
|
+ ->OrWhere('type',BasicType::type_22)
|
|
|
->pluck('title','id')
|
|
|
->toArray();
|
|
|
|
|
@@ -1242,13 +1246,30 @@ class ProductService extends Service
|
|
|
//当前门店
|
|
|
$top_depart = $user['depart_top'][0] ?? [];
|
|
|
|
|
|
+ $stock = ProductInventoryOfTop::where('del_time',0)
|
|
|
+ ->whereIn('product_id',$product_id)
|
|
|
+ ->pluck('number','product_id')
|
|
|
+ ->toArray();
|
|
|
foreach ($product as $key => $value){
|
|
|
$tmp = $this->fillProductPrice($detail_map, $value, $top_depart,$basic_map);
|
|
|
$product[$key]['product_price'] = $tmp;
|
|
|
$product[$key]['img'] = $img[$value['id']] ?? "";
|
|
|
$product[$key]['product_category_name'] = $category[$value['product_category_id']] ?? '';
|
|
|
$product[$key]['product_attribute_title'] = Product::$product_attribute[$value['product_attribute']] ?? "";
|
|
|
- $product[$key]['stock'] = "0";
|
|
|
+ if(isset($stock[$value['id']])){
|
|
|
+ $number = $stock[$value['id']];
|
|
|
+ if($number <= 0){
|
|
|
+ $stock = "售罄";
|
|
|
+ } elseif($number <= 15){
|
|
|
+ $stock = " 库存紧张";
|
|
|
+ }else{
|
|
|
+ $stock = " 库存充足";
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $stock = "联系客服";
|
|
|
+ }
|
|
|
+ $product[$key]['stock'] = $stock;
|
|
|
+ $product[$key]['unit_title'] = $basic_map[$value['unit']] ?? "";
|
|
|
}
|
|
|
|
|
|
return [true, $product];
|
|
@@ -1261,7 +1282,7 @@ class ProductService extends Service
|
|
|
$product = $model->where('del_time',0)
|
|
|
->whereIn('item_code', $item_code)
|
|
|
->where('is_use', Product::is_use_one)
|
|
|
- ->select('title','id','product_category_id','retail_price','product_attribute','item_code','size')
|
|
|
+ ->select('title','id','product_category_id','retail_price','product_attribute','item_code','size','unit')
|
|
|
->get()->toArray();
|
|
|
|
|
|
return $product;
|
|
@@ -1284,4 +1305,61 @@ class ProductService extends Service
|
|
|
|
|
|
return $tmp;
|
|
|
}
|
|
|
+
|
|
|
+ public function updateTopStock($data, $user){
|
|
|
+ $service = new U8ServerService(true);
|
|
|
+ if(! empty($service->error)) return [false, $service->error];
|
|
|
+
|
|
|
+ $limit_key = "updateTopStockFromYy";
|
|
|
+ list($status, $msg) = $this->limitingSendRequestBackgExpire($limit_key, 20);
|
|
|
+ if(! $status) return [false, '正在获取T9杭州总仓库存货库存,请勿重复操作'];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::enableQueryLog();
|
|
|
+ //总店
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
+ $storehouse_id = Storehouse::where('top_depart_id', $head)->where('del_time',0)->value('id') ?? 0;
|
|
|
+ $time = time();
|
|
|
+ DB::table('product')
|
|
|
+ ->where('del_time', 0)
|
|
|
+ ->where('top_depart_id', $head)
|
|
|
+ ->select('id','code')
|
|
|
+ ->orderBy('id')
|
|
|
+ ->chunk(200, function ($data) use($service,$head,$storehouse_id,$time){
|
|
|
+ $data = Collect($data)->map(function ($object) {
|
|
|
+ return (array)$object;
|
|
|
+ })->toArray();
|
|
|
+
|
|
|
+ $map = array_column($data,'id','code');
|
|
|
+ $id = array_unique(array_column($data,'id'));
|
|
|
+ $code = array_unique(array_column($data,'code'));
|
|
|
+ list($status, $msg) = $service->getStock($code, "001");
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
+
|
|
|
+ $insert = [];
|
|
|
+ foreach ($msg as $value){
|
|
|
+ $insert[] = [
|
|
|
+ 'product_id' => $map[$value['product_no']] ?? 0,
|
|
|
+ 'storehouse_id' => $storehouse_id,
|
|
|
+ 'top_depart_id' => $head,
|
|
|
+ 'number' => $value['number'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ ProductInventoryOfTop::where('del_time',0)
|
|
|
+ ->whereIn('product_id',$id)
|
|
|
+ ->update(['del_time' => $time]);
|
|
|
+
|
|
|
+ ProductInventoryOfTop::insert($insert);
|
|
|
+ });
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Throwable $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true, ''];
|
|
|
+ }
|
|
|
}
|