| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace addons\Happiness\api\modules\v1\controllers;
- use addons\Clinic\common\enums\ClinicEnum;
- use addons\Clinic\common\models\Clinic;
- use addons\Clinic\common\models\ClinicCoupon;
- use addons\Clinic\common\models\ClinicCouponCatRelate;
- use addons\Clinic\common\models\ClinicCouponGoodsRelate;
- use addons\Clinic\common\models\ClinicGoods;
- use addons\Clinic\common\services\ClinicGoodsTrackingService;
- use addons\Coupon\common\enums\AddonsCouponEnum;
- use addons\Happiness\common\enums\HappinessEnum;
- use addons\Happiness\common\service\GoodsService;
- use addons\Happiness\common\service\StoreService;
- use common\enums\GoodsTypeEnum;
- use common\enums\OrderCommentEnum;
- use common\enums\StatusEnum;
- use common\events\census\ViewsEvent;
- use common\globals\GlobalInvoke;
- use common\helpers\LocationHelper;
- use common\models\common\Region;
- use common\models\goods\Goods;
- use common\models\goods\GoodsCateRelate;
- use common\models\order\OrderComments;
- use common\models\user\User;
- use common\models\user\UserLevel;
- use common\logic\common\GoodsLogic;
- use common\models\user\UserPartitionRelationship;
- use Yii;
- use Exception;
- use api\controllers\OnAuthController;
- /**
- * 幸福小店商品
- *
- * Class DefaultController
- * @package addons\Store\api\modules\v1\controllers
- */
- class GoodsController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index', 'detail', 'cate-goods-list', 'list', 'recommend', 'comments-list', 'get-platform-goods'];
- //获取门店商品列表
- public function actionCateGoodsList()
- {
- $request = Yii::$app->request;
- if ($request->isGet) {
- try {
- $get = $request->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['cate_id', 'page', 'store_id', 'limit'], 'integer'],
- [['keyword'], 'string'],
- [['type'],'safe']
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $list = (new GoodsService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->cateGoodsList($get);
- $this->success('获取成功', $list);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- //最近的门店商品
- public function actionGetNearStoreGoodsList()
- {
- $request = Yii::$app->request;
- if ($request->isGet) {
- try {
- $get = $request->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['longitude', 'latitude', 'shipping_type', 'attr_id', 'attr_ids', 'goods_ids'], 'string'],
- ]);
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $get['mall_id'] = $this->mall_id;
- $get['user_id'] = $this->user_id;
- if (!empty($get['attr_ids'])) $get['attr_ids'] = explode(',', $get['attr_ids']);
- if (!empty($get['goods_ids'])) $get['goods_ids'] = explode(',', $get['goods_ids']);
- $info = (new StoreService())->getStore($get);
- $search['store_id']= $info['id'];
- $search['page'] = $get['page'];
- $search['limit'] = $get['limit'];
- if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage());
- $list = (new GoodsService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->cateGoodsList
- ($search);
- $list['store']=(new StoreService(['mall_id' => $this->mall_id]))->getStoreDetail(['store_id'=>$info['id']]);
- $this->success('获取成功', $list);
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- }
- /**
- * 首页
- *
- * @return string
- */
- public function actionDetail()
- {
- $params = \Yii::$app->request->get();
- $res = \Yii::$app->services->validate->validate($params, [
- [['goods_id'], 'integer'],
- [['scene'], 'string'],
- ['store_id', 'integer'],
- [['addonsFields','latitude','longitude'], 'safe']
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $goods = GoodsLogic::GetDetail($this->mall_id, $params, $this->user);
- if (empty($goods)) return $this->error(GoodsLogic::getStaticError());
- if ($params['addonsFields']) {
- if($this->platform == User::PLATFORM_MP_WX){
- is_string($params['addonsFields']) && $params['addonsFields'] = json_decode($params['addonsFields'], true);
- }else{
- $params['addonsFields'] = is_string($params['addonsFields']) ? explode(',', $params['addonsFields']) : $params['addonsFields'];
- }
- $goods = Goods::getAddonsGoodsSetting($this->mall_id, $params['addonsFields'], $goods, 'detail');
- }
- $goods['is_bind_popups'] = UserPartitionRelationship::getIsNeedPopups($this->mall_id, $this->user_id ?? 0);
- //浏览
- if ($goods) {
- $event = new ViewsEvent($this->mall_id);
- $data['mall_id'] = $this->mall_id;
- $data['user_id'] = $this->user_id;
- $data['goods_id'] = $params['goods_id'];
- \Yii::$app->services->events->dispatch($event, $data, $event->listeners);
- $smart_form_template = GlobalInvoke::exec(GlobalInvoke::GOODS_NEED_SMARTFORM, $this->mall_id, ['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'goods_id' => $params['goods_id']]);
- if (!empty($smart_form_template)) $goods = array_merge($goods, $smart_form_template);
- // 商品详情公共调用
- $invoke_data = GlobalInvoke::exec(
- GlobalInvoke::API_GOODS_DETAIL,
- $this->mall_id,
- ['mall_id' => $this->mall_id, 'goods' => $goods, 'user' => $this->user,'latitude'=>$params['latitude']??0,'longitude'=>$params['longitude']??0]
- );
- if (!empty($invoke_data['goods'])) $goods = $invoke_data['goods'];
- }
- // 首页文本命名
- $home_text = Yii::$app->services->setting->mall->get($this->mall_id, "goodsdetail.home_text");
- $goods['home_text'] = !empty($home_text) ? $home_text : '首页';
- $res = GoodsLogic::getGoodsAssociationList($this->mall_id,$params['goods_id']);
- $goods['extra1_goods_list'] = $res['extra1_goods_list']??[];
- $goods['extra2_goods_list'] = $res['extra2_goods_list']??[];
- $pension_scale = \Yii::$app->services->setting->addons->get($this->mall_id, HappinessEnum::ADDONS_NAME,
- 'basic.pension_scale')??0;
- $goods['pension_price']=bcmul($goods['price'],bcdiv($pension_scale,100,4),2);
- return $this->success('获取成功', $goods);
- }
- }
|