diff --git a/app/admin/controller/LocalController.php b/app/admin/controller/LocalController.php index bcb506ab..485cd662 100644 --- a/app/admin/controller/LocalController.php +++ b/app/admin/controller/LocalController.php @@ -10,7 +10,47 @@ use support\Redis; class LocalController extends BaseAdminController { - public $notNeedLogin = ['index']; + public $notNeedLogin = []; + + public function fixCategory() + { + $topCate = StoreCategory::where('pid', 0)->field('id,name,pid')->order('name')->select()->toArray(); + $topCate = reset_index($topCate, 'name'); + $sql = []; + $time = time(); + foreach ($topCate as $item) { + if (isset($topCate[$item['name'] . '类'])) { + $target = $topCate[$item['name'] . '类']; + $sql[] = "##原分类id:{$item['id']},原分类名:{$item['name']},目标分类id:{$target['id']},目标分类名:{$target['name']}"; + $sql[] = "update la_store_product set top_cate_id={$target['id']} where top_cate_id={$item['id']};"; + $sql[] = "update la_store_product set two_cate_id={$target['id']} where two_cate_id={$item['id']};"; + $sql[] = "update la_store_category set delete_time=$time where id={$item['id']};"; + } + $secondCate = StoreCategory::where('pid', $item['id'])->field('id,name,pid')->order('name')->select()->toArray(); + $secondCate = reset_index($secondCate, 'name'); + foreach ($secondCate as $item2) { + if (isset($secondCate[$item2['name'] . '类'])) { + $target = $secondCate[$item2['name'] . '类']; + $sql[] = "##原分类id:{$item2['id']},原分类名:{$item2['name']},目标分类id:{$target['id']},目标分类名:{$target['name']}"; + $sql[] = "update la_store_product set two_cate_id={$target['id']} where two_cate_id={$item2['id']};"; + $sql[] = "update la_store_product set cate_id={$target['id']} where cate_id={$item2['id']};"; + $sql[] = "update la_store_category set delete_time=$time where id={$item2['id']};"; + } + $thirdCate = StoreCategory::where('pid', $item2['id'])->field('id,name,pid')->order('name')->select()->toArray(); + $thirdCate = reset_index($thirdCate, 'name'); + foreach ($thirdCate as $item3) { + if (isset($thirdCate[$item3['name'] . '类'])) { + $target = $thirdCate[$item3['name'] . '类']; + $sql[] = "##原分类id:{$item3['id']},原分类名:{$item3['name']},目标分类id:{$target['id']},目标分类名:{$target['name']}"; + $sql[] = "update la_store_product set cate_id={$target['id']} where cate_id={$item3['id']};"; + $sql[] = "update la_store_category set delete_time=$time where id={$item3['id']};"; + } + } + } + } + file_put_contents(public_path() . '/update.sql', implode(PHP_EOL, $sql)); + return $this->success('数据已更新完成', $sql); + } public function index() { diff --git a/app/admin/logic/ActivityZoneFormLogic.php b/app/admin/logic/ActivityZoneFormLogic.php index 5f76614a..c8854679 100644 --- a/app/admin/logic/ActivityZoneFormLogic.php +++ b/app/admin/logic/ActivityZoneFormLogic.php @@ -6,6 +6,7 @@ namespace app\admin\logic; use app\common\model\ActivityZone; use app\common\logic\BaseLogic; use app\common\model\ActivityZoneForm; +use app\common\model\store_category\StoreCategory; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\common\service\xlsx\ActivityZoneService; @@ -46,12 +47,12 @@ class ActivityZoneFormLogic extends BaseLogic $params['cate_ids'] = !empty($cateIds) ? implode(',', $cateIds) : ''; $activityZoneForm = new ActivityZoneForm(); $activityZoneForm->save($params); - $productIds = StoreProduct::where('two_cate_id', 'in', $secondCateIds)->whereOr('cate_id', 'in', $thirdCateIds)->column('id'); + $products = StoreProduct::field('id,two_cate_id,cate_id')->where('two_cate_id', 'in', $secondCateIds)->whereOr('cate_id', 'in', $thirdCateIds)->select()->toArray(); $productInfo = []; $time = time(); - foreach ($productIds as $productId) { + foreach ($products as $product) { $productInfo[] = [ - 'product_id' => $productId, + 'product_id' => $product['id'], 'form_id' => $activityZoneForm->id, 'create_time' => $time, 'update_time' => $time, @@ -124,22 +125,24 @@ class ActivityZoneFormLogic extends BaseLogic { $service = new ActivityZoneService(); $activityZoneForm = ActivityZoneForm::findOrEmpty($params['id'])->toArray(); - $products = ActivityZone::with('product')->field('id,product_id')->where('form_id', $params['id'])->select()->toArray(); + $productIds = ActivityZone::where('form_id', $params['id'])->column('product_id'); + $products = StoreProduct::field('id,unit,store_name,two_cate_id')->whereIn('id', $productIds)->order('two_cate_id')->select()->toArray(); $unitIds = array_unique(array_column($products, 'unit')); + $cateIds = array_unique(array_column($products, 'two_cate_id')); $unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray(); + $categories = StoreCategory::whereIn('id', $cateIds)->field('id,name')->withTrashed()->select()->toArray(); $unit = reset_index($unit, 'id'); - foreach ($products as &$item) { - $item['unit_name'] = $unit[$item['unit']]['name'] ?? ''; - unset($item['unit'], $item['product_id']); - } - $data = ConfigLogic::getDictByType('activity_zone'); - foreach ($data['activity_zone'] as $value) { - if ($value['value'] == $activityZoneForm['type']) { - $typeName = $value['remark']; - break; + $categories = reset_index($categories, 'id'); + $data = []; + foreach ($products as $item) { + $currentCate = $categories[$item['two_cate_id']]['name'] ?? ''; + if (!empty($currentCate)) { + $item['unit_name'] = $unit[$item['unit']]['name'] ?? ''; + unset($item['unit'], $item['two_cate_id']); + $data[$currentCate][] = $item; } } - return $service->export($products, $activityZoneForm['title'], $typeName ?? '', $activityZoneForm['remark']); + return $service->export($data, $activityZoneForm['title'], $activityZoneForm['remark']); } } \ No newline at end of file diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 782f1c02..7ba297bd 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -41,7 +41,11 @@ class PurchaseProductOfferLogic extends BaseLogic { Db::startTrans(); try { - $procurementOrder = BeforehandOrder::where('order_type', 7)->where('buyer_id', $params['buyer_id'])->where('is_buying', 0)->where('create_time', '>=', strtotime('-3 days'))->find(); + $procurementOrder = BeforehandOrder::where('order_type', 7) + ->where('buyer_id', $params['buyer_id']) + ->where('is_buying', 0) + ->where('create_time', '>=', strtotime('today')) + ->find(); if (empty($procurementOrder)) { $procurementOrder = new BeforehandOrder(); $procurementOrder->order_id = getNewOrderId('CG'); diff --git a/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php b/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php index 53907af9..a9ac145d 100644 --- a/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php +++ b/app/admin/logic/store_product_group_price/StoreProductGroupPriceLogic.php @@ -105,7 +105,7 @@ class StoreProductGroupPriceLogic extends BaseLogic { $arr=StoreProductGroupPrice::where('product_id',$params['product_id'])->select()->toArray(); $purchase=StoreProduct::where('id',$params['product_id'])->value('purchase'); - $arr_two=UserShip::where('id','>',4)->select()->toArray(); + $arr_two=UserShip::where('id','>',0)->select()->toArray(); $arr_two[] = ['id' => 100001, 'title' => '供货价']; $arr_two[] = ['id' => 100002, 'title' => '零售价']; foreach ($arr_two as $k=>$v){ 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 diff --git a/app/common/service/xlsx/ActivityZoneService.php b/app/common/service/xlsx/ActivityZoneService.php index f0d0b6b8..d3ae3f3b 100644 --- a/app/common/service/xlsx/ActivityZoneService.php +++ b/app/common/service/xlsx/ActivityZoneService.php @@ -9,7 +9,7 @@ use PhpOffice\PhpSpreadsheet\Style\Alignment; class ActivityZoneService { - public function export($data, $title, $typeName, $remark) + public function export($data, $title, $remark) { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); @@ -65,23 +65,30 @@ class ActivityZoneService // 应用默认样式到A2:F5 $sheet->getStyle('A2:F5')->applyFromArray($leftStyle); - foreach ($data as $k => $v) { - $column = $k + 7; - $sheet->mergeCells("B{$column}:C{$column}"); - $sheet->setCellValue('A' . ($k + 7), $v['id']); - $sheet->setCellValue("B{$column}", $v['store_name']); - $sheet->setCellValue("D{$column}", $v['unit_name']); + $column = 7; + foreach ($data as $k => $item) { + $sheet->mergeCells("A{$column}:F{$column}"); + $sheet->setCellValue('A' . $column, $k); + $sheet->getStyle('A' . $column)->applyFromArray([ + 'font' => [ + 'bold' => true, + 'size' => 16, + ], + ]); + $column++; + foreach ($item as $value) { + $sheet->mergeCells("B{$column}:C{$column}"); + $sheet->setCellValue('A' . $column, $value['id']); + $sheet->setCellValue("B{$column}", $value['store_name']); + $sheet->setCellValue("D{$column}", $value['unit_name']); + $column++; + } } - $count = count($data); - $sheet->mergeCells('A' . ($count + 7) . ':F' . ($count + 7)); - $sheet->setCellValue('A' . ($count + 7), "专区类型:{$typeName}"); - $sheet->mergeCells('A' . ($count + 8) . ':F' . ($count + 8)); - $sheet->setCellValue('A' . ($count + 8), ""); - $sheet->mergeCells('A' . ($count + 9) . ':F' . ($count + 9)); - $sheet->setCellValue('A' . ($count + 9), "备注:{$remark}"); - $sheet->getRowDimension($count + 9)->setRowHeight(50); - $sheet->getStyle('A' . ($count + 9))->getAlignment()->setWrapText(true); - $sheet->getStyle('A' . ($count + 7). ':' . 'F' . ($count + 9))->applyFromArray($leftStyle); + $sheet->mergeCells('A' . $column . ':F' . $column); + $sheet->setCellValue('A' . $column, "备注:{$remark}"); + $sheet->getRowDimension($column)->setRowHeight(50); + $sheet->getStyle('A' . $column)->getAlignment()->setWrapText(true); + $sheet->getStyle('A' . $column. ':' . 'F' . $column)->applyFromArray($leftStyle); // 设置单元格的样式 $styleArray = [ @@ -100,7 +107,7 @@ class ActivityZoneService ], ], ]; - $sheet->getStyle('A1:F' . ($count + 9))->applyFromArray($styleArray); + $sheet->getStyle('A1:F' . $column)->applyFromArray($styleArray); $writer = new Xlsx($spreadsheet); $url = '/export/' . date('Y-m') . $title . date('YmdHi') . '.xlsx';