| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\models\Attr;
- use app\models\AttrGroup;
- use app\models\Coupon;
- use app\modules\client\controllers\BaseController;
- use app\models\Option;
- use app\constants\OptionSetting;
- use yii\db\Query;
- use app\models\GoodsCat;
- use app\models\Goods;
- use app\models\SaasUser;
- //use app\modules\client\models\v1\VideoShopGoodsForm;
- use app\modules\admin\models\VideoShopOrderForm;
- use app\modules\admin\models\VideoShopGoodsForm;
- use app\modules\client\models\v1\ShareQrcodeForm;
- use app\utils\Wechat\WechatMini;
- class VideoShopController extends BaseController
- {
- //获取分享员分销排行
- public function actionSharerOrderNum() {
- $form = new VideoShopOrderForm();
- $form->attributes = all_params();
- $form->store_id = get_store_id();
- $res = $form->getSharerOrderNum();
- return $this->asJson($res);
- }
- //获取分享链接
- public function actionSharerLink() {
- $store_id = get_store_id();
- $product_id = input_params('product_id', 0);
- $sharer_id = input_params('sharer_id', 0);
- $sharer = \app\models\VideoShopSharer::findOne($sharer_id);
- $goodsExt = \app\models\VideoShopGoodsExt::findOne(['product_id' => (string)$product_id, 'store_id' => $store_id]);
- $VideoShopGoodsForm = new VideoShopGoodsForm();
- $base_ = new WechatMini();
- $miniProgram = $base_::getWechatConfig($store_id, $goodsExt['mini_id'], 1);
- $VideoShopGoodsForm->miniProgram = $miniProgram;
- $product_h5url = $VideoShopGoodsForm->product_h5url($product_id, $sharer['openid']);
- if($product_h5url['code'] != 0){
- return $this->asJson($product_h5url);
- }
- $product_taglink = $VideoShopGoodsForm->product_taglink($product_id, $sharer['openid']);
- if($product_taglink['code'] != 0){
- return $this->asJson($product_taglink);
- }
- $product_qrcode = $VideoShopGoodsForm->product_qrcode($product_id, $sharer['openid']);
- if($product_qrcode['code'] != 0){
- return $this->asJson($product_qrcode);
- }
- if($product_qrcode['code'] == 0){
- $form = new ShareQrcodeForm();
- $form->attributes = all_params();
- $form->store_id = $store_id;
- $form->type = 0;
- $form->user = get_user();
- $form->user_id = get_user_id();
- $form->goods_id = $goodsExt['goods_id'];
- $goods_qrcode = $form->goods_qrcode($product_qrcode['data']);
- if($goods_qrcode['code'] == 0){
- $product_qrcode['data1'] = $product_qrcode['data'];
- $product_qrcode['data'] = $goods_qrcode['data'];
- }
- }
- $res = [
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => [
- 'product_h5url' => $product_h5url,
- 'product_taglink' => $product_taglink,
- 'product_qrcode' => $product_qrcode,
- ],
- ];
- return $this->asJson($res);
- }
- //获取分享员状态
- public function actionSharerStatus() {
- $store_id = get_store_id();
- $user = get_user();
- $data = [
- 'not_is_distributor' => $user->is_distributor ? 0 : 1,
- 'is_distributor_wait_audit' => 0,
- 'is_distributor_audit_reject' => 0,
- 'not_is_video_sharer' => 0,
- 'finderUserName' => '',
- 'allow_add' => 0,
- ];
- if($user->is_distributor == 1){
- $product_id = input_params('product_id', 0);
- $goodsExt = \app\models\VideoShopGoodsExt::findOne(['product_id' => (string)$product_id, 'store_id' => $store_id]);
- $mini_id = $goodsExt['mini_id'];
- $finderUserName = Option::get('finderUserName', $store_id, 'video_shop_config_' . $mini_id, '')['value'];
- if($finderUserName){
- $data['finderUserName'] = $finderUserName;
- }
- $sharer = \app\models\VideoShopSharer::findAll(['action_id' => $mini_id, 'user_id' => $user->id, 'is_delete' => 0]);
- if(!$sharer){
- $data['not_is_video_sharer'] = 1;
- $data['allow_add'] = 1;
- }else{
- $data['sharer_list'] = $sharer;
- }
- }else{
- $share = \app\models\Share::findOne(['user_id' => $user->id, 'is_delete' => 0]);
- $data['$share'] = $share;
- if($share){
- $data['not_is_distributor'] = 0;
- if($share['status'] == 0){
- $data['is_distributor_wait_audit'] = 1;
- }
- if($share['status'] == 2){
- $data['is_distributor_audit_reject'] = 1;
- }
- }
- }
- $res = [
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $data,
- ];
- return $this->asJson($res);
- }
- //绑定分享员
- public function actionBindSharer() {
- $store_id = get_store_id();
- $user_id = get_user_id();
- $mini_id = input_params('vs_mini_id', 0);
- $wx_username = input_params('wx_username', '');
- $sharer_id = input_params('sharer_id', 0);
- if($sharer_id){
- $sharer = \app\models\VideoShopSharer::findOne(['id' => $sharer_id, 'store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0]);
- if($sharer){
- $mini_id = $sharer['action_id'];
- }
- }
- if(!$mini_id){
- $product_id = input_params('product_id', 0);
- if(!$product_id){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '缺少参数',
- ]);
- }
- $goodsExt = \app\models\VideoShopGoodsExt::findOne(['product_id' => (string)$product_id, 'store_id' => $store_id]);
- $mini_id = $goodsExt['mini_id'];
- }
- $base_ = new WechatMini();
- $miniProgram = $base_::getWechatConfig($store_id, $mini_id, 1);
- if (empty($miniProgram)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '应用被取消授权或未绑定产品',
- ]);
- }
- $user = get_user();
- $form = new \app\modules\client\models\v1\VideoShopForm();
- $form->params = [
- 'user_id' => $user_id,
- 'sharer_id' => $sharer_id,
- 'wx_username' => $wx_username,
- ];
- $form->miniProgram = $miniProgram;
- $form->mini_id = $base_::$mini_id;
- $form->store_id = $store_id;
- $form->user = $user;
- $res = $form->bindSharer();
- return $this->asJson($res);
- }
- //分享员
- public function actionUserSharerList() {
- $store_id = get_store_id();
- $user = get_user();
- $form = new \app\modules\client\models\v1\VideoShopForm();
- $form->store_id = $store_id;
- $form->user = $user;
- $res = $form->userSharerList();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $res,
- ]);
- }
- }
|