feat(app): 添加订单类型名称映射函数并配置 PSI 中间件
- 在 app/functions.php 中添加 getOrderTypeName 函数,用于获取订单类型名称 - 在 config/middleware.php 中添加 psi 中间件配置,包括跨域中间件、初始化中间件、登录验证中间件、权限认证中间件和操作日志记录中间件
This commit is contained in:
parent
4db10be442
commit
c0caac17f9
95
app/admin/controller/supplier/SupplierController.php
Normal file
95
app/admin/controller/supplier/SupplierController.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\supplier;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\supplier\SupplierLists;
|
||||
use app\admin\logic\supplier\SupplierLogic;
|
||||
use app\admin\validate\supplier\SupplierValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 供应链控制器
|
||||
* Class SupplierController
|
||||
* @package app\admin\controller\supplier
|
||||
*/
|
||||
class SupplierController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取供应链列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new SupplierLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加供应链
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = (new SupplierValidate())->post()->goCheck('add');
|
||||
$result = SupplierLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(SupplierLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑供应链
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = (new SupplierValidate())->post()->goCheck('edit');
|
||||
$result = SupplierLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(SupplierLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除供应链
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new SupplierValidate())->post()->goCheck('delete');
|
||||
SupplierLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取供应链详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new SupplierValidate())->goCheck('detail');
|
||||
$result = SupplierLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
69
app/admin/lists/supplier/SupplierLists.php
Normal file
69
app/admin/lists/supplier/SupplierLists.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\lists\supplier;
|
||||
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
|
||||
/**
|
||||
* 供应链列表
|
||||
* Class SupplierLists
|
||||
* @package app\admin\listssupplier
|
||||
*/
|
||||
class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['phone'],
|
||||
'%like%'=>['mer_name']
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取供应链列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Supplier::where($this->searchWhere)
|
||||
->field(['id', 'category_id', 'mer_name', 'phone', 'settle_cycle', 'address', 'mark'])
|
||||
->limit($this->limitOffset, 100)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
$item->total_completed_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',1)->sum('total_price');
|
||||
$item->total_outstanding_amount=WarehouseProduct::where('supplier_id',$item['id'])->where('financial_pm',1)->where('is_pay',0)->sum('total_price');
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取供应链数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Supplier::where($this->searchWhere)->count();
|
||||
}
|
||||
|
||||
}
|
103
app/admin/logic/supplier/SupplierLogic.php
Normal file
103
app/admin/logic/supplier/SupplierLogic.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\supplier;
|
||||
|
||||
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\logic\BaseLogic;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
/**
|
||||
* 供应链逻辑
|
||||
* Class SupplierLogic
|
||||
* @package app\admin\logic\supplier
|
||||
*/
|
||||
class SupplierLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加供应链
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Supplier::create([
|
||||
'mer_name' => $params['mer_name'],
|
||||
'phone' => $params['phone'],
|
||||
'settle_cycle' => $params['settle_cycle'],
|
||||
'address' => $params['address'],
|
||||
'mark' => $params['mark'],
|
||||
'status' => $params['status']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑供应链
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
Supplier::where('id', $params['id'])->update([
|
||||
'mer_name' => $params['mer_name'],
|
||||
'phone' => $params['phone'],
|
||||
'settle_cycle' => $params['settle_cycle'],
|
||||
'address' => $params['address'],
|
||||
'mark' => $params['mark'],
|
||||
'status' => $params['status']
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除供应链
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
return Supplier::destroy($params['id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取供应链详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/08/15 14:10
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return Supplier::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
244
app/common/enum/OrderEnum.php
Normal file
244
app/common/enum/OrderEnum.php
Normal file
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\common\enum;
|
||||
|
||||
|
||||
class OrderEnum
|
||||
{
|
||||
/**
|
||||
* 流水类型
|
||||
* @USER_ORDER_PAY 用户订单支付
|
||||
* @CASHIER_ORDER_PAY 收银台支付
|
||||
* @CASHIER_CASH_ORDER_PAY 收银台现金支付
|
||||
* @MERCHANT_ORDER_OBTAINS 商户订单获得
|
||||
* @ORDER_HANDLING_FEES 订单手续费
|
||||
* @MERCHANT_ORDER_PAY 商户订单支付
|
||||
* @PLATFORM_ORDER_OBTAINS 平台订单获得
|
||||
* @SUPPLIER_ORDER_OBTAINS 供应链订单获得
|
||||
* @VIP_ORDER_OBTAINS 会员订单获得
|
||||
* @VILLAGE_ORDER_OBTAINS 村长获得
|
||||
* @BRIGADE_ORDER_OBTAINS 队长获得
|
||||
* @OTHER_ORDER_OBTAINS 其他获得
|
||||
* @PLATFORM_ORDER_PAY 平台订单支付
|
||||
* @SYSTEM_SET 系统设置
|
||||
* @OWN_GET 平台收入
|
||||
* @ORDER_MARGIN 商户保证金
|
||||
* @PURCHASE_FUNDS 采购款收银
|
||||
*/
|
||||
const USER_ORDER_PAY = 1;
|
||||
const MERCHANT_ORDER_OBTAINS = 2;
|
||||
const ORDER_HANDLING_FEES = 3;
|
||||
const MERCHANT_ORDER_PAY = 4;
|
||||
const PLATFORM_ORDER_OBTAINS = 5;
|
||||
const SUPPLIER_ORDER_OBTAINS = 6;
|
||||
const PLATFORM_ORDER_PAY = 7;
|
||||
const SYSTEM_SET = 8;
|
||||
const CASHIER_ORDER_PAY = 9;//微信条码
|
||||
const CASHIER_CASH_ORDER_PAY = 10;
|
||||
const ORDER_MARGIN = 11;
|
||||
const VIP_ORDER_OBTAINS = 12;
|
||||
const CASHIER_ORDER_ALI_PAY = 13;//支付宝条码
|
||||
const VILLAGE_ORDER_OBTAINS = 14;
|
||||
const BRIGADE_ORDER_OBTAINS = 15;
|
||||
const OTHER_ORDER_OBTAINS = 16;
|
||||
|
||||
const CASHIER_FACE_PAY = 17;//现金收银
|
||||
|
||||
const PURCHASE_FUNDS = 18;//采购款收银
|
||||
const USER_ORDER_REFUND = 19;//订单返还
|
||||
const PAY_BACK =-1;
|
||||
|
||||
//-----------------------订单来源-----------------------//
|
||||
/**
|
||||
* @SOURCE_0 小程序
|
||||
* @SOURCE_1 收银台
|
||||
* @SOURCE_2 后台下单
|
||||
* @SOURCE_20 预订单转订单
|
||||
*/
|
||||
const SOURCE_0 =0;//小程序
|
||||
const SOURCE_1 =1;//收银台
|
||||
const SOURCE_2 =2;//后台下单
|
||||
const SOURCE_20 =20;//预订单转订单
|
||||
|
||||
|
||||
/**
|
||||
* 收入支出类型
|
||||
* @EXPENDITURE 支出
|
||||
* @INCOME 收入
|
||||
*/
|
||||
const EXPENDITURE = 0;
|
||||
const INCOME = 1;
|
||||
|
||||
//-----------------------物流状态-----------------------//
|
||||
/**
|
||||
* @RECEIVED_GOODS 已收货
|
||||
*/
|
||||
const RECEIVED_GOODS = 2;
|
||||
|
||||
/**
|
||||
* @RECEIVED_BACK 已退款
|
||||
*/
|
||||
const RECEIVED_BACK = 4;
|
||||
|
||||
/**
|
||||
* @WAIT_EVALUATION 待评价
|
||||
*/
|
||||
const WAIT_EVALUATION = 3;
|
||||
/**
|
||||
* @WAIT_DELIVERY 待发货
|
||||
*/
|
||||
const WAIT_DELIVERY = 0;
|
||||
/**
|
||||
* @WAIT_RECEIVING 待收货
|
||||
*/
|
||||
const WAIT_RECEIVING = 1;
|
||||
/**
|
||||
* @ALREADY_REFUND 申请退款
|
||||
*/
|
||||
const ALREADY_REFUND = -1;
|
||||
|
||||
/**
|
||||
* @RETURN_SUCCESS 退款成功
|
||||
*/
|
||||
const RETURN_SUCCESS = -2;
|
||||
|
||||
/**
|
||||
* 核销
|
||||
* @IS_OK 已核销
|
||||
*/
|
||||
const IS_OK = 1;
|
||||
|
||||
/**
|
||||
* 回调订单相关
|
||||
* @PAY 支付
|
||||
* @IBACK 退款
|
||||
*/
|
||||
const PAY = 1;
|
||||
const BACK = 0;
|
||||
|
||||
/**小程序下单**/
|
||||
const ONLINE = [1,2];
|
||||
const OFFLINE = [3];
|
||||
/**
|
||||
* 账户类型
|
||||
* @USER 用户
|
||||
* @MERCHANT 商户
|
||||
* @PLATFORM 平台
|
||||
* @SUPPLIER 供应链
|
||||
* @SYSTEM 系统
|
||||
*/
|
||||
const USER = 0;
|
||||
const MERCHANT = 1;
|
||||
const PLATFORM = 2;
|
||||
const SUPPLIER = 3;
|
||||
const SYSTEM = 4;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 订单状态
|
||||
* @CANCEL_ORDER 取消售后
|
||||
*/
|
||||
const REFUND_GOODS = -2;
|
||||
const REFUND_PAY = 4;
|
||||
|
||||
const CANCEL_ORDER = 5;
|
||||
|
||||
//退款状态
|
||||
const REFUND_STATUS_NO = 0;
|
||||
const REFUND_STATUS_YES = 1;
|
||||
const REFUND_STATUS_FINISH = 2;
|
||||
const CANCEL_SALE = 3;
|
||||
|
||||
//判断资金流水是否余额支付
|
||||
const BALANCE_PAYMEN_NO = 1;
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取支付类型
|
||||
* @param bool $value
|
||||
* @return string|string[]
|
||||
* @author 段誉
|
||||
* @date 2023/2/23 15:36
|
||||
*/
|
||||
public static function getFinancialType($value = true)
|
||||
{
|
||||
$data = [
|
||||
self::USER_ORDER_PAY => '订单支付',
|
||||
self::MERCHANT_ORDER_PAY => '商户订单支付',
|
||||
self::PLATFORM_ORDER_PAY => '平台订单支付',
|
||||
self::MERCHANT_ORDER_OBTAINS => '商户',
|
||||
self::ORDER_HANDLING_FEES => '手续费',
|
||||
self::PLATFORM_ORDER_OBTAINS => '平台',
|
||||
self::SUPPLIER_ORDER_OBTAINS => '成本',
|
||||
self::SYSTEM_SET => '平台设置',
|
||||
self::VILLAGE_ORDER_OBTAINS => '村长',
|
||||
self::BRIGADE_ORDER_OBTAINS=>'队长',
|
||||
self::ORDER_MARGIN=>'保证金',
|
||||
self::VIP_ORDER_OBTAINS=>'会员',
|
||||
self::OTHER_ORDER_OBTAINS=>'其他',
|
||||
self::USER_ORDER_REFUND=>'订单返还'
|
||||
|
||||
];
|
||||
if ($value === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$value] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取订单状态类型
|
||||
*/
|
||||
public static function getOrderType($value = true)
|
||||
{
|
||||
$data = [
|
||||
self::RECEIVED_GOODS => '已完成',
|
||||
self::WAIT_EVALUATION => '待评价',
|
||||
self::WAIT_DELIVERY => '待发货',
|
||||
self::WAIT_RECEIVING => '待核销',
|
||||
self::RETURN_SUCCESS => '退货成功',
|
||||
self::ALREADY_REFUND => '已退款',
|
||||
self::RECEIVED_BACK => '已退款',
|
||||
];
|
||||
if ($value === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$value] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取订单状态类型
|
||||
*/
|
||||
public static function refundStatus($value = true)
|
||||
{
|
||||
$data = [
|
||||
self::REFUND_STATUS_NO => '未退款',
|
||||
self::REFUND_STATUS_YES => '退款中',
|
||||
self::REFUND_STATUS_FINISH => '已退款',
|
||||
];
|
||||
if ($value === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$value] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取订单状态类型
|
||||
*/
|
||||
public static function refundType($value = true)
|
||||
{
|
||||
$data = [
|
||||
1 => '仅退款',
|
||||
2 => '退款退货',
|
||||
3 => '拒绝退款',
|
||||
4 => '商品待退货',
|
||||
5 => '退货待收货',
|
||||
6 => '已退款',
|
||||
];
|
||||
if ($value === true) {
|
||||
return $data;
|
||||
}
|
||||
return $data[$value] ?? '';
|
||||
}
|
||||
}
|
23
app/common/model/psi/psi_order/PsiOrder.php
Normal file
23
app/common/model/psi/psi_order/PsiOrder.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\psi\psi_order;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 进销订单模型
|
||||
* Class PsiOrder
|
||||
* @package app\common\model\psi\PsiOrder
|
||||
*/
|
||||
class PsiOrder extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'psi_order';
|
||||
protected $deleteTime = 'delete_time';
|
||||
// 不生成该表的日志
|
||||
public $doNotRecordLog = true;
|
||||
|
||||
}
|
48
app/common/model/psi/psi_product/PsiProduct.php
Normal file
48
app/common/model/psi/psi_product/PsiProduct.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\psi\psi_product;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 商品仓储信息模型
|
||||
* Class WarehouseProduct
|
||||
* @package app\common\model\psi\psi_product
|
||||
*/
|
||||
class PsiProduct extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'psi_product';
|
||||
protected $deleteTime = 'delete_time';
|
||||
public $ignoreLogFields = [
|
||||
'price',
|
||||
'total_price',
|
||||
'status',
|
||||
'pay_type',
|
||||
'is_pay',
|
||||
'vip_price',
|
||||
'cost',
|
||||
'purchase',
|
||||
'total_price',
|
||||
'mark',
|
||||
'after_nums',
|
||||
'before_nums',
|
||||
'batch',
|
||||
'enter_admin_id',
|
||||
'admin_id',
|
||||
'financial_pm',
|
||||
'expiration_date',
|
||||
'manufacture',
|
||||
'code',
|
||||
'oid',
|
||||
'unit',
|
||||
'store_id',
|
||||
'supplier_id',
|
||||
'warehouse_id',
|
||||
'create_time',
|
||||
'update_time',
|
||||
];
|
||||
}
|
23
app/common/model/psi/warehouse/Warehouse.php
Normal file
23
app/common/model/psi/warehouse/Warehouse.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\psi\warehouse;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 仓库信息模型
|
||||
* Class Warehouse
|
||||
* @package app\common\model\psi\warehouse
|
||||
*/
|
||||
class Warehouse extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'warehouse';
|
||||
protected $deleteTime = 'delete_time';
|
||||
// 不生成该表的日志
|
||||
public $doNotRecordLog = true;
|
||||
|
||||
}
|
23
app/common/model/psi/warehouse_storege/WarehouseStorege.php
Normal file
23
app/common/model/psi/warehouse_storege/WarehouseStorege.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\psi\warehouse_storege;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* 仓库存储
|
||||
* Class WarehouseStorege
|
||||
* @package app\common\model\psi\warehouse_storege
|
||||
*/
|
||||
class WarehouseStorege extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'warehouse_storege';
|
||||
protected $deleteTime = 'delete_time';
|
||||
public $ignoreLogFields = [
|
||||
'price',
|
||||
'update_time',
|
||||
];
|
||||
}
|
23
app/common/model/supplier/Supplier.php
Normal file
23
app/common/model/supplier/Supplier.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\supplier;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
/**
|
||||
* 供应链模型
|
||||
* Class Supplier
|
||||
* @package app\common\model\supplier
|
||||
*/
|
||||
class Supplier extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'supplier';
|
||||
protected $deleteTime = 'delete_time';
|
||||
// 不生成该表的日志
|
||||
public $doNotRecordLog = true;
|
||||
|
||||
}
|
23
app/common/model/system_store/SystemStore.php
Normal file
23
app/common/model/system_store/SystemStore.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\system_store;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
/**
|
||||
* 门店列表模型
|
||||
* Class SystemStore
|
||||
* @package app\common\model\system_store
|
||||
*/
|
||||
class SystemStore extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
protected $name = 'system_store';
|
||||
protected $deleteTime = 'delete_time';
|
||||
// 不生成该表的日志
|
||||
public $doNotRecordLog = true;
|
||||
|
||||
|
||||
}
|
@ -493,4 +493,21 @@ if (!function_exists('convertStringToNumber')) {
|
||||
return intval($str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!function_exists('getOrderTypeName')) {
|
||||
function getOrderTypeName($type)
|
||||
{
|
||||
$typeMap = [
|
||||
1 => '铺货订单',
|
||||
2 => '商贩订单',
|
||||
3 => '一条龙订单',
|
||||
4 => '线上订单',
|
||||
5 => '仓库补货',
|
||||
6 => '往期补单-出库',
|
||||
7 => '采购订单',
|
||||
8 => '其他订单',
|
||||
9 => '往期补单-入库',
|
||||
];
|
||||
return $typeMap[$type] ?? '';
|
||||
}
|
||||
}
|
||||
|
329
app/psi/controller/psi_order/PsiOrderController.php
Normal file
329
app/psi/controller/psi_order/PsiOrderController.php
Normal file
@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
namespace app\psi\controller\psi_order;
|
||||
|
||||
|
||||
use app\admin\controller\BaseAdminController;
|
||||
use app\admin\lists\warehouse_order\WarehouseOrderLists;
|
||||
use app\admin\logic\store_product\StoreProductLogic;
|
||||
use app\admin\logic\warehouse_order\WarehouseOrderLogic;
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\admin\validate\warehouse_order\WarehouseOrderValidate;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_order\StoreOrder;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\store_product_unit\StoreProductUnit;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use app\common\service\xlsx\Beforehand;
|
||||
use app\common\service\xlsx\OrderDetail;
|
||||
use app\common\service\xlsx\WarehouseOrdeRentry;
|
||||
use app\psi\lists\psi_order\PsiOrderLists;
|
||||
use support\exception\BusinessException;
|
||||
use support\Log;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 进销订单控制器
|
||||
* Class PsiOrderController
|
||||
* @package app\admin\controller\warehouse_order
|
||||
*/
|
||||
class PsiOrderController extends BaseAdminController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单列表
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
|
||||
return $this->dataLists(new PsiOrderLists());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加入库单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = WarehouseOrderLogic::add($params);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 添加出库单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function outbound()
|
||||
{
|
||||
$product_arr = $this->request->post('product_arr');
|
||||
$warehouse_id = $this->request->post('warehouse_id');
|
||||
$delivery_time = $this->request->post('delivery_time');
|
||||
$mark = $this->request->post('mark');
|
||||
$type = $this->request->post('order_type', 1);
|
||||
Db::startTrans();
|
||||
try {
|
||||
if($type==1){
|
||||
$code=getNewOrderId('TGY');
|
||||
}else{
|
||||
$code=getNewOrderId('BS');
|
||||
}
|
||||
$arr = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'store_id' => 0,
|
||||
'supplier_id' => 0,
|
||||
'code' => $code,
|
||||
'admin_id' => $this->adminId,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark ?? "",
|
||||
];
|
||||
$arr['delivery_time'] = strtotime($delivery_time);
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => 0,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
'type' => $type,
|
||||
'order_type' => 0,
|
||||
];
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->find();
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
$data['financial_pm'] = 0;
|
||||
$data['price'] = $storeProduct['price'];
|
||||
WarehouseProductLogic::setOutbound($data,1,$this->adminId);
|
||||
$finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return $this->success('出库成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑仓储商品单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = WarehouseOrderLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑仓储商品单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function update_edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = WarehouseOrderLogic::update_edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail('编辑失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除仓储商品单
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$params = (new WarehouseOrderValidate())->post()->goCheck('delete');
|
||||
WarehouseOrderLogic::delete($params);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单详情
|
||||
* @return \think\response\Json
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$params = (new WarehouseOrderValidate())->goCheck('detail');
|
||||
$result = WarehouseOrderLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
/**
|
||||
* 入库表格
|
||||
*/
|
||||
public function rentry_export()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$xlsx = new WarehouseOrdeRentry();
|
||||
$order = WarehouseOrder::where('id', $id)->findOrEmpty();
|
||||
$data = WarehouseProduct::where('oid', $id)->select();
|
||||
$order['total_num'] = 0;
|
||||
$credit_pay = 0;
|
||||
$cash_pay = 0;
|
||||
foreach ($data as $key => &$value) {
|
||||
$find = StoreProduct::where('id', $value->product_id)->withTrashed()->find();
|
||||
$value->store_name = $find['store_name'] ?? '';
|
||||
$value->store_info = $find['store_info'] ?? '';
|
||||
if (!empty($find['unit'])) {
|
||||
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
} else {
|
||||
$value->unit_name = '';
|
||||
}
|
||||
$order['total_num'] += $value->nums;
|
||||
$value->supplier_name = Supplier::where('id', $value->supplier_id)->value('mer_name');
|
||||
if ($value->pay_type == 1) {
|
||||
$credit_pay += $value->total_price;
|
||||
$value->pay_type_name = '赊账';
|
||||
} elseif ($value->pay_type == 2) {
|
||||
$cash_pay += $value->total_price;
|
||||
$value->pay_type_name = '现款';
|
||||
} else {
|
||||
$value->pay_type_name = '未设置';
|
||||
}
|
||||
}
|
||||
$order['credit_pay'] = $credit_pay;
|
||||
$order['cash_pay'] = $cash_pay;
|
||||
$file_path = $xlsx->export($data, $order);
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 出库表格
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$type = $this->request->post('type');
|
||||
if (in_array($type, [2, 3])) {
|
||||
return $this->fail('暂不支持此操作');
|
||||
}
|
||||
$xlsx = new OrderDetail();
|
||||
$order = WarehouseOrder::where('id', $id)->findOrEmpty();
|
||||
$system_store = SystemStore::where('id', $order['store_id'])->value('name');
|
||||
$data = WarehouseProduct::where('oid', $id)->select();
|
||||
$order['total_num'] = 0;
|
||||
$total_price = 0;
|
||||
foreach ($data as $key => &$value) {
|
||||
if (in_array($order['store_id'], [17, 18])) {
|
||||
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id', $order['store_id'])->withTrashed()->find();
|
||||
} else {
|
||||
$find = StoreProduct::where('id', $value->product_id)->withTrashed()->find();
|
||||
}
|
||||
$value->store_name = $find['store_name'] ?? '';
|
||||
$value->store_info = $find['store_info'] ?? '';
|
||||
// if($type==2){
|
||||
// $value->price = $value['purchase'];
|
||||
// $value->total_price=bcmul($value['purchase'],$value['nums'],2);
|
||||
// $total_price+=$value->total_price;
|
||||
// }elseif($type==3){
|
||||
// $value->price = $find['cost'];
|
||||
// $value->total_price=bcmul($find['cost'],$value['nums'],2);
|
||||
// $total_price+=$value->total_price;
|
||||
// }elseif($type==4){
|
||||
// $value->price = $find['price'];
|
||||
// $value->total_price=bcmul($find['price'],$value['nums'],2);
|
||||
// $total_price+=$value->total_price;
|
||||
// }else{
|
||||
if ($type == 1) {
|
||||
$value->price = $value['purchase'];
|
||||
$value->total_price = bcmul($value['purchase'], $value['nums'], 2);
|
||||
$total_price += $value->total_price;
|
||||
}
|
||||
|
||||
|
||||
// }
|
||||
$value->cart_num = $value['nums'];
|
||||
if (!empty($find['unit'])) {
|
||||
$value->unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
} else {
|
||||
$value->unit_name = '';
|
||||
}
|
||||
$order['total_num'] += $value->nums;
|
||||
}
|
||||
if ($type == 2) {
|
||||
$order['total_price'] = $total_price;
|
||||
}
|
||||
$order['delivery_time'] = date('Y-m-d H:i:s', $order['delivery_time']);
|
||||
$order['pay_time'] = $order['create_time'];
|
||||
$order['order_id'] = $order['code'];
|
||||
|
||||
if ($order['oid'] > 0) {
|
||||
$orders = StoreOrder::where('id', $order['oid'])->findOrEmpty();
|
||||
$order['real_name'] = $orders['real_name'];
|
||||
$order['user_phone'] = $orders['user_phone'];
|
||||
$order['user_address'] = $orders['user_address'];
|
||||
}
|
||||
$file_path = $xlsx->export($data, $system_store, $order);
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出标签
|
||||
*/
|
||||
public function export_tags()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$warehouseOrder = WarehouseOrder::where('id', $id)->field('oid,store_id,delivery_time')->find();
|
||||
$system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('introduction');
|
||||
$data = WarehouseProduct::where('oid', $id)->where('financial_pm', 0)->field('oid,product_id,nums')->select()
|
||||
->each(function ($item) use ($system_store, $warehouseOrder) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->withTrashed()->find();
|
||||
$unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$item['system_store'] = $system_store;
|
||||
$item['subtitle'] = $item['oid'] . ' ' . convertStringToNumber($item['nums']) . '/' . $unit_name;
|
||||
$item['store_name'] = $find['store_name'];
|
||||
if ($warehouseOrder['oid']) {
|
||||
$find = StoreOrder::where('id', $warehouseOrder['oid'])->field('real_name,user_address')->find();
|
||||
if ($find) {
|
||||
$item['address'] = $find['real_name'] . ' ' . $find['user_address'];
|
||||
} else {
|
||||
$item['address'] = '无地址';
|
||||
}
|
||||
} else {
|
||||
$item['address'] = '无地址';
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
$file_path = (new Beforehand())->export($data, $system_store);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
}
|
152
app/psi/lists/psi_order/PsiOrderLists.php
Normal file
152
app/psi/lists/psi_order/PsiOrderLists.php
Normal file
@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace app\psi\lists\psi_order;
|
||||
|
||||
use app\admin\lists\BaseAdminDataLists;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\supplier\Supplier;
|
||||
use app\common\model\system_store\SystemStore;
|
||||
use app\common\lists\ListsExcelInterface;
|
||||
use app\common\model\psi\psi_order\PsiOrder;
|
||||
use app\common\model\psi\warehouse\Warehouse;
|
||||
|
||||
/**
|
||||
* 进销存单列表
|
||||
* Class PsiOrderLists
|
||||
* @package app\admin\listswarehouse_order
|
||||
*/
|
||||
class PsiOrderLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExcelInterface
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置搜索条件
|
||||
* @return \string[][]
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['financial_pm', 'supplier_id', 'warehouse_id', 'store_id','id'],
|
||||
'%like'=>['code'],
|
||||
'between_time' => 'create_time'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return PsiOrder::where($this->searchWhere)
|
||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time','oid', 'order_type'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item) {
|
||||
if ($item->financial_pm == 0) {
|
||||
$item->financial_pm_name = '出库';
|
||||
} else {
|
||||
$item->financial_pm_name = '入库';
|
||||
}
|
||||
if ($item->financial_pm == 0) {
|
||||
if ($item->store_id) {
|
||||
$item->system_store = SystemStore::where('id', $item->store_id)->value('name');
|
||||
} else {
|
||||
$item->system_store = '';
|
||||
}
|
||||
}
|
||||
if ($item->admin_id) {
|
||||
$item->admin_name = Admin::where('id', $item->admin_id)->value('name');
|
||||
} else {
|
||||
$item->admin_name = '';
|
||||
}
|
||||
if ($item->warehouse_id) {
|
||||
$item->warehouse_name = Warehouse::where('id', $item->warehouse_id)->value('name');
|
||||
} else {
|
||||
$item->warehouse_name = '';
|
||||
}
|
||||
if ($item->supplier_id) {
|
||||
$item->supplier_name = Supplier::where('id', $item->supplier_id)->value('mer_name');
|
||||
}else{
|
||||
$item->supplier_name = '';
|
||||
}
|
||||
if (!empty($item['order_type'])) {
|
||||
$item->order_type_name = getOrderTypeName($item->order_type);
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单数量
|
||||
* @return int
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return PsiOrder::where($this->searchWhere)->count();
|
||||
}
|
||||
/**
|
||||
* @notes 导出文件名
|
||||
* @return string
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setFileName(): string
|
||||
{
|
||||
$financial_pm = $this->request->get('financial_pm');
|
||||
if ($financial_pm == 0) {
|
||||
return '出库单列表';
|
||||
} else {
|
||||
return '入库单列表';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 导出字段
|
||||
* @return string[]
|
||||
* @date 2022/11/24 16:17
|
||||
*/
|
||||
public function setExcelFields(): array
|
||||
{
|
||||
$financial_pm = $this->request->get('financial_pm');
|
||||
if ($financial_pm == 1) {
|
||||
$data = [
|
||||
'create_time' => '操作时间',
|
||||
'warehouse_name' => '仓库',
|
||||
'supplier_name' => '供应商',
|
||||
'code' => '单号',
|
||||
'financial_pm_name' => '状态',
|
||||
'admin_name' => '填写人员',
|
||||
'completed_amount' => '已结金额',
|
||||
'outstanding_amount' => '未结金额',
|
||||
'total_price' => '总金额',
|
||||
'mark' => '备注',
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
'create_time' => '操作时间',
|
||||
'warehouse_name' => '仓库',
|
||||
'supplier_name' => '供应商',
|
||||
'code' => '单号',
|
||||
'financial_pm_name' => '状态',
|
||||
'admin_name' => '填写人员',
|
||||
'total_price' => '总金额',
|
||||
'mark' => '备注',
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
190
app/psi/logic/psi_order/PsiOrderLogic.php
Normal file
190
app/psi/logic/psi_order/PsiOrderLogic.php
Normal file
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\logic\warehouse_order;
|
||||
|
||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||
use app\common\model\warehouse_order\WarehouseOrder;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\beforehand_order\BeforehandOrder;
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use support\exception\BusinessException;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 进销订单逻辑
|
||||
* Class PsiOrderLogic
|
||||
* @package app\admin\logic\warehouse_order
|
||||
*/
|
||||
class PsiOrderLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 添加仓储商品单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function add(array $params): bool
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$arr = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'supplier_id' => $params['supplier_id'],
|
||||
'code' => $params['code'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'financial_pm' => 1,
|
||||
'batch' => 0,
|
||||
'mark' => $params['remark'],
|
||||
'total_price' => $params['remark'],
|
||||
'completed_amount' => $params['completed_amount']??0,
|
||||
'outstanding_amount' => $params['outstanding_amount']??0,
|
||||
];
|
||||
|
||||
$total_price = 0;
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$total_price += $v['total_price'];
|
||||
}
|
||||
$arr['total_price'] = $total_price;
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$data['admin_id'] = $params['admin_id'];
|
||||
$data['store_id'] = 0;
|
||||
$data['oid'] = $res['id'];
|
||||
$data['supplier_id'] = $params['supplier_id'];
|
||||
$data['warehouse_id'] = $params['warehouse_id'];
|
||||
$data['code'] = $params['code'];
|
||||
$data['product_id'] = $v['product_id'];
|
||||
$data['nums'] = $v['nums'];
|
||||
$data['purchase'] = $v['purchase'];
|
||||
$data['total_price'] = $v['total_price'];
|
||||
$data['financial_pm'] = 1;
|
||||
if (!empty($v['manufacture'])) {
|
||||
$data['manufacture'] = $v['manufacture'];
|
||||
}
|
||||
if (!empty($v['expiration_date'])) {
|
||||
$data['expiration_date'] = $v['expiration_date'];
|
||||
}
|
||||
WarehouseProductLogic::add($data,1,$params['admin_id']);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 编辑仓储商品单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function edit(array $params): bool
|
||||
{
|
||||
$find = WarehouseOrder::where('id', $params['id'])->find();
|
||||
if (!$find) {
|
||||
throw new BusinessException('订单不存在');
|
||||
}
|
||||
$order_type=BeforehandOrder::where('warehousing_id|outbound_id',$find['id'])->value('order_type')??0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$data['order_type'] = $order_type;
|
||||
$data['supplier_id'] = $v['supplier_id']??0;
|
||||
$data['pay_type'] = $v['pay_type']??0;
|
||||
$data['admin_id'] = $params['admin_id'];
|
||||
$data['store_id'] = $find['store_id'];
|
||||
$data['oid'] = $find['id'];
|
||||
$data['warehouse_id'] = $find['warehouse_id'];
|
||||
$data['code'] = $find['code'];
|
||||
$data['product_id'] = $v['id'];
|
||||
$data['nums'] = $v['nums'];
|
||||
$data['purchase'] = $v['purchase'];
|
||||
$data['total_price'] = $v['total_price'];
|
||||
$data['financial_pm'] = $find['financial_pm'];
|
||||
if (!empty($v['manufacture'])) {
|
||||
$data['manufacture'] = $v['manufacture'];
|
||||
}
|
||||
if (!empty($v['expiration_date'])) {
|
||||
$data['expiration_date'] = $v['expiration_date'];
|
||||
}
|
||||
if($find['financial_pm']==0){
|
||||
$data['purchase'] = $v['prices'];
|
||||
$data['total_price'] = bcmul($v['prices'], $v['nums'], 2);
|
||||
}
|
||||
WarehouseProductLogic::add($data,1,$params['admin_id']);
|
||||
}
|
||||
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $params['id'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 删除仓储商品单
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function delete(array $params): bool
|
||||
{
|
||||
$count = WarehouseProduct::where('oid', $params['id'])->count();
|
||||
if ($count >= 1) {
|
||||
throw new BusinessException('该订单下还有商品没有删除,请先删除商品');
|
||||
}
|
||||
WarehouseOrder::destroy($params['id']);
|
||||
$find = WarehouseProduct::where('oid', $params['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find();
|
||||
if ($find) {
|
||||
WarehouseOrder::where('id', $params['id'])->update([
|
||||
'nums' => $find['nums'],
|
||||
'total_price' => $find['total_price']
|
||||
]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑仓储商品单
|
||||
* @param $data
|
||||
* @return bool
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function update_edit($data){
|
||||
$res=WarehouseOrder::update($data);
|
||||
if($res){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取仓储商品单详情
|
||||
* @param $params
|
||||
* @return array
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
return WarehouseOrder::findOrEmpty($params['id'])->toArray();
|
||||
}
|
||||
}
|
@ -47,4 +47,16 @@ return [
|
||||
// 操作日志记录
|
||||
app\admin\middleware\OperationLogMiddleware::class,
|
||||
],
|
||||
'psi' => [
|
||||
// 跨域中间件
|
||||
app\common\http\middleware\AdminAllowMiddleware::class,
|
||||
// 初始化
|
||||
app\admin\middleware\InitMiddleware::class,
|
||||
// 登录验证
|
||||
app\admin\middleware\LoginMiddleware::class,
|
||||
// 权限认证
|
||||
app\admin\middleware\AuthMiddleware::class,
|
||||
// 操作日志记录
|
||||
app\admin\middleware\OperationLogMiddleware::class,
|
||||
],
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user