isAjax()) { $goods = new GoodsModel(); $page = input('page', 1); $page_size = input('page_size', PAGE_LIST_ROWS); $keywords = input('keywords', ''); $goods_id = input('goods_id', ''); $condition = [ ['sg.site_id', '=', $this->site_id], ['sg.api_type', '=', 'allcategory'], ]; if ($keywords) { $condition[] = [ 'g.goods_name', 'like', "%{$keywords}%" ]; } if ($goods_id) { $condition[] = [ 'g.goods_id', '=', $goods_id ]; } $data = $goods->getGoodsPageList($condition, '*', 'id desc', $page, $page_size); return $data; } else { $category = (new Category())->getCategoryByParent($this->site_id, 1, 0, 1); $category_two = (new Category())->getCategoryByParent($this->site_id, 1, 0, 2); $category_three = (new Category())->getCategoryByParent($this->site_id, 1, 0, 3); $this->assign('first_cat_one', $category['data']); $this->assign('first_cat_two', $category_two['data']); $this->assign('first_cat_three', $category_three['data']); $this->assign('Package', $category_three['data']); $this->forthMenu(); return $this->fetch("goods/index"); } } /*** * 获取本地生活生商品 * @return array|mixed */ public function lifelists() { if (request()->isAjax()) { $goods = new GoodsModel(); $page = input('page', 1); $page_size = input('page_size', PAGE_LIST_ROWS); $condition = [ 'sg.site_id' => $this->site_id, 'sg.api_type' => 'localitem', ]; $data = $goods->getGoodsPageList($condition, '*', 'id desc', $page, $page_size); return $data; } else { $category = (new Category())->getCategoryByParent($this->site_id, 1, 0, 1, 'localitem'); $first_cat_two = (new Category())->getCategoryByParent($this->site_id, 1, 0, 2, 'localitem'); $this->assign('first_cat_one', $category['data']); $this->assign('first_cat_two', $first_cat_two['data']); $this->assign('shop_info', $this->shop_info); $this->forthMenu(); return $this->fetch("goods/local"); } } /*** * 添加商品 * @return array|void */ public function add() { if (request()->isAjax()) { if ($this->shop_info['site_status'] <= 0) { return error('', '您的店铺已到期'); } $param = input(); if (empty($param)) error('必要参数必填'); $api_type = input('api_type', 'allcategory'); $item_type = input('item_type', ''); $merchant_name = input('merchant_name', ''); $phone_number = input('phone_number', ''); $data = [ 'site_id' => $this->site_id, 'goods_ids' => $param['goods_ids'], 'cat_id' => $param['cat_id'], ]; $goods_model = new GoodsModel(); if ($api_type == 'localitem') { $data = request()->post(); $data['site_id'] = $this->site_id; return $goods_model->localitemAddGoods($data, $item_type, $merchant_name, $phone_number); } else { return $goods_model->addGoods($data, $api_type); } } $this->assign('shop_info', $this->shop_info); $api_type = input('api_type', 'localitem'); $this->assign('api_type', $api_type); return $this->fetch('goods/add'); } /** * 修改商品分类 */ public function edit() { $goods_model = new GoodsModel(); $api_type = input('api_type', 'localitem'); if (request()->isAjax()) { $param = input(); if (empty($param)) $this->error('必要参数必填'); $api_type = input('api_type', 'allcategory'); $data = [ 'site_id' => $this->site_id, 'goods_id' => $param['goods_id'], 'cat_id' => $param['cat_id'], ]; if ($api_type == 'localitem') { $goods_id = input('goods_id'); $item_type = input('item_type'); $data = request()->post(); return $goods_model->updateGoodslocalitemGoods($goods_id, $data, $item_type); } else { return $goods_model->updateGoods($data, $api_type); } } if ($api_type == 'localitem') { $goods_id = input('goods_id'); $groupbuy_model = new GroupbuyModel(); //获取团购信息 $condition = [ ['pg.goods_id', '=', $goods_id], ['pg.site_id', '=', $this->site_id], ['g.goods_state', '=', 1], ['g.is_delete', '=', 0] ]; $groupbuy_info = $groupbuy_model->getGroupbuyInfo($condition)['data']; $this->assign('groupbuy_info', $groupbuy_info); $this->assign('shop_info', $this->shop_info); $this->assign('api_type', $api_type); $this->assign('category_id', input('category_id')); return $this->fetch('goods/edit'); } } /*** * 同步商家产品 * @return array */ public function sync() { $start = input('start', 0); $api_type = input('api_type', 'allcategory'); $res = (new GoodsModel())->syncGoods($start, 20, $this->site_id, $api_type); return $res; } public function syncGoods() { $goods_id = input('goods_id'); $goods_model = new GoodsModel(); if (request()->isAjax()) { $data = request()->post(); $api_type = input('api_type'); if ($api_type != 'allcategory') { $res = $goods_model->PushLocaSyncGoodsInfo($goods_id, $data); } else { $res = $goods_model->PushPTSyncGoodsInfo($goods_id, $data); } return $res; } $join = [ ['goods g', 'g.goods_id=a.goods_id', 'right'] ]; $where = [ ['g.goods_id', '=', $goods_id] ]; $goods_info = $goods_model->getGoodsInfo($where, 'g.*,a.category_id', 'a', $join); $this->assign('goods_info', $goods_info); $this->assign('goods_id', $goods_id); $this->assign('shop_info', $this->shop_info); $this->assign('alipaycategory_id', $goods_info['category_id'] ?: ''); return $this->fetch('goods/syncGoods'); } /*** * 上传库存价格 * @return array */ public function syncrenew() { $goods_id = input('goods_id'); $api_type = input('api_type'); if ($api_type != 'allcategory') { $res = (new GoodsModel())->syncLocalitemPrice($goods_id, $this->site_id); } else { $res = (new GoodsModel())->syncDtockPrice($goods_id, $this->site_id, $api_type); } return $res; } /*** * 下架 * @return array */ public function goodsDelisting() { $out_item_id = input('out_item_id', ''); $res = (new GoodsModel())->goodsDelisting($out_item_id, $this->site_id); return $res; } /*** * 上架 * @return array */ public function listing() { $out_item_id = input('out_item_id', ''); $res = (new GoodsModel())->goodsListing($out_item_id, $this->site_id); return $res; } /** * 小程序删除商品 */ public function delete() { if (request()->isAjax()) { $goods_model = new GoodsModel(); return $goods_model->deleteGoods(input('out_item_id', ''), $this->site_id); } } }