You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

136 lines
5.6 KiB

<?php
namespace app\admin\controller\ykjp\inventory;
use app\common\controller\Backend;
use think\Db;
/**
* 商品单位
*
* @icon fa fa-circle-o
*/
class Statement extends Backend {
/**
* Statement模型对象
* @var \app\admin\model\ykjp\inventory\Statement
*/
protected $model = null;
public function _initialize() {
parent::_initialize();
$this->model = new \app\admin\model\ykjp\inventory\Statement;
$this->view->assign("typeList", $this->model->getTypeList());
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index() {
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
// if ($this->request->request('keyField')) {
// return $this->selectpage();
// }
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = Db::name('ykjp_inventory_statement')
->alias('i')
->join('shopro_goods_sku_price p', 'i.product_id = p.id')
->join('shopro_goods g', 'g.id = p.goods_id')
->where($where)
->where("i.firmid", $this->auth->firmid)
->order('i.id', $order)
->count();
$list = Db::name('ykjp_inventory_statement')
->alias('i')
->join('shopro_goods_sku_price p', 'i.product_id = p.id')
->join('shopro_goods g', 'g.id = p.goods_id')
// ->field('i.*,p.name,p.unit,p.prop,p.sku,p.specification,p.product_code,p.product_type_id')
->field('i.*,p.goods_id,p.goods_sku_text,p.id')
->where($where)
->where("i.firmid", $this->auth->firmid)
->order('i.id', $order)
->limit($offset, $limit)
->select();
foreach ($list as &$value) {
$goods = Db::name('shopro_goods')->where('id', $value['goods_id'])->find();
//$value['product_type_name'] = Db::name('ykjp_product_type')->where('id',$value['product_type_id'])->value('name');
$value['product_type_name'] = Db::name('shopro_category')->where('id', explode(",", $goods['category_ids'])[0] ?? 0)->value('name');
$value['prop'] = $value['goods_sku_text'];
$value['sku'] = $value['id'];
$value['name'] = $goods['title'] ?? "";
$value['product_code'] = $goods['id'] ?? 0;
//获取所在仓库名称
$warehouse = Db::name('ykjp_warehouse')
->field('name')
// ->where("firmid", $this->auth->firmid)
->where('id', $value['warehouse_id'])
->find();
// var_dump($value['warehouse_id']);
// exit();
$value['w_name'] = $warehouse['name'] ?? "";
}
$list = collection($list)->toArray();
// 根据字段中储存的id,获取实际的值
// for ($i = 0; $i < count($list); $i++) {
// $w_id = $list[$i]['warehouse_id']; //所在仓库id
// $p_id = $list[$i]['partition_id']; //所在库区id
// $prop_list = json_decode($list[$i]['prop'], true); //获取商品属性列表
// $prop = '';
// if (isset($prop_list)) {
// // 解析商品属性
// for ($j = 0; $j < count($prop_list); $j++) {
// if (isset($prop_list[$j]['title'])) {
// $title = $prop_list[$j]['title'];
// } else {
// $title = '';
// }
// if (isset($prop_list[$j]['value'])) {
// $value = $prop_list[$j]['value'];
// } else {
// $value = '';
// }
// $prop .= $title . ':' . $value . ';';
// }
// }
// $list[$i]['prop'] = $prop; //商品属性
// //获取所在仓库名称
// $warehouse = Db::name('ykjp_warehouse')
// ->field('name')
// ->where("firmid", $this->auth->firmid)
// ->where('id', $w_id)
// ->find();
// $list[$i]['w_name'] = $warehouse['name'];
// //获取所在库区名称
// $partition = Db::name('ykjp_partition')
// ->field('name')
// ->where("firmid", $this->auth->firmid)
// ->where('id', $p_id)
// ->find();
// $list[$i]['p_name'] = $partition['name'];
// }
//获取仓库
$result = array("total" => $total, "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}