141 行
5.9 KiB
PHP
可执行文件
141 行
5.9 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Common\Business;
|
|
|
|
use Common\Model\CostPriceRecordModel;
|
|
use Common\Model\SaleMGoodsModel;
|
|
use Common\Model\SCostPriceRecordModel;
|
|
use Common\Model\SSaleMGoodsModel;
|
|
use Common\Model\SWarehousingGoodsModel;
|
|
use Common\Model\WarehousingGoodsModel;
|
|
//[1.8.50]
|
|
class SaleGoodsOperation
|
|
{
|
|
/**
|
|
* 销售仓新增商品
|
|
* @param $param
|
|
* [
|
|
* user_type 3商户 4门店
|
|
* goods_info 商品信息
|
|
* type 1新增 2编辑
|
|
* ]
|
|
* @return mixed
|
|
*/
|
|
public function addSaleGoods($param)
|
|
{
|
|
$goods = $param['goods_info'];
|
|
$type = $param['type'];
|
|
switch ($param['user_type']) {
|
|
case 3:
|
|
$SaleGoodsModel = new SaleMGoodsModel();
|
|
$WarehousingGoodsModel = new WarehousingGoodsModel();
|
|
$CostPriceRecordModel = new CostPriceRecordModel();
|
|
break;
|
|
case 4:
|
|
$SaleGoodsModel = new SSaleMGoodsModel();
|
|
$WarehousingGoodsModel = new SWarehousingGoodsModel();
|
|
$CostPriceRecordModel = new SCostPriceRecordModel();
|
|
break;
|
|
}
|
|
$content = [
|
|
'merchant_id' => $goods['merchant_id'],
|
|
'warehouse_id' => $goods['warehouse_id'],
|
|
'goods_class_id' => $goods['goods_class_id'],
|
|
'goods_id' => $goods['goods_id'],
|
|
'goods_name' => $goods['goods_name'],
|
|
'goods_number' => $goods['goods_number'],
|
|
'goods_code' => $goods['goods_code'],
|
|
'company' => $goods['company'],
|
|
'specifications' => $goods['specifications'],
|
|
'attribute_state' => $goods['attribute_state'],
|
|
'pricing_method' => $goods['pricing_method'],
|
|
'goods_brand_id' => $goods['goods_brand_id'],
|
|
'goods_yieldly_id' => $goods['goods_yieldly_id'],
|
|
'goods_num' => $goods['goods_num'],
|
|
'more_num' => $goods['more_num'],
|
|
'less_num' => $goods['less_num'],
|
|
'status' => $goods['status'],
|
|
'cost_price' => $goods['purchase_price'],
|
|
'serial_number_state' => $goods['serial_number_state'] ? $goods['serial_number_state'] : 0,
|
|
'third_goods_code'=>$goods['third_goods_code']?$goods['third_goods_code']:''
|
|
];
|
|
if ($type == 1) {
|
|
$content['add_time'] = $goods['add_time'] ? $goods['add_time'] : time();
|
|
}
|
|
if ($content['attribute_state'] == 2) {
|
|
$content['sku_id'] = $goods['sku_id'];
|
|
$content['sku_name'] = $goods['sku_name'];
|
|
$content['sku_id_list'] = $goods['sku_id_list'];
|
|
$content['sku_goods_number'] = $goods['sku_goods_number'];
|
|
$content['sku_code'] = $goods['sku_code'];
|
|
$content['sku_num'] = $goods['sku_num'];
|
|
}
|
|
if ($type == 2) {
|
|
$where = [
|
|
'goods_id' => $goods['goods_id']
|
|
];
|
|
if ($goods['attribute_state'] == 2) {
|
|
$where['sku_id'] = $goods['sku_id'];
|
|
}
|
|
unset($content['goods_num']);
|
|
unset($content['cost_price']);
|
|
unset($content['add_time']);
|
|
unset($content['third_goods_code']);
|
|
$SaleGoodsModel->updateData($where, $content);
|
|
} else if ($type == 1) {
|
|
$result = $SaleGoodsModel->addData($content);
|
|
if ($result['status'] != 1) {
|
|
return callBack(statusCode()['error'], '销售仓商品信息添加失败');
|
|
}
|
|
}
|
|
if ($type == 1) {
|
|
if ($content['goods_num'] > 0) {
|
|
//库存大于0存入销售仓库
|
|
$content['warehouse_price'] = $content['cost_price'];
|
|
$content['warehouse_num'] = $content['goods_num'];
|
|
$content['surplus_num'] = $content['goods_num'];
|
|
$content['subtotal'] = round($content['warehouse_num'] * $content['warehouse_price'], 2);
|
|
$content['remarks'] = "初始化库存";
|
|
$content['type'] = 5;
|
|
unset($content['specifications']);
|
|
unset($content['goods_brand_id']);
|
|
unset($content['goods_yieldly_id']);
|
|
unset($content['goods_num']);
|
|
unset($content['more_num']);
|
|
unset($content['less_num']);
|
|
unset($content['status']);
|
|
unset($content['cost_price']);
|
|
$result = $WarehousingGoodsModel->addData($content);
|
|
if ($result['status'] != 1) {
|
|
return callBack(statusCode()['error'], '销售仓商品入库记录添加失败');
|
|
}
|
|
//初始成本价添加
|
|
$cost = [
|
|
'merchant_id' => $goods['merchant_id'],
|
|
'cost_price' => $goods['purchase_price'],
|
|
'goods_id' => $goods['goods_id'],
|
|
'purchase_price' => $goods['purchase_price'],
|
|
'goods_class_id' => $goods['goods_class_id'],
|
|
'attribute_state' => $goods['attribute_state'],
|
|
'pricing_method' => $goods['pricing_method'],
|
|
'add_time' => $_SERVER['REQUEST_TIME'],
|
|
'sku_id' => $goods['sku_id'] ? $goods['sku_id'] : 0
|
|
];
|
|
$result = $CostPriceRecordModel->addData($cost);
|
|
if ($result['status'] == 0) {
|
|
return callBack(statusCode()['error'], '成本价记录添加失败');
|
|
}
|
|
}
|
|
} else if ($type == 2) {
|
|
$where = array();
|
|
$where['merchant_id'] = $content['merchant_id'];
|
|
$where['goods_id'] = $content['goods_id'];
|
|
$where['type'] = 5;
|
|
if ($content['attribute_state'] == 2) {
|
|
$where['sku_id'] = $content['sku_id'];
|
|
}
|
|
$WarehousingGoodsModel->updateData($where, $content);
|
|
}
|
|
return callBack(statusCode()['success'], '操作成功');
|
|
}
|
|
} |