alias('c') ->join('ls_retail_goods as g on c.' . $this::GOODS_ID . '=g.id') ->where($where) ->field($field) ->page($page) ->order($order) ->select(); } else { $collect = $this->alias('c') ->join('ls_retail_goods as g on c.' . $this::GOODS_ID . '=g.id') ->where($where) ->field($field) ->order($order) ->select(); } return $collect; } /** * 获取商品列表及促销信息 * @param $map * @param string $fields * @param string $order * @param string $page * @return array */ public function getPromotionGoods($map, $fields = '*', $order = 'c.id desc', $page = '1,10') { if (empty($map)) { return array(); } $time = time(); $list = $this->alias('c') ->join("ls_retail_goods as g on g.id=c.goods_id") ->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') ->where($map) ->order($order) ->group('g.id') ->page($page) ->field($fields) ->select(); return $list; } /** * 验证收藏或取消收藏参数 */ protected function verify_parameter($parameter) { if(empty($parameter['goods_id'])){ $res = array( 'status'=>0, 'msg'=>'缺少商品信息' ); return $res; } if (empty($parameter['uid'])) { $res['status'] = -1; $res['msg'] = '用户未登录'; return $res; } if(!empty($parameter['activity_id'])){ if(empty($parameter['type'])){ $res = array( 'status'=>0, 'msg'=>'缺少活动类型' ); return $res; } } $res = array( 'status'=>1, 'msg'=>'验证成功' ); return $res; } /** * 添加收藏 */ public function addCollect($parameter) { $verify = $this->verify_parameter($parameter); if($verify['status'] != 1){ return $verify; } $content = array( self::GOODS_ID=>$parameter['goods_id'], self::STORE_ID=>$parameter['store_id'], self::MERCHANT_ID=>$parameter['merchant_id'], self::UID=>$parameter['uid'], self::ADD_TIME=>time() ); $where = array( self::GOODS_ID => $content[self::GOODS_ID], self::UID => $content[self::UID] ); if(!empty($parameter['activity_id'])){ $content[self::ACTIVITY_ID] = $parameter['activity_id']; $content[self::TYPE] = $parameter['type']; $where[self::ACTIVITY_ID] = $parameter['activity_id']; $where[self::TYPE] = $parameter['type']; } $exist = $this->getFind($where); if ($exist) { $res = array( 'status'=>0, 'msg'=>'您已收藏' ); return $res; } $add_collect = $this->addOrder($content); if ($add_collect) { $res = array( 'status'=>1, 'msg'=>'收藏成功', 'data'=>array( 'id'=>$add_collect ) ); } else { $res = array( 'status'=>0, 'msg'=>'收藏失败' ); } return $res; } /** * 取消收藏 */ public function cancelCollect($parameter) { $verify = $this->verify_parameter($parameter); if($verify['status'] != 1){ return $verify; } $where = array( self::GOODS_ID=>$parameter['goods_id'], self::STORE_ID=>$parameter['store_id'], self::UID=>$parameter['uid'] ); if(!empty($parameter['activity_id'])){ $where[self::ACTIVITY_ID] = $parameter['activity_id']; $where[self::TYPE] = $parameter['type']; } $cancel = $this->deleteOrder($where); if ($cancel) { $res['status'] = 1; $res['msg'] = '取消成功'; } else { $res['status'] = 0; $res['msg'] = '取消失败'; } return $res; } }