attributes = get_params(); $form->goods_id = get_params('goods_id'); $form->recommend_count = 6; $form->limit = 6; $form->store_id = $this->store_id; return $this->asJson($form->recommend()); } /** * 商品推荐 */ public function actionNewGoodsRecommend() { $store_id = get_store_id(); $size = intval(get_params('size', 10)); if ($size < 1) { return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [] ]); } $goods = Goods::find()->where(['store_id' => $store_id, 'status' => Goods::STATUS_NORMAL, 'is_delete' => 0, 'md_food_id' => 0, 'is_recommend' => 1]) ->andWhere(['!=', 'product_type',Goods::GOODS_TYPE_INTEGRAL]) ->orderBy('sort desc')->limit($size)->asArray()->all(); foreach ($goods as &$item) { $goods_ = Goods::findOne($item['id']); $item['virtual_sales'] = $goods_->getSalesVolume() + $item['virtual_sales']; $res = CommonGoods::getMemberPrice([ 'attr' => $item['attr'], 'price' => $item['price'], 'mch_id' => 0, 'is_level' => $item['is_level'], ]); $goodsMemberPrice = $res['min_member_price'] ? $res['min_member_price'] : $item['price']; $item['price'] = sprintf("%.2f", $goodsMemberPrice); } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $goods ]); } /** * 商品详情 */ public function actionGoods() { $form = new GoodsForm(); $form->attributes = get_params(); $form->user_id = get_user_id(); $form->store_id = $this->store_id; MochatForm::sendMsg(1, get_store_id(), MochatForm::MSG_TYPE_VIEW_GOODS, get_saas_user_id(), ['goods_id' => $form->id]); return $this->asJson($form->search()); } public function actionGoodsNum() { $form = new GoodsForm(); $form->attributes = get_params(); $form->user_id = get_user_id(); $form->store_id = $this->store_id; return $this->asJson($form->getGoodsNum()); } /** * 获取商品优惠详情 */ public function actionGetGoodsYouhui() { $form = new GoodsForm(); $form->attributes =get_params(); return $this->asJson($form->getYouhui()); } /** * 获取商品优惠详情 */ public function actionAddress() { $form = new GoodsForm(); $form->attributes = get_params(); return $this->asJson($form->getAddress()); } /** * 店铺推荐 */ public function actionMchRecommend() { $form = new GoodsForm(); $form->attributes =get_params(); return $this->asJson($form->mchRecommend()); } /** * 猜你喜欢 */ public function actionGuessLike() { $form = new GoodsForm(); $form->attributes =get_params(); return $this->asJson($form->guessLike()); } /** * 用户商品浏览量 */ public function actionUserView() { $id = post_params('id'); $user_view = UserViews::findOne(['goods_id' => $id, 'user_id' => get_user_id()]); if (!$user_view) { $user_view = new UserViews(); $user_view->store_id = get_store_id(); $user_view->user_id = get_user_id(); $user_view->goods_id = $id; $user_view->views = 1; $user_view->save(); return [ 'code' => 0, 'msg' => '添加成功' ]; } $user_view->views += 1; $user_view->save(); return [ 'code' => 0, 'msg' => '添加成功' ]; } /** * 商品详情页门店信息接口 */ public function actionMdAddress() { $latitude = get_params('latitude', 0); $longitude = get_params('longitude', 0); $md_id = get_md_id(); $shop_table_name = Md::tableName(); $store_id = get_store_id(); $sql = "SELECT *, acos(cos({$latitude}*pi()/180 )*cos(latitude*pi()/180)*cos({$longitude}*pi()/180 -longitude*pi()/180)+sin({$latitude}*pi()/180 )*sin(latitude*pi()/180))*6370996.81 as distance FROM {$shop_table_name} WHERE `id`=:id "; $sql = \Yii::$app->db->quoteSql($sql); $md = \Yii::$app->db->createCommand($sql, [ ':id' => $md_id, ])->queryOne(); $md['distance'] = MdListForm::distance($md['distance']); return $this->asJson([ 'code' => 0, 'data' => $md ]); } /** * 模块名:actionGoodsLoweringPrice * 代码描述:商品订阅降价通知 * 作者:WPing丶 * 请求方式:GET * 创建时间:2024/03/11 14:18:20 * @param int id 商品id * @param float price 期望价格 */ public function actionGoodsLoweringPrice() { $id = get_params('id', 0); $goods = Goods::find()->where(['id' => $id, 'is_delete' => 0, 'status' => Goods::STATUS_NORMAL])->asArray()->one(); if(!$goods) { return $this->asJson([ 'code' => 1, 'msg' => '商品不存在或已下架' ]); } // $price = get_params('price', 0); $user_id = get_user_id(); $store_id = get_store_id(); $model = GoodsLoweringPrice::findOne(['goods_id' => $id, 'user_id' => $user_id, 'store_id' => $store_id, 'is_delete' => 0]); if(!$model) { $model = new GoodsLoweringPrice(); $model->store_id = $store_id; $model->user_id = $user_id; $model->goods_id = $id; $model->saas_id = get_saas_user_id(); } $model->created_at = time(); $model->is_delete = 0; $model->type = 0; $res = CommonGoods::getMemberPrice($goods); $model->price = $res['min_member_price'] ? $res['min_member_price'] : $goods['price']; if(!$model->save()) { return $this->asJson([ 'code' => 1, 'msg' => '保存GoodsLoweringPrice表失败' ]); } else { return $this->asJson([ 'code' => 0, 'msg' => '订阅降价通知成功', 'is_lowering' => true, ]); } } /** * 模块名:actionGoodsLoweringPrice * 代码描述:商品订阅降价通知 * 作者:WPing丶 * 请求方式:GET * 创建时间:2024/03/11 14:18:20 * @param int id 商品id * @param float price 期望价格 */ public function actionCancelGoodsLoweringPrice() { $id = get_params('id', 0); // $price = get_params('price', 0); $user_id = get_user_id(); $store_id = get_store_id(); $model = GoodsLoweringPrice::findOne(['goods_id' => $id, 'user_id' => $user_id, 'store_id' => $store_id, 'is_delete' => 0]); if(!$model) { return $this->asJson([ 'code' => 0, 'msg' => '提醒记录不存在或已取消' ]); } $model->is_delete = 1; if(!$model->save()) { return $this->asJson([ 'code' => 1, 'msg' => '保存GoodsLoweringPrice表失败' ]); } else { return $this->asJson([ 'code' => 0, 'msg' => '取消降价通知成功', 'is_lowering' => false ]); } } //商品常购清单分类列表 public function actionGoodsPurchaseCatList() { $form = new GoodsForm(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $form->md_id = get_md_id(); return $this->asJson($form->goodsPurchaseCatList()); } //商品常购清单 public function actionGoodsPurchaseList() { $form = new GoodsForm(); $form->store_id = get_store_id(); $form->user_id = get_user_id(); $form->cat_id = get_params('cat_id', 0); $form->md_id = get_md_id(); return $this->asJson($form->goodsPurchaseList()); } }