alias('g') ->join('ls_retail_goods_class as c on g.' . $this::GOODS_CLASS_ID . '=c.id') ->where($where) ->field($field) ->page($page) ->order($order) ->select(); $count = $this->alias('g') ->join('ls_retail_goods_class as c on g.' . $this::GOODS_CLASS_ID . '=c.id') ->where($where) ->field($field) ->page($page) ->order($order) ->count(); $goods = array( 'list' => $list, 'count' => $count, ); } else { $goods = $this->alias('g') ->join('ls_retail_goods_class as c on g.' . $this::GOODS_CLASS_ID . '=c.id') ->where($where) ->field($field) ->order($order) ->select(); } return $goods; } /*商品数量作为条件查询商品列表 * * @param $where 条件 * @param $field 查询的字段 */ public function getGoodsList($where, $field, $order) { $field = $field ? $field : 'g.*'; $order = $order ? $order : 'g.id desc'; $info = $this->alias('g') ->join('ls_retail_store_sale_goods as s on g.id=s.goods_id', 'LEFT') ->where($where) ->field($field) ->select(); return $info; } /** * 商城商品列表获取 */ public function getOnlineGoods($where, $fileds, $order, $page) { $fileds = $fileds ? $fileds : 'g.*'; $order = $order ? $order : 'g.id desc'; $info = $this->alias('g') ->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT') ->field($fileds) ->where($where) ->order($order) ->page($page) ->select(); return $info; } /** * 商城商品列表获取 */ public function getOnlineCount($where) { $info = $this->alias('g') ->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT') ->where($where) ->count(); return $info; } /** * 获取分类及商品 * @param $map 查询条件 * @param $fields 选取字段 * @param $page 页码 * @param $limit 页数 * @return array */ public function getClassGoodsList($map, $fields, $page, $limit) { $list = $this->alias('g') ->join('ls_retail_goods_class as c on g.' . $this::GOODS_CLASS_ID . '=c.id') ->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT') ->where($map) ->field($fields) ->order('c.code asc,g.goods_order asc,g.id desc') ->page($page, $limit) ->select(); return $list ? $list : array(); } /** * 获取分类及商品 * @param $map 查询条件 * @param $fields 选取字段 * @param $page 页码 * @param $limit 页数 * @return array */ public function getSaleGoodsList($map, $fields, $page, $limit) { $list = $this->alias('g') ->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT') ->where($map) ->field($fields) ->order('g.goods_order asc,g.id desc') ->page($page, $limit) ->select(); return $list ? $list : array(); } /** * 获取分类及商品 * @param $map 查询条件 * @param $fields 选取字段 * @param $page 页码 * @param $limit 页数 * @return array */ public function getSaleGoodsCount($map) { $count = $this->alias('g') ->join('ls_retail_store_sale_goods as s on g.id=s.goods_id and s.attribute_state=1', 'LEFT') ->where($map) ->count(); return $count; } /** * 查询多条 * @param $map 查询条件 * @param string $field 获取的字段类型 * @param string $order 排序规则 * @param int $limit 获取的数量 * @return mixed */ public function getLimitSelect($map, $field = '*', $order = 'id asc', $limit = 20) { $res = $this->field($field)->where($map)->order($order)->limit($limit)->select(); return $res; } /** * 获取商品列表,如果商品在参加促销则把促销状态及价格返回 * @param $map * @param string $fields * @param string $order * @param string $page * @return array */ public function getHostGoods($map, $fields = '*', $order = 'g.goods_order asc,g.id desc', $page = '1,10') { if (empty($map)) { return array(); } $time = time(); $list = $this->alias('g') ->join("ls_retail_host as h on g.id=h.goods_id AND h.type=2 AND h.starttime<={$time} AND h.endtime>={$time} AND h.state=1 AND h.status=1", 'LEFT') ->join('ls_goods_label_link as link on link.goods_id = g.id', 'LEFT') ->join('ls_label_inventory as inve on inve.id = link.label_id', 'LEFT') ->where($map) ->order($order) ->group('g.id') ->page($page) ->field($fields) ->select(); return $list; } /** * 获取商品列表,如果商品在参加促销则把促销状态及价格返回 * @param $map * @param string $fields * @param string $order * @param string $page * @return array */ public function getUnHostGoods($map, $fields = '*', $order = 'g.goods_order asc,g.id desc', $page = '1,10') { if (empty($map)) { return array(); } $list = $this->alias('g') ->join('ls_goods_label_link as link on link.goods_id = g.id', 'LEFT') ->join('ls_label_inventory as inve on inve.id = link.label_id', 'LEFT') ->where($map) ->order($order) ->group('g.id') ->page($page) ->field($fields) ->select(); return $list; } public function getGoodsBrand($map) { if (empty($map)) { return []; } return $this->alias('g') ->join('ls_goods_label_link as link on link.goods_id = g.id', 'LEFT') ->join('ls_label_inventory as inve on inve.id = link.label_id', 'LEFT') ->join('ls_retail_goods_brand as brand on g.goods_brand_id = brand.id', 'LEFT') ->where($map) ->group('g.goods_brand_id') ->field('brand.id, brand.name') ->select(); } /** * 配送模板-批量使用-获取商品(普通、拼团、秒杀)信息 * @param $store_id * @param $keyword * @param $goods_type 类型 1普通商品 2拼团 3秒杀 * @param $template_id * @param $pricing_method * @param $page * @param $limit * @return mixed */ public function batchUsageGoodsInfo($store_id, $keyword, $goods_type, $template_id, $pricing_method, $page, $limit) { $map = array( 'g.store_id' => $store_id, 'g.status' => array('in', '0,1'), ); if ($keyword != '' && $keyword != null) { $map['g.goods_name|g.goods_number|g.goods_code'] = array('like', '%' . $keyword . '%'); } if (!empty($pricing_method)) { $map[] = array( 'g.pricing_method' => $pricing_method, 'g.weight_value' => array('gt', 0), '_logic' => 'OR' ); } $join_name = 'g'; $join = null; $fields = 'g.goods_name,g.goods_number,g.goods_code,g.pricing_method,g.retail_price,t.title'; $order = 'g.id desc'; switch ($goods_type) { case '1': //普通商品 $fields = 'g.id,g.delivery_type,' . $fields; break; case '2': //拼团 $join = 'ls_retail_spellgroup as s on s.gid = g.id'; $join_name = 's'; $order = 's.id desc'; $fields = 's.id,s.actname as act_name,s.actprice as act_price,s.send_type as delivery_type,' . $fields; $map['s.acttype'] = 1; //拼团活动正常 break; case '3': //秒杀 $join = 'ls_retail_seckill as s on s.gid = g.id'; $join_name = 's'; $order = 's.id desc'; $fields = 's.id,s.active_title as act_name,s.goods_seckill_price as act_price,s.send_type as delivery_type,' . $fields; $map['s.active_status'] = 1; //秒杀活动正常 break; case '4': //预售 $join = 'ls_retail_advance_goods as a on a.goods_id = g.id'; $join_name = 'a'; $order = 'a.id desc'; $fields = 'a.id,a.advance_price as act_price,a.delivery_type,' . $fields; $map['a.advance_state'] = 1; //预售活动正常 break; } if (!empty($template_id)) { $map[$join_name . '.delivery_template_id'] = $template_id; } $sql = $this->alias('g'); if ($join) { $sql = $sql->join($join); } $list = $sql->join("ls_delivery_template as t on {$join_name}.delivery_template_id = t.id AND (t.status=1 OR t.status=2) AND t.state=1", 'LEFT') ->field($fields) ->where($map) ->order($order) ->page($page, $limit) ->select(); $sql = $this->alias('g'); if ($join) { $sql = $sql->join($join); } $count = $sql->join("ls_delivery_template as t on {$join_name}.delivery_template_id = t.id AND (t.status=1 OR t.status=2) AND t.state=1", 'LEFT') ->where($map) ->count(); foreach ($list as &$value) { $value['delivery_type'] = $value['delivery_type'] ? json_decode('[' . $value['delivery_type'] . ']', true) : array(); if ($goods_type == 4) { $value['act_price'] = $value['act_price'] ? $value['act_price'] : '规格活动价'; } } return array( 'list' => $list, 'count' => $count, ); } /** * 更新商品所在的模板 * @param $goodsList 商品、拼团、秒杀ID, json数组[{"id":"1","delivery_type":"1,2,3"}] * @param $templateId 模板ID * @param $goods_type 类型 1普通商品 2拼团 3秒杀 * @return mixed */ public function batchUsage($goodsList, $templateId, $goods_type) { $goodsList = json_decode($goodsList, true); if (!$goodsList) { return false; } $res = array(); switch ($goods_type) { case '1': $activity_model = $this; break; case '2': $activity_model = new RetailGroupModel(); break; case '3': $activity_model = new RetailSpikeModel(); break; case '4': $activity_model = new AdvanceGoodsModel(); break; } $up = array('delivery_template_id' => $templateId); foreach ($goodsList as $value) { $map = array( 'id' => array('in', $value['id']) ); $updateRet = false; switch ($goods_type) { case '1': //普通商品 $up['delivery_type'] = $value['delivery_type']; break; case '2': //拼团 $up['send_type'] = $value['delivery_type']; break; case '3': //秒杀 $up['send_type'] = $value['delivery_type']; break; case '4': $up['delivery_type'] = $value['delivery_type']; break; } $updateRet = $activity_model->updateOrder($map, $up); if ($updateRet) { $res[] = 1; } } return count($res); } /** * 查询门店商品 分页 * @param $where 查询条件 * @param $page 当前页 * @param $limit 每页记录数 * @return $list */ public function selectStoreGoods($where, $page, $limit) { $list = $this->field('id,goods_name') ->where($where) ->page($page, $limit) ->order('add_time desc') ->select(); return $list; } /** * 编辑商品时验证开启预售该商品是否参与促销秒杀拼团活动 * @param $parameter * @return mixed */ public function advance_open_verify($parameter) { if (is_array($parameter)) { $store_id = $parameter['store_id']; $goods_id = $parameter['goods_id']; if (empty($store_id) || empty($goods_id)) { $res = array('status' => 0, 'msg' => '参数缺失'); return $res; } $host_map = array( 'storeid' => $store_id, 'goods_id' => $goods_id, 'type' => 2, 'state' => 1, 'status' => 1, 'endtime' => array('gt', time()), ); $host_info = D("RetailHost")->getFind($host_map); if ($host_info) { $res = array('status' => 0, 'msg' => '该商品已参与促销,不能与预售同时参与'); return $res; } $group_map = array( 'storeid' => $store_id, 'gid' => $goods_id, 'acttype' => 1, 'endtime' => array('gt', time()), ); $group_info = D("RetailGroup")->getFind($group_map); if ($group_info) { $res = array('status' => 0, 'msg' => '该商品已参与拼团,不能与预售同时参与'); return $res; } $seckill_map = array( 'storeid' => $store_id, 'gid' => $goods_id, 'active_status' => 1, 'active_endtime' => array('gt', time()) ); $seckill_info = D("RetailSeckill")->getFind($seckill_map); if ($seckill_info) { $res = array('status' => 0, 'msg' => '该商品已参与秒杀,不能与预售同时参与'); return $res; } $res = array('status' => 1, 'msg' => '验证成功'); } else { $res = array('status' => 0, 'msg' => '验证失败,参数类型错误'); } return $res; } /** * 编辑商品档案时验证是否可以关闭预售 */ public function advance_close_verify($parameter) { if (is_array($parameter)) { $store_id = $parameter['store_id']; $goods_id = $parameter['goods_id']; $AdvanceGoodsModel = D("AdvanceGoods"); $advance_map = array( 'store_id' => $store_id, 'goods_id' => $goods_id, 'advance_state' => 1 ); $advance_end_time = $AdvanceGoodsModel->getOrderFindField($advance_map,'advance_end_time','id desc'); if (!empty($advance_end_time) && $advance_end_time > time()) { $res['status'] = 0; $res['msg'] = "该商品已参与预售,请先关闭该商品预售活动"; return $res; } $res['status'] = 1; $res['msg'] = '验证成功'; } else { $res['status'] = 0; $res['msg'] = '参数类型错误'; } return $res; } /** * 商户调拨门店的普通商品库存详情 * @param $parameter * [ * merchant_goods_id 商户商品id * merchant_id * ] * @return mixed */ public function getSyncMerchantGoodsInfo($parameter) { $where = array( 'g.merchant_id' => $parameter['merchant_id'], 'g.status' => array('in', '0,1'), 'g.m_goods_id' => $parameter['merchant_goods_id'], 's.status' => array('in', '0,1') ); $page = $parameter['page'] ? $parameter['page'] : 1; $limit = $parameter['limit'] ? $parameter['limit'] : 10; $list = $this->alias('g') ->join('ls_retail_store_sale_goods as s on g.id=s.goods_id') ->field("s.store_id,s.goods_num,s.id,s.goods_id,s.serial_number_state") ->where($where) ->page($page, $limit) ->select(); return $list; } /** * 商户调拨门店的普通商品库存详情 * @param $parameter * [ * merchant_goods_id 商户商品id * merchant_id * ] * @return mixed */ public function getSyncMerchantGoodsCount($parameter) { $where = array( 'g.merchant_id' => $parameter['merchant_id'], 'g.status' => array('in', '0,1'), 'g.m_goods_id' => $parameter['merchant_goods_id'], 's.status' => array('in', '0,1') ); $count = $this->alias('g') ->join('ls_retail_store_sale_goods as s on g.id=s.goods_id') ->where($where) ->count(); return $count ? $count : 0; } /** * 判断该门店的商品是否有使用的分类属于该行业的 */ public function getStoreIsUseClassIndustry($where) { $result = $this->alias('goods') ->join('ls_retail_goods_class as class on class.id = goods.goods_class_id') ->join('ls_store_industry as industry on industry.id = class.industry_id') ->where($where) ->count(); return $result; } }