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.
 
 
 
 
 
 

159 lines
6.0 KiB

<?php
namespace app\admin\controller\ykjp\inventory;
use app\common\controller\Backend;
use think\Db;
/**
* 商品库存
*
* @icon fa fa-circle-o
*/
class Wp extends Backend {
/**
* Wp模型对象
* @var \app\admin\model\ykjp\inventory\Wp
*/
protected $model = null;
// protected $distinguish=true;
public function _initialize() {
parent::_initialize();
$this->model = new \app\admin\model\ykjp\inventory\Wp;
}
/**
* 查看
*/
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 = $this->model
->alias('w')
->join('shopro_goods_sku_price p', 'w.product_id = p.id')
->join('shopro_goods g', 'g.id = p.goods_id')
->where($where)
// ->where("w.firmid", $this->auth->firmid)
->order('w.id', $order)
->count();
$list = $this->model
->alias('w')
//->field('w.*,p.name,p.unit,p.sku,p.prop,p.specification,p.product_code,p.product_type_id')
->field('w.*,p.goods_id,p.goods_sku_text,p.id')
->join('shopro_goods_sku_price p', 'w.product_id = p.id')
->join('shopro_goods g', 'g.id = p.goods_id')
->where($where)
// ->where("w.firmid", $this->auth->firmid)
->order('w.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();
}
/**
* 联动获取仓库
*/
public function getWP() {
//参考开发示例中的自定义搜索
$type = $this->request->get('type');
$partition_id = $this->request->get('partition_id');
$list = null;
if ($partition_id !== '') {
if ($type == 'whouse') {
//获取仓库列表
$list = Db::name('ykjp_warehouse')
->field('id as value,name')
->where("firmid", $this->auth->firmid)
->select();
} else {
//获取库区列表
$list = Db::name('ykjp_partition')
->field('id as value,name')
->where("firmid", $this->auth->firmid)
->where('warehouse_id', $partition_id)
->select();
}
}
$this->success('', null, $list);
}
}