173 行
6.4 KiB
PHP
可执行文件
173 行
6.4 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Sellapi\Controller;
|
|
//[1.3.64]
|
|
use Think\Controller;
|
|
|
|
class CallController extends Controller
|
|
{
|
|
//获取子级元素
|
|
public function getChildClass()
|
|
{
|
|
$id = I('post.id');
|
|
$type = I('post.type');
|
|
if ($type == 2) {
|
|
$class = M('retail_goods_class as c1')
|
|
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
|
|
->where(array('c1.id' => $id, 'c2.status' => 0))
|
|
->field('c2.id,c2.class_name')
|
|
->order('c2.code asc')
|
|
->select();
|
|
} else {
|
|
$class = M('retail_goods_class as c2')
|
|
->join('ls_retail_goods_class as c3 on c2.id=c3.pid')
|
|
->where(array('c2.id' => $id, 'c3.status' => 0))
|
|
->field('c3.id,c3.class_name')
|
|
->order('c3.code asc')
|
|
->select();
|
|
}
|
|
if (!empty($class)) {
|
|
$result['status'] = 1;
|
|
$result['data'] = $class;
|
|
$result['msg'] = '查询成功';
|
|
} else {
|
|
$result['status'] = 0;
|
|
$result['msg'] = '暂无分类';
|
|
}
|
|
$this->ajaxReturn($result);
|
|
}
|
|
|
|
//获取这个门店所有的分类
|
|
public function getCate()
|
|
{
|
|
$merchantid = I("post.merchantid");
|
|
//array('merchantid' => , 'status' => 0, 'type' => 1);
|
|
$where["merchantid"] = $merchantid;
|
|
$where["status"] = 0;
|
|
$where["type"] = 1;
|
|
$class_name = M('retail_goods_class')->where($where)->order('code asc')->select();
|
|
if (!empty($class_name)) {
|
|
$data["status"] = 1;
|
|
$data["data"] = $class_name;
|
|
} else {
|
|
$data["status"] = 0;
|
|
$data["data"] = "无分类" . $merchantid;
|
|
}
|
|
$this->ajaxReturn($data);
|
|
}
|
|
|
|
//获取所有称重的商品
|
|
public function getShop()
|
|
{
|
|
$storeid = I("post.storeid");
|
|
if (!$storeid) {
|
|
$data["status"] = 1;
|
|
$data["msg"] = "参数错误,请检查";
|
|
} else {
|
|
$where['store_id'] = $storeid;
|
|
$where["pricing_method"] = 2;
|
|
$where['status'] = array('in', array(0, 1));
|
|
//根据条件获取商品信息
|
|
$goods_number = I('post.good_number');
|
|
if (!empty($goods_number)) {
|
|
$keyword = trim($goods_number, ' ');
|
|
if (is_numeric($keyword)) {
|
|
//纯数字直接走查询货号
|
|
$where['goods_number|goods_code'] = $keyword;
|
|
} else {
|
|
$where['goods_name'] = array('like', '%' . $keyword . '%');
|
|
}
|
|
}
|
|
$person1 = I('post.person1');
|
|
$person2 = I('post.person2');
|
|
$person3 = I('post.person3');
|
|
//查询文件
|
|
if (!empty($person3)) {
|
|
$where['goods_class_id'] = $person3;
|
|
} else if (!empty($person1)) {
|
|
$class = M('retail_goods_class as c1')
|
|
->join('ls_retail_goods_class as c2 on c1.id=c2.pid')
|
|
->join('ls_retail_goods_class as c3 on c2.id=c3.pid AND c3.status=0', 'LEFT')
|
|
->where(array('c1.id' => $person1, 'c2.status' => 0))
|
|
->field('c2.id,c3.id as c3_id')->select();
|
|
$flag = 1;
|
|
}
|
|
if (!empty($class)) {
|
|
$arr = array();
|
|
foreach ($class as &$val) {
|
|
if (!in_array($val['id'], $arr)) {
|
|
$arr[] = $val['id'];
|
|
}
|
|
if (!empty($val['c3_id'])) {
|
|
if (!in_array($val['c3_id'], $arr)) {
|
|
$arr[] = $val['c3_id'];
|
|
}
|
|
}
|
|
}
|
|
$str = implode(',', $arr);
|
|
$where['goods_class_id'] = array('in', $str . ',' . ($person2 ? $person2 : $person1));
|
|
} else if ($flag == 1) {
|
|
$where['goods_class_id'] = $person2 ? $person2 : $person1;
|
|
}
|
|
//只获取称重商品
|
|
$goods = M('retail_goods')
|
|
->field("plu_code,id,goods_number as good_number,goods_name,goods_code,retail_price,goods_class_id,shelf_life")
|
|
->where($where)
|
|
->order('goods_number desc')
|
|
->select();
|
|
$number = M('retail_goods')->where($where)->order('plu_code desc')->getField('plu_code');
|
|
$number = $number ? $number : 1;
|
|
foreach ($goods as $key => &$value) {
|
|
$value['cate_name'] = M('retail_goods_class')->where(array('id' => $value['goods_class_id']))->getField('class_name');
|
|
$value['goods_number'] = $value['good_number'];
|
|
if ($value["plu_code"]) {
|
|
$value["good_plu"] = $value["plu_code"];
|
|
} else {
|
|
$value["good_plu"] = $number++;
|
|
}
|
|
if (empty($value['shelf_life'])) {
|
|
$value['shelf_life'] = '000';
|
|
} else {
|
|
$time = round(($value['shelf_life'] - time()) / 86400);
|
|
if ($time > 999) {
|
|
$time = '999';
|
|
} else if ($time < 1) {
|
|
$time = '000';
|
|
} else {
|
|
$time = str_pad($time, '3', '0', STR_PAD_LEFT);
|
|
}
|
|
$value['shelf_life'] = strval($time);
|
|
}
|
|
}
|
|
//获取商品的所有数量
|
|
$goods_count = M('retail_goods')
|
|
->where($where)
|
|
->count();
|
|
$data['code'] = 0;
|
|
$data['msg'] = '';
|
|
$data['count'] = $goods_count;
|
|
$data['data'] = $goods;
|
|
}
|
|
$this->ajaxReturn($data);
|
|
}
|
|
|
|
//可以修改价钱和商品名称 或者plu值
|
|
public function changeData()
|
|
{
|
|
$id = I("post.id");
|
|
$data = I("post.");
|
|
$map["id"] = $id;
|
|
$data["plu_code"] = $data["good_plu"];
|
|
unset($data['shelf_life']);
|
|
unset($data['good_number']);
|
|
$cache = M("retail_goods")->where($map)->save($data);
|
|
if ($cache) {
|
|
$datas["status"] = 1;
|
|
$datas["msg"] = "修改成功,后台已同步";
|
|
} else {
|
|
$datas["status"] = 0;
|
|
$datas["msg"] = "修改失败,请检查";
|
|
}
|
|
$this->ajaxReturn($datas);
|
|
}
|
|
} |