diff --git a/app/api/controller/purchase_product_offer/PurchaseProductOfferController.php b/app/api/controller/purchase_product_offer/PurchaseProductOfferController.php index 67f07da1..3261ab5a 100644 --- a/app/api/controller/purchase_product_offer/PurchaseProductOfferController.php +++ b/app/api/controller/purchase_product_offer/PurchaseProductOfferController.php @@ -3,6 +3,8 @@ namespace app\api\controller\purchase_product_offer; +use app\admin\lists\supplier\SupplierLists; +use app\admin\logic\purchase_product_offer\PurchaseProductOfferLogic; use app\api\lists\purchase_product_offer\PurchaseProductOfferLists; use app\api\controller\BaseApiController; use app\common\model\dict\DictData; @@ -34,21 +36,14 @@ class PurchaseProductOfferController extends BaseApiController * 提交采购信息 */ public function offer_update(){ - $params=$this->request->post(); - $data=[ - 'buyer_nums'=>$params['nums'], - 'price'=>$params['price'], - 'outbound_price'=>$params['outbound_price'], - 'total_price'=>$params['total_price'], - 'buyer_confirm'=>1, - 'pay_type'=>$params['pay_type']??0, - ]; - $res=PurchaseProductOffer::where('id',$params['id'])->where('buyer_id',$this->userId)->update($data); - if($res){ - return $this->success('提交成功'); - }else{ - return $this->fail('提交失败'); + + $params = $this->request->post(); + if($params['supplier_id']=='' ||$params['supplier_id']<=0){ + return $this->fail('请选择供应商'); } + $params['admin_id']=0; + PurchaseProductOfferLogic::setProcureInfo($params); + return $this->success('设置成功', [], 1, 1); } /** @@ -64,4 +59,9 @@ class PurchaseProductOfferController extends BaseApiController return $this->success('ok',$data); } + public function supplier() + { + return $this->dataLists(new SupplierLists()); + } + } \ No newline at end of file diff --git a/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php b/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php index 17f7f7ff..88a0faad 100644 --- a/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php +++ b/app/api/lists/purchase_product_offer/PurchaseProductOfferLists.php @@ -10,6 +10,7 @@ use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\api\lists\BaseApiDataLists; use app\common\model\store_category\StoreCategory; +use app\common\model\supplier\Supplier; /** * 采购供应链商品列表 @@ -49,17 +50,16 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI }else{ return []; } - return PurchaseProductOffer::where($this->searchWhere) - ->field(['id', 'order_id', 'product_id', 'price', 'buyer_nums', 'unit', 'is_buyer', 'buyer_confirm','need_num', 'buyer_id', 'status', 'mark','update_time']) + $cateIds = []; + $list = PurchaseProductOffer::where($this->searchWhere) + ->with('product') + ->field(['id', 'order_id', 'product_id', 'price', 'total_price', 'buyer_nums', 'unit', 'is_buyer', 'buyer_confirm','need_num', 'buyer_id', 'status', 'mark','update_time', 'supplier_id', 'package', 'store_info', 'marques', 'after_sales', 'pay_type']) ->limit($this->limitOffset, $this->limitLength) - ->order(['product_id'=>'desc','id' => 'desc']) - ->select()->each(function($item){ - $find=StoreProduct::where('id',$item->product_id)->find(); - $item->store_name=$find->store_name; - $item->image=$find->image; - $item->store_info=$find->store_info; - $item->unit_name=StoreProductUnit::where('id',$item->unit)->value('name'); - $item->category_name=StoreCategory::where('id',$find->top_cate_id)->value('name'); + ->order(['id' => 'desc']) + ->select()->each(function($item) use(&$cateIds, &$supplierIds, &$unitIds) { + $item->store_name=$item->product->store_name ?? ''; + $item->image=$item->product->image ?? ''; + $cateIds[] = $item->product->top_cate_id ?? 0; if($item->is_buyer==1){ $item->is_buyer_name='需要采购'; }elseif($item->is_buyer==-1){ @@ -73,9 +73,20 @@ class PurchaseProductOfferLists extends BaseApiDataLists implements ListsSearchI $item->buyer_confirm_name='采购完成'; } } - }) ->toArray(); + $suppliers = Supplier::field('id,mer_name')->whereIn('id', array_unique(array_column($list,'supplier_id')))->select()->toArray(); + $suppliers = reset_index($suppliers, 'id'); + $units = StoreProductUnit::field('id,name')->whereIn('id', array_unique(array_column($list,'unit')))->select()->toArray(); + $units = reset_index($units, 'id'); + $categories = StoreCategory::field('id,name')->whereIn('id', array_unique($cateIds))->select()->toArray(); + $categories = reset_index($categories, 'id'); + foreach ($list as &$item) { + $item['supplier_name'] = $suppliers[$item['supplier_id']]['mer_name'] ?? ''; + $item['unit_name'] = $units[$item['unit']]['name'] ?? ''; + $item['category_name'] = !empty($item['product']['top_cate_id']) && !empty($categories[$item['product']['top_cate_id']]) ? $categories[$item['product']['top_cate_id']]['name'] : ''; + } + return $list; } diff --git a/app/common/model/purchase_product_offer/PurchaseProductOffer.php b/app/common/model/purchase_product_offer/PurchaseProductOffer.php index 1c6efb33..ba02ef4c 100644 --- a/app/common/model/purchase_product_offer/PurchaseProductOffer.php +++ b/app/common/model/purchase_product_offer/PurchaseProductOffer.php @@ -4,6 +4,7 @@ namespace app\common\model\purchase_product_offer; use app\common\model\BaseModel; +use app\common\model\store_product\StoreProduct; use think\model\concern\SoftDelete; @@ -20,5 +21,10 @@ class PurchaseProductOffer extends BaseModel protected $json = ['source_order_info']; protected $jsonAssoc = true; + + public function product() + { + return $this->hasOne(StoreProduct::class, 'id', 'product_id')->field('id,store_name,top_cate_id,image'); + } } \ No newline at end of file