From 4d3135ed8c23e80bf7eb7b6f331cb129223723ca Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 20 Nov 2024 11:54:23 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat(admin):=20=E6=B7=BB=E5=8A=A0=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E4=BA=A7=E5=93=81=E6=8A=A5=E4=BB=B7=E5=8D=95=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 BeforehandOrderLists 中添加 order_sn 字段 - 在 PurchaseProductOfferLogic 中增加产品信息和单位名称的获取 - 添加报价单推送功能 - 优化报价单数据处理逻辑,增加支付类型名称 --- .../beforehand_order/BeforehandOrderLists.php | 2 +- .../PurchaseProductOfferLogic.php | 17 ++++++++- .../service/workWechat/ProductOffer.php | 37 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 app/common/service/workWechat/ProductOffer.php diff --git a/app/admin/lists/beforehand_order/BeforehandOrderLists.php b/app/admin/lists/beforehand_order/BeforehandOrderLists.php index 7b7ca0116..52772795f 100644 --- a/app/admin/lists/beforehand_order/BeforehandOrderLists.php +++ b/app/admin/lists/beforehand_order/BeforehandOrderLists.php @@ -68,7 +68,7 @@ class BeforehandOrderLists extends BaseAdminDataLists implements ListsSearchInte break; } return BeforehandOrder::where($this->searchWhere) - ->field(['id', 'order_id', 'store_id', 'order_type', 'total_num', 'total_price', 'outbound_id', 'admin_id', 'create_time', 'status', 'mark', 'warehousing_id', 'file']) + ->field(['id', 'order_id', 'order_sn','store_id', 'order_type', 'total_num', 'total_price', 'outbound_id', 'admin_id', 'create_time', 'status', 'mark', 'warehousing_id', 'file']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 398e16498..51a7cfbe8 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -12,6 +12,8 @@ use app\common\model\delivery_service\DeliveryService; use app\common\model\dict\DictData; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_price\StoreProductPrice; +use app\common\model\store_product_unit\StoreProductUnit; +use app\common\service\workWechat\ProductOffer; use support\exception\BusinessException; use think\facade\Db; @@ -136,8 +138,9 @@ class PurchaseProductOfferLogic extends BaseLogic 'after_sales' => $params['after_sales'], ]); $find = StoreProductPrice::where(['offer_id' => $params['id']])->find(); - $top_cate_id = StoreProduct::where('id', $offer['product_id'])->value('top_cate_id'); - $dict_data = DictData::where('type_value', 'price_lv_' . $top_cate_id)->field('name,value')->select(); + $product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('store_name,top_cate_id')->find(); + $unit_name=StoreProductUnit::where('id', $offer['unit_id'])->value('name'); + $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select(); $data = []; $data['bhoid'] = $offer['order_id']; $data['offer_id'] = $params['id']; @@ -167,6 +170,16 @@ class PurchaseProductOfferLogic extends BaseLogic StoreProductPrice::create($data); } Db::commit(); + $offer['store_name']=$product['store_name']; + $offer['unit_name']=$unit_name; + if($offer['pay_type']==1){ + $offer['pay_type_name']='赊账'; + }elseif($offer['pay_type']==2){ + $offer['pay_type_name']='现金'; + }else{ + $offer['pay_type_name']='没设置'; + } + ProductOffer::push($offer); return true; } catch (\Throwable $e) { Db::rollback(); diff --git a/app/common/service/workWechat/ProductOffer.php b/app/common/service/workWechat/ProductOffer.php new file mode 100644 index 000000000..e14c6620a --- /dev/null +++ b/app/common/service/workWechat/ProductOffer.php @@ -0,0 +1,37 @@ + "markdown", "markdown" => ["content" => "有新的采购商品 + >订单ID:$order_id + >商品名称:$store_name + >数量/单位:$num/$unit_name + >采购人:$buyer_name + >采购金额:$price + >采购时间:$create_time + >支付方式:$pay_type + [下载今日采购表格]($url)"]]; + (new Curl())->postJson($url, json_encode($arr, true)); + } catch (\Throwable $e) { + Log::error('推送商品信息保存:'.$e->getMessage()); + } + } +} From b44ee6e9ebf8b0d0a7a29e283f6fe758ce4bcade Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 20 Nov 2024 13:53:58 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix(workWechat):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=A7=E5=93=81Offer=E6=B6=88=E6=81=AF=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将变量名从 $url 改为 $urls,以匹配消息内容中的链接变量 - 修复了消息内容中下载链接的变量引用错误 --- app/common/service/workWechat/ProductOffer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/common/service/workWechat/ProductOffer.php b/app/common/service/workWechat/ProductOffer.php index e14c6620a..9d966d0e7 100644 --- a/app/common/service/workWechat/ProductOffer.php +++ b/app/common/service/workWechat/ProductOffer.php @@ -19,7 +19,7 @@ class ProductOffer $create_time = $data['create_time']; $buyer_name = $data['buyer_name']; $pay_type = $data['pay_type_name']; - $url=getenv('APP_URL')."/api/purchase_product_offer?date=".$data['create_time']; + $urls=getenv('APP_URL')."/api/purchase_product_offer?date=".$data['create_time']; $arr = ["msgtype" => "markdown", "markdown" => ["content" => "有新的采购商品 >订单ID:$order_id >商品名称:$store_name @@ -28,7 +28,7 @@ class ProductOffer >采购金额:$price >采购时间:$create_time >支付方式:$pay_type - [下载今日采购表格]($url)"]]; + [下载今日采购表格]($urls)"]]; (new Curl())->postJson($url, json_encode($arr, true)); } catch (\Throwable $e) { Log::error('推送商品信息保存:'.$e->getMessage()); From 590a4abc4b603b64590bca8c94c390fb4a3e2955 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 20 Nov 2024 13:57:34 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix(purchase):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E4=BA=A7=E5=93=81=E6=8A=A5=E4=BB=B7=E5=8D=95?= =?UTF-8?q?=E6=8D=AE=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修正了单位名称的查询逻辑,使用正确的字段 'unit' 替代 'unit_id' - 添加了买家名称的查询和显示 - 优化了代码结构,提高了可读性和维护性 --- .../purchase_product_offer/PurchaseProductOfferLogic.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php index 51a7cfbe8..2bab83798 100644 --- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php +++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php @@ -13,6 +13,7 @@ use app\common\model\dict\DictData; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_price\StoreProductPrice; use app\common\model\store_product_unit\StoreProductUnit; +use app\common\model\user\User; use app\common\service\workWechat\ProductOffer; use support\exception\BusinessException; use think\facade\Db; @@ -139,7 +140,7 @@ class PurchaseProductOfferLogic extends BaseLogic ]); $find = StoreProductPrice::where(['offer_id' => $params['id']])->find(); $product = StoreProduct::where('id', $offer['product_id'])->withTrashed()->field('store_name,top_cate_id')->find(); - $unit_name=StoreProductUnit::where('id', $offer['unit_id'])->value('name'); + $unit_name=StoreProductUnit::where('id', $offer['unit'])->value('name'); $dict_data = DictData::where('type_value', 'price_lv_' . $product['top_cate_id'])->field('name,value')->select(); $data = []; $data['bhoid'] = $offer['order_id']; @@ -172,6 +173,7 @@ class PurchaseProductOfferLogic extends BaseLogic Db::commit(); $offer['store_name']=$product['store_name']; $offer['unit_name']=$unit_name; + $offer['buyer_name']=User::where('id',$offer['buyer_id'])->value('real_name'); if($offer['pay_type']==1){ $offer['pay_type_name']='赊账'; }elseif($offer['pay_type']==2){ From 2580957b71b33e52aa0bf6d2277d4baf8831be61 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 20 Nov 2024 14:51:34 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E5=95=86=E5=93=81=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 purchase_product_offer 方法实现采购商品下载 - 移除未使用的 view_beforehand_order_record 和 view_beforehand_order_record_enter 方法 - 优化代码结构,引入 PurchaseProductOfferListsTwo 类处理下载逻辑 --- app/api/controller/IndexController.php | 73 ++++-------- .../PurchaseProductOfferListsTwo.php | 111 ++++++++++++++++++ 2 files changed, 136 insertions(+), 48 deletions(-) create mode 100644 app/api/lists/purchase_product_offer/PurchaseProductOfferListsTwo.php diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index ce571667d..4220e9b9c 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -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('时间不能为空'); } } + } diff --git a/app/api/lists/purchase_product_offer/PurchaseProductOfferListsTwo.php b/app/api/lists/purchase_product_offer/PurchaseProductOfferListsTwo.php new file mode 100644 index 000000000..803664e31 --- /dev/null +++ b/app/api/lists/purchase_product_offer/PurchaseProductOfferListsTwo.php @@ -0,0 +1,111 @@ +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; + } +} \ No newline at end of file From afc39e852a438ca3d14d2f73aaca90afaced8019 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 20 Nov 2024 14:54:53 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix(workWechat):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E4=BA=A7=E5=93=81=E4=BF=A1=E6=81=AF=E5=88=B0?= =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在发送消息前增加对 URL 的判断,确保只在生产环境发送 - 优化了代码结构,提高了代码的可读性和维护性 --- .../service/workWechat/ProductOffer.php | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/app/common/service/workWechat/ProductOffer.php b/app/common/service/workWechat/ProductOffer.php index 9d966d0e7..06305f969 100644 --- a/app/common/service/workWechat/ProductOffer.php +++ b/app/common/service/workWechat/ProductOffer.php @@ -11,25 +11,27 @@ class ProductOffer { try { $url = getenv('PUSHPRODUCTOFFER'); - $order_id = $data['order_id']; - $store_name = $data['store_name']; - $num = $data['buyer_nums']; - $unit_name = $data['unit_name']; - $price = $data['price']; - $create_time = $data['create_time']; - $buyer_name = $data['buyer_name']; - $pay_type = $data['pay_type_name']; - $urls=getenv('APP_URL')."/api/purchase_product_offer?date=".$data['create_time']; - $arr = ["msgtype" => "markdown", "markdown" => ["content" => "有新的采购商品 - >订单ID:$order_id - >商品名称:$store_name - >数量/单位:$num/$unit_name - >采购人:$buyer_name - >采购金额:$price - >采购时间:$create_time - >支付方式:$pay_type - [下载今日采购表格]($urls)"]]; - (new Curl())->postJson($url, json_encode($arr, true)); + if($url){ + $order_id = $data['order_id']; + $store_name = $data['store_name']; + $num = $data['buyer_nums']; + $unit_name = $data['unit_name']; + $price = $data['price']; + $create_time = $data['create_time']; + $buyer_name = $data['buyer_name']; + $pay_type = $data['pay_type_name']; + $urls=getenv('APP_URL')."/api/purchase_product_offer?date=".$data['create_time']; + $arr = ["msgtype" => "markdown", "markdown" => ["content" => "有新的采购商品 + >订单ID:$order_id + >商品名称:$store_name + >数量/单位:$num/$unit_name + >采购人:$buyer_name + >采购金额:$price + >采购时间:$create_time + >支付方式:$pay_type + [下载今日采购表格]($urls)"]]; + (new Curl())->postJson($url, json_encode($arr, true)); + } } catch (\Throwable $e) { Log::error('推送商品信息保存:'.$e->getMessage()); }