init: import production code mss.nahaichuan.com (exclude Runtime/Uploads/backups/logs)
这个提交包含在:
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
/*
|
||||
* 门店采购商品模型 - 数据对象模型
|
||||
*/
|
||||
|
||||
namespace Common\Model;
|
||||
|
||||
use Think\Model;
|
||||
//[1.8.45]
|
||||
class SPurchaseGoodsModel extends JBaseModel
|
||||
{
|
||||
protected $tableName = 'retail_store_purchase_goods';
|
||||
protected $fields = array(
|
||||
'id', //int(11) NOT NULL AUTO_INCREMENT,
|
||||
'merchant_id', //int(11) DEFAULT '0' COMMENT '商户Id',
|
||||
'store_id', //门店id
|
||||
'purchase_order_id', //int(11) DEFAULT '0' COMMENT '采购订单表id '
|
||||
'warehouse_id', //int(11) DEFAULT '0' COMMENT '采购仓库id',
|
||||
'supplier_id', //int(11) DEFAULT '0' COMMENT '供货商id',
|
||||
'goods_id', //int(11) DEFAULT '0' COMMENT '商户商品id',,
|
||||
'sku_id', //int(11) DEFAULT '0' COMMENT '规格id',,
|
||||
'goods_name', //varchar(255) DEFAULT '' COMMENT '商品名称',
|
||||
'sku_name', //varchar(255) DEFAULT '' COMMENT '规格名称'
|
||||
'sku_id_list', //规格名称id
|
||||
'goods_class_id', //int(11) DEFAULT '0' COMMENT '分类id',
|
||||
'goods_number', //varchar(20) DEFAULT '' COMMENT '商品货号'
|
||||
'sku_goods_number', //规格货号
|
||||
'goods_code', //varchar(30) DEFAULT '' COMMENT '条码',
|
||||
'sku_code', //varchar(30) DEFAULT '' COMMENT '规格条码',
|
||||
'company', //varchar(255) DEFAULT '' COMMENT '单位',
|
||||
'attribute_state', //tinyint(1) DEFAULT '1' COMMENT '规格开关 是否是规格 1关闭 2开启',
|
||||
'pricing_method', //tinyint(1) DEFAULT '1' COMMENT '称重开关:是否称重 1:关闭 2:开启'
|
||||
'purchase_price', //decimal(10,2) DEFAULT NULL COMMENT '进货价',
|
||||
'sku_num', //规格基数
|
||||
'purchase_num', //decimal(10,3) DEFAULT NULL COMMENT '进货数量',
|
||||
'surplus_num', //decimal(10,3) DEFAULT '0.000' COMMENT '待入库数量'
|
||||
'warehousing_num', //decimal(10,3) DEFAULT '0.000' COMMENT ' 已入库数量',
|
||||
'retreat_num', //decimal(10,3) DEFAULT '0.000' COMMENT '退货数量',
|
||||
'subtotal', //decimal(10,2) DEFAULT '0.00' COMMENT '小计',
|
||||
'remarks', //text COMMENT '备注',
|
||||
'order_number', //采购订单号
|
||||
'add_time', //varchar(10) DEFAULT NULL COMMENT '添加时间',
|
||||
'build_date', //varchar(13) DEFAULT NULL COMMENT '生产日期',
|
||||
'quality_guarantee_period', //varchar(255) DEFAULT NULL COMMENT '保质期',
|
||||
'retail_price', //店内零售价
|
||||
'online_price', //商城零售价
|
||||
'serial_number_state', //串号状态 0关闭 1开启
|
||||
'goods_batch_number', //商品批号
|
||||
);
|
||||
|
||||
/**
|
||||
* 采购详情
|
||||
* @param $parameter
|
||||
* @return array
|
||||
*/
|
||||
public function getList($parameter)
|
||||
{
|
||||
if (!empty($parameter)) {
|
||||
$where = $parameter['where'];
|
||||
$page = $parameter['page'];
|
||||
$limit = $parameter['limit'];
|
||||
$list = $this->getSelect($where, $page,$limit,"goods_name,sku_name,purchase_num,sku_goods_number,attribute_state,purchase_price,goods_id,sku_id,goods_number,company", 'id asc');
|
||||
} else {
|
||||
$list = array();
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function handleList($parameter)
|
||||
{
|
||||
$sell_model = new RetailSellModel();
|
||||
$list = $parameter['list'];
|
||||
$store_id = $parameter['store_id'];
|
||||
$id = $parameter['id'];
|
||||
$map = array(
|
||||
'store_id'=>$store_id,
|
||||
'pay_state'=>1,
|
||||
'pay_type'=>array('neq',0)
|
||||
);
|
||||
foreach ($list as $key => &$val) {
|
||||
$val['index'] = $key + 1;
|
||||
$val['purchase_num'] = round($val['purchase_num'], 3);
|
||||
$val['purchase_price'] = round($val['purchase_price'], 2);
|
||||
if ($val['attribute_state'] == 2) {
|
||||
$val['goods_name'] = $val['goods_name'] . ',' . $val['sku_name'];
|
||||
$val['goods_number'] = $val['sku_goods_number'];
|
||||
}
|
||||
$map['goods_id'] = $val['goods_id'];
|
||||
$map['_string'] = "FIND_IN_SET(" . $id . ",purchase_id_str)";
|
||||
$sell_list = $sell_model->getSelect($map,"sku_json_info,supplier_json,sell_type");
|
||||
if(!empty($sell_list)){
|
||||
$val['num'] = $this->sellList($sell_list,$id,$val['sku_id']);
|
||||
}else{
|
||||
$val['num'] = 0;
|
||||
}
|
||||
$val['should_money'] = round($val['purchase_price'] * $val['num'],2);
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取售出数量
|
||||
* @param $sellList
|
||||
* @param $id 采购id
|
||||
* @param $sku_id 规格id
|
||||
* @return $num 出售数量
|
||||
*/
|
||||
public function sellList($sellList,$id,$sku_id=0)
|
||||
{
|
||||
$sell_num = 0; //出售数
|
||||
$refund_num = 0; //退款数
|
||||
foreach ($sellList as $k=>$v){
|
||||
if(!empty($sku_id)){
|
||||
$sku_json_info = json_decode($v['sku_json_info'],true);
|
||||
if($sku_id != $sku_json_info['id']){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$supplier_json = json_decode($v['supplier_json'],true);
|
||||
switch ($v['sell_type']){
|
||||
case 1:
|
||||
$sell_num += $supplier_json[$id]['num'];
|
||||
break;
|
||||
case 2:
|
||||
$refund_num += $supplier_json[$id]['num'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$num = round($sell_num - $refund_num,3);
|
||||
return $num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购总商品数
|
||||
* @param $parameter
|
||||
* @return int
|
||||
*/
|
||||
public function getListCount($parameter)
|
||||
{
|
||||
if (!empty($parameter)) {
|
||||
$count = $this->getCount($parameter['where']);
|
||||
} else {
|
||||
$count = 0;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户