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; } }