Merge pull request 'feat(warehouse_order): 添加订单管理功能' (#147) from dev into main
Reviewed-on: #147
This commit is contained in:
commit
2d4ef79ef3
@ -149,7 +149,8 @@ class WarehouseOrderController extends BaseAdminController
|
|||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit()
|
||||||
{
|
{
|
||||||
$params = (new WarehouseOrderValidate())->post()->goCheck('edit');
|
$params = $this->request->post();
|
||||||
|
$params['admin_id']=$this->adminId;
|
||||||
$result = WarehouseOrderLogic::edit($params);
|
$result = WarehouseOrderLogic::edit($params);
|
||||||
if (true === $result) {
|
if (true === $result) {
|
||||||
return $this->success('编辑成功', [], 1, 1);
|
return $this->success('编辑成功', [], 1, 1);
|
||||||
@ -168,6 +169,9 @@ class WarehouseOrderController extends BaseAdminController
|
|||||||
{
|
{
|
||||||
$params = (new WarehouseOrderValidate())->post()->goCheck('delete');
|
$params = (new WarehouseOrderValidate())->post()->goCheck('delete');
|
||||||
WarehouseOrderLogic::delete($params);
|
WarehouseOrderLogic::delete($params);
|
||||||
|
if(WarehouseOrderLogic::hasError()){
|
||||||
|
return $this->fail(WarehouseOrderLogic::getError());
|
||||||
|
}
|
||||||
return $this->success('删除成功', [], 1, 1);
|
return $this->success('删除成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class WarehouseOrderLists extends BaseAdminDataLists implements ListsSearchInter
|
|||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return WarehouseOrder::where($this->searchWhere)
|
return WarehouseOrder::where($this->searchWhere)
|
||||||
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time'])
|
->field(['id', 'warehouse_id', 'supplier_id', 'store_id', 'code', 'financial_pm', 'admin_id', 'batch', 'mark', 'purchase', 'total_price', 'status', 'create_time','completed_amount','outstanding_amount'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()->each(function ($item){
|
->select()->each(function ($item){
|
||||||
|
@ -5,9 +5,9 @@ namespace app\admin\logic\warehouse_order;
|
|||||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||||
use app\common\model\warehouse_order\WarehouseOrder;
|
use app\common\model\warehouse_order\WarehouseOrder;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\model\warehouse_product\WarehouseProduct;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 仓储商品单逻辑
|
* 仓储商品单逻辑
|
||||||
* Class WarehouseOrderLogic
|
* Class WarehouseOrderLogic
|
||||||
@ -37,6 +37,8 @@ class WarehouseOrderLogic extends BaseLogic
|
|||||||
'batch' => 0,
|
'batch' => 0,
|
||||||
'mark' => $params['remark'],
|
'mark' => $params['remark'],
|
||||||
'total_price' => $params['remark'],
|
'total_price' => $params['remark'],
|
||||||
|
'completed_amount' => $params['completed_amount']??0,
|
||||||
|
'outstanding_amount' => $params['outstanding_amount']??0,
|
||||||
];
|
];
|
||||||
|
|
||||||
$total_price = 0;
|
$total_price = 0;
|
||||||
@ -84,25 +86,47 @@ class WarehouseOrderLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function edit(array $params): bool
|
public static function edit(array $params): bool
|
||||||
{
|
{
|
||||||
|
$find = WarehouseOrder::where('id', $params['id'])->find();
|
||||||
|
if (!$find) {
|
||||||
|
self::setError('订单不存在');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
|
foreach ($params['product_arr'] as $k => $v) {
|
||||||
|
$data['admin_id'] = $params['admin_id'];
|
||||||
|
$data['store_id'] = 0;
|
||||||
|
$data['oid'] = $find['id'];
|
||||||
|
$data['supplier_id'] = $find['supplier_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);
|
||||||
|
}
|
||||||
|
$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([
|
WarehouseOrder::where('id', $params['id'])->update([
|
||||||
'warehouse_id' => $params['warehouse_id'],
|
'nums' => $find['nums'],
|
||||||
'supplier_id' => $params['supplier_id'],
|
'total_price' => $find['total_price']
|
||||||
'store_id' => $params['store_id'],
|
|
||||||
'code' => $params['code'],
|
|
||||||
'financial_pm' => $params['financial_pm'],
|
|
||||||
'admin_id' => $params['admin_id'],
|
|
||||||
'batch' => $params['batch'],
|
|
||||||
'mark' => $params['mark'],
|
|
||||||
'purchase' => $params['purchase'],
|
|
||||||
'total_price' => $params['total_price'],
|
|
||||||
'status' => $params['status']
|
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Throwable $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
@ -119,7 +143,20 @@ class WarehouseOrderLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function delete(array $params): bool
|
public static function delete(array $params): bool
|
||||||
{
|
{
|
||||||
return WarehouseOrder::destroy($params['id']);
|
$count = WarehouseProduct::where('oid', $params['id'])->count();
|
||||||
|
if ($count >= 1) {
|
||||||
|
self::setError('该订单下还有商品没有删除,请先删除商品');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$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']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
WarehouseOrder::destroy($params['id']);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user