/**
* 添加商品预览
*
*/
public function goods()
{
$filter = $this->request->param('filter');
$offset = $this->request->param('offset');
$limit = $this->request->param('limit');
$startDate = $this->request->param('startDate');
$endDate = $this->request->param('endDate');
$shop_id = $this->request->param('shop_id');
if ($this->request->isAjax())
{
//list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$filters = json_decode($filter,true);
//halt($filters);
// $correlation = "wanlshop_groups.state = 'success'";
$correlation = "1 = 1";
if(!empty($filters['shopname'])){
//$db::name('wanlshop_groups_order')->where()->column('id');
$correlation .=" and wanlshop_shop.shopname like '%{$filters['shopname']}%'";
}
if(!empty($startDate)){
$starttime = strtotime($startDate);
// $correlation .=" and wanlshop_groups.deliverytime >= {$starttime}";
}
if(!empty($endDate)){
$endtime = strtotime($endDate) + 24 * 3600;
// $correlation .=" and wanlshop_groups.deliverytime < {$endtime}";
}
if(!empty($filters['status'])){
//$db::name('wanlshop_groups_order')->where()->column('id');
$correlation .=" and a.status = {$filters['status']}";
}
// $shop_id = 41;
$correlations = "sg.shop_id = {$shop_id} and o.deliveryDay >= {$starttime} and o.deliveryDay <= {$endtime}";
$GoodsModel = new \app\common\model\AgencyOrderGoods;
$list = $GoodsModel->alias('a')
// ->join('agency_goods_quotation agq','agq.id = a.agency_goods_quotation_id','LEFT')
// ->join('agency_goods ag','ag.id = agq.agency_goods_id','LEFT')
// ->join('agency_goods_category agc','ag.cid = agc.id','LEFT')
->join('agency_order o','o.id = a.agency_order_id')
->join('wanlshop_groups_goods gg','a.groups_goods_id = gg.id','LEFT')
->join('wanlshop_goods sg','gg.goods_id = sg.id','LEFT')
->join('wanlshop_category gc','sg.category_id = gc.id','LEFT')
->join('wanlshop_shop shop','sg.shop_id = shop.id')
->where($correlations)
->limit($offset, $limit)
->field('a.id,a.agency_order_id,a.number,a.price,a.groups_price,agency_shop_tax_rate,shop_tax_rate')
->field('gc.name as category_name')
->field('shop.id as shop_id,shop.shopname')
->field('gg.goods_id')
->field('sg.goods_unit_id,sg.title as goods_name')
->field('o.deliveryDay')
->order('o.deliveryDay asc,gc.weigh desc')
// ->order('o.deliveryDay desc,agc.weigh desc')
->select();
// $result = $this->handleShopGoodsData($list);
$count = $GoodsModel->alias('a')
// ->join('agency_goods_quotation agq','agq.id = a.agency_goods_quotation_id','LEFT')
// ->join('agency_goods ag','ag.id = agq.agency_goods_id','LEFT')
// ->join('agency_goods_category agc','ag.cid = agc.id','LEFT')
->join('agency_order o','o.id = a.agency_order_id')
->join('wanlshop_groups_goods gg','a.groups_goods_id = gg.id','LEFT')
->join('wanlshop_goods sg','gg.goods_id = sg.id','LEFT')
->join('wanlshop_category gc','sg.category_id = gc.id','LEFT')
->join('wanlshop_shop shop','sg.shop_id = shop.id')
->where($correlations)
->field('a.id')
->order('o.deliveryDay asc,gc.weigh desc')
// ->order('o.deliveryDay desc,agc.weigh desc')
->count();
$total = $GoodsModel->alias('a')
// ->join('agency_goods_quotation agq','agq.id = a.agency_goods_quotation_id','LEFT')
// ->join('agency_goods ag','ag.id = agq.agency_goods_id','LEFT')
// ->join('agency_goods_category agc','ag.cid = agc.id','LEFT')
->join('agency_order o','o.id = a.agency_order_id')
->join('wanlshop_groups_goods gg','a.groups_goods_id = gg.id','LEFT')
->join('wanlshop_goods sg','gg.goods_id = sg.id','LEFT')
->join('wanlshop_category gc','sg.category_id = gc.id','LEFT')
->join('wanlshop_shop shop','sg.shop_id = shop.id')
->where($correlations)
->field('sum(a.number) as number,sum(a.number * a.price) as price')
->find();
$number = round($total['number'],1);
$price = round($total['price'],2);
$list = $this->handleShopGoodsData($list);
$result = array("total" => $count, "rows" => $list, "number" => $number, "price" => $price);
return json($result);
}
return $this->view->fetch();
}
/**
* 数据处理
*
*/
public function handleShopGoodsData($list)
{
$unit_list = \app\admin\model\wanlshop\GoodsUnit::column('id,title');
foreach($list as $k=>&$v){
$v['unit_name'] = empty($unit_list[$v['goods_unit_id']]) ? '-':$unit_list[$v['goods_unit_id']];
$v['deliveryDay_str'] = empty($v['deliveryDay']) ? '-':date('Y-m-d',$v['deliveryDay']);
//进项税额 = 采购价/(1+进项税率)*进项税率
$item_shop_price = $v['groups_price']*$v['number'];
// $total['groups_price'] = round(bcadd($total['groups_price'],$item_shop_price,2),2);
$v['total_price'] = round($item_shop_price,2);
$item_shop_invoice_price = 0;
if(!empty($item_shop_price) && !empty($v['shop_tax_rate'])){
$item_shop_invoice_price = $item_shop_price/(1+$v['shop_tax_rate']/100)*$v['shop_tax_rate']/100;
$item_shop_invoice_price = round($item_shop_invoice_price,2);
}
// $total['shop_invoice_price'] = round(bcadd($total['shop_invoice_price'],$item_shop_invoice_price,2),2);
// $total['shop_invoice_price'] = $item_shop_invoice_price;
}
return $list;
}优化下以上代码
最新发布