| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- /*
- * @Author: your name
- * @Date: 2021-03-02 09:50:20
- * @LastEditTime: 2021-04-28 10:52:45
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: \admin_php\modules\client\controllers\v1\GoodsController.php
- */
- namespace app\modules\client\controllers\v1;
- use app\models\Goods;
- use app\models\GoodsLoweringPrice;
- use app\models\Md;
- use app\models\OrderDetail;
- use app\models\UserViews;
- use app\modules\client\controllers\BaseController;
- use app\modules\client\models\v1\common\CommonGoods;
- use app\modules\client\models\v1\GoodsForm;
- use app\modules\client\models\v1\GoodsListForm;
- use app\modules\client\models\v1\MdListForm;
- use yii\base\BaseObject;
- use app\modules\admin\models\mochat\MochatForm;
- /**
- * 测试
- */
- class GoodsController extends BaseController
- {
- /**
- * 商品推荐
- */
- public function actionGoodsRecommend()
- {
- $form = new GoodsListForm();
- $form->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());
- }
- }
|