feat(api): 添加采购商品下载功能
- 新增 purchase_product_offer 方法实现采购商品下载 - 移除未使用的 view_beforehand_order_record 和 view_beforehand_order_record_enter 方法 - 优化代码结构,引入 PurchaseProductOfferListsTwo 类处理下载逻辑
This commit is contained in:
parent
590a4abc4b
commit
2580957b71
@ -8,11 +8,14 @@ use app\common\logic\StoreFinanceFlowLogic;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\validate\tools\GenerateTableValidate;
|
||||
use app\admin\logic\tools\GeneratorLogic;
|
||||
use app\api\lists\purchase_product_offer\PurchaseProductOfferListsTwo;
|
||||
use app\api\logic\order\OrderLogic as OrderOrderLogic;
|
||||
use app\common\cache\ExportCache;
|
||||
use app\common\logic\PayNotifyLogic;
|
||||
use app\common\logic\store_order\StoreOrderLogic;
|
||||
use app\common\model\beforehand_order_record\BeforehandOrderRecord;
|
||||
use app\common\model\Config as ModelConfig;
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_finance_flow\StoreFinanceFlow;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
@ -50,7 +53,7 @@ use PhpOffice\PhpWord\Style\Font;
|
||||
|
||||
class IndexController extends BaseApiController
|
||||
{
|
||||
public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street', 'village', 'brigade', 'config', 'push', 'view_beforehand_order_record', 'view_beforehand_order_record_enter'];
|
||||
public $notNeedLogin = ['index', 'app_update', 'express_list', 'province', 'city', 'area', 'street', 'village', 'brigade', 'config', 'push', 'purchase_product_offer'];
|
||||
|
||||
public function index()
|
||||
{
|
||||
@ -251,55 +254,29 @@ class IndexController extends BaseApiController
|
||||
return $this->success('ok', ['data' => $a]);
|
||||
}
|
||||
|
||||
public function view_beforehand_order_record()
|
||||
/**
|
||||
* @notes 采购商品下载
|
||||
*/
|
||||
public function purchase_product_offer()
|
||||
{
|
||||
$id = $this->request->get('id');
|
||||
$is_xlsx = $this->request->get('is_xlsx');
|
||||
if ($is_xlsx == 1) {
|
||||
$xlsx_name = '清单';
|
||||
} elseif ($is_xlsx == 2) {
|
||||
$xlsx_name = '分单';
|
||||
} elseif ($is_xlsx == 3) {
|
||||
$xlsx_name = '采购';
|
||||
} elseif ($is_xlsx == 4) {
|
||||
$xlsx_name = '出库';
|
||||
}
|
||||
return view('beforehand_order/record', ['id' => $id, 'is_xlsx' => $is_xlsx, 'xlsx_name' => $xlsx_name]);
|
||||
}
|
||||
public function view_beforehand_order_record_enter()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$check = $this->request->post('check');
|
||||
$is_xlsx = $this->request->post('is_xlsx', 0);
|
||||
if ($is_xlsx) {
|
||||
if ($is_xlsx == 1) {
|
||||
$file_path = BeforehandOrderLogic::OrderList(['id' => $id]);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
} elseif ($is_xlsx == 2) {
|
||||
$file_path = BeforehandOrderLogic::OrderAllocation(['id' => $id]);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
} elseif ($is_xlsx == 3) {
|
||||
$file_path = BeforehandOrderLogic::OrderInfo(['id' => $id]);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
} elseif ($is_xlsx == 4) {
|
||||
$file_path = BeforehandOrderLogic::OrderOutbound(['id' => $id]);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
} else {
|
||||
return $this->fail('导出失败');
|
||||
$date=$this->request->get('date');
|
||||
if($date){
|
||||
$this->request->setGet(['date'=>$date,'export'=>2]);
|
||||
$lists=new PurchaseProductOfferListsTwo();
|
||||
$exportDownloadUrl = $lists->createExcel($lists->setExcelFields(), $lists->lists());
|
||||
$fileKey=explode('?file=',$exportDownloadUrl)[1];
|
||||
//通过文件缓存的key获取文件储存的路径
|
||||
$exportCache = new ExportCache();
|
||||
$fileInfo = $exportCache->getFile($fileKey);
|
||||
if (empty($fileInfo)) {
|
||||
return $this->fail('下载文件不存在');
|
||||
}
|
||||
}
|
||||
$check_id = 0;
|
||||
if ($check == '001') {
|
||||
$check_id = 14;
|
||||
}
|
||||
if ($check == '002') {
|
||||
$check_id = 6;
|
||||
}
|
||||
$res = BeforehandOrderRecord::where(['id' => $id])->update(['check_user_id' => $check_id, 'status' => 1]);
|
||||
if ($res) {
|
||||
return $this->success('审核通过');
|
||||
} else {
|
||||
return $this->fail('审核失败');
|
||||
//下载前删除缓存
|
||||
Cache::delete($fileKey);
|
||||
return response()->download($fileInfo['src'] . $fileInfo['name'],$fileInfo['name']);
|
||||
}else{
|
||||
return $this->fail('时间不能为空');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\lists\purchase_product_offer;
|
||||
|
||||
|
||||
use app\common\model\purchase_product_offer\PurchaseProductOffer;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\delivery_service\DeliveryService;
|
||||
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\lists\ListsExcelInterface;
|
||||
use app\common\model\user\User;
|
||||
|
||||
/**
|
||||
* 采购供应链商品列表
|
||||
* Class PurchaseProductOfferLists
|
||||
* @package app\admin\listspurchase_product_offer
|
||||
*/
|
||||
class PurchaseProductOfferListsTwo extends BaseApiDataLists implements ListsSearchInterface,ListsExcelInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/08/14 15:06
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取采购供应链商品列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/08/14 15:06
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
$this->searchWhere[]=['buyer_confirm','=',1];
|
||||
return PurchaseProductOffer::where($this->searchWhere)
|
||||
->whereDay('create_time',$this->request->get('date'))
|
||||
->field(['id', 'order_id', 'product_id', 'price', 'buyer_nums', 'unit', 'total_price', 'buyer_confirm', 'buyer_id','mark'])
|
||||
->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->unit_name=StoreProductUnit::where('id',$item->unit)->value('name');
|
||||
$item->category_name=StoreCategory::where('id',$find->top_cate_id)->value('name');
|
||||
$item->buyer_name=User::where('id',$item['buyer_id'])->value('real_name');
|
||||
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取采购供应链商品数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/08/14 15:06
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return PurchaseProductOffer::where($this->searchWhere)->whereDay('create_time',$this->request->get('date'))->count();
|
||||
|
||||
}
|
||||
/**
|
||||
* @notes 导出文件名
|
||||
* @return string
|
||||
* @author 乔峰
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setFileName(): string
|
||||
{
|
||||
return '采购列表';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 导出字段
|
||||
* @return string[]
|
||||
* @author 乔峰
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
$data=[
|
||||
'order_id' => '订单id',
|
||||
'product_id' => '商品id',
|
||||
'store_name' => '商品名称',
|
||||
'unit_name' => '单位',
|
||||
'category_name' => '分类',
|
||||
'buyer_nums' => '数量',
|
||||
'buyer_name' => '采购人',
|
||||
'price' => '采购单价',
|
||||
'total_price' => '采购总价',
|
||||
'mark' => '备注',
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user