VideoShopController.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\controllers\v1;
  8. use app\models\Attr;
  9. use app\models\AttrGroup;
  10. use app\models\Coupon;
  11. use app\modules\client\controllers\BaseController;
  12. use app\models\Option;
  13. use app\constants\OptionSetting;
  14. use yii\db\Query;
  15. use app\models\GoodsCat;
  16. use app\models\Goods;
  17. use app\models\SaasUser;
  18. //use app\modules\client\models\v1\VideoShopGoodsForm;
  19. use app\modules\admin\models\VideoShopOrderForm;
  20. use app\modules\admin\models\VideoShopGoodsForm;
  21. use app\modules\client\models\v1\ShareQrcodeForm;
  22. use app\utils\Wechat\WechatMini;
  23. class VideoShopController extends BaseController
  24. {
  25. //获取分享员分销排行
  26. public function actionSharerOrderNum() {
  27. $form = new VideoShopOrderForm();
  28. $form->attributes = all_params();
  29. $form->store_id = get_store_id();
  30. $res = $form->getSharerOrderNum();
  31. return $this->asJson($res);
  32. }
  33. //获取分享链接
  34. public function actionSharerLink() {
  35. $store_id = get_store_id();
  36. $product_id = input_params('product_id', 0);
  37. $sharer_id = input_params('sharer_id', 0);
  38. $sharer = \app\models\VideoShopSharer::findOne($sharer_id);
  39. $goodsExt = \app\models\VideoShopGoodsExt::findOne(['product_id' => (string)$product_id, 'store_id' => $store_id]);
  40. $VideoShopGoodsForm = new VideoShopGoodsForm();
  41. $base_ = new WechatMini();
  42. $miniProgram = $base_::getWechatConfig($store_id, $goodsExt['mini_id'], 1);
  43. $VideoShopGoodsForm->miniProgram = $miniProgram;
  44. $product_h5url = $VideoShopGoodsForm->product_h5url($product_id, $sharer['openid']);
  45. if($product_h5url['code'] != 0){
  46. return $this->asJson($product_h5url);
  47. }
  48. $product_taglink = $VideoShopGoodsForm->product_taglink($product_id, $sharer['openid']);
  49. if($product_taglink['code'] != 0){
  50. return $this->asJson($product_taglink);
  51. }
  52. $product_qrcode = $VideoShopGoodsForm->product_qrcode($product_id, $sharer['openid']);
  53. if($product_qrcode['code'] != 0){
  54. return $this->asJson($product_qrcode);
  55. }
  56. if($product_qrcode['code'] == 0){
  57. $form = new ShareQrcodeForm();
  58. $form->attributes = all_params();
  59. $form->store_id = $store_id;
  60. $form->type = 0;
  61. $form->user = get_user();
  62. $form->user_id = get_user_id();
  63. $form->goods_id = $goodsExt['goods_id'];
  64. $goods_qrcode = $form->goods_qrcode($product_qrcode['data']);
  65. if($goods_qrcode['code'] == 0){
  66. $product_qrcode['data1'] = $product_qrcode['data'];
  67. $product_qrcode['data'] = $goods_qrcode['data'];
  68. }
  69. }
  70. $res = [
  71. 'code' => 0,
  72. 'msg' => 'ok',
  73. 'data' => [
  74. 'product_h5url' => $product_h5url,
  75. 'product_taglink' => $product_taglink,
  76. 'product_qrcode' => $product_qrcode,
  77. ],
  78. ];
  79. return $this->asJson($res);
  80. }
  81. //获取分享员状态
  82. public function actionSharerStatus() {
  83. $store_id = get_store_id();
  84. $user = get_user();
  85. $data = [
  86. 'not_is_distributor' => $user->is_distributor ? 0 : 1,
  87. 'is_distributor_wait_audit' => 0,
  88. 'is_distributor_audit_reject' => 0,
  89. 'not_is_video_sharer' => 0,
  90. 'finderUserName' => '',
  91. 'allow_add' => 0,
  92. ];
  93. if($user->is_distributor == 1){
  94. $product_id = input_params('product_id', 0);
  95. $goodsExt = \app\models\VideoShopGoodsExt::findOne(['product_id' => (string)$product_id, 'store_id' => $store_id]);
  96. $mini_id = $goodsExt['mini_id'];
  97. $finderUserName = Option::get('finderUserName', $store_id, 'video_shop_config_' . $mini_id, '')['value'];
  98. if($finderUserName){
  99. $data['finderUserName'] = $finderUserName;
  100. }
  101. $sharer = \app\models\VideoShopSharer::findAll(['action_id' => $mini_id, 'user_id' => $user->id, 'is_delete' => 0]);
  102. if(!$sharer){
  103. $data['not_is_video_sharer'] = 1;
  104. $data['allow_add'] = 1;
  105. }else{
  106. $data['sharer_list'] = $sharer;
  107. }
  108. }else{
  109. $share = \app\models\Share::findOne(['user_id' => $user->id, 'is_delete' => 0]);
  110. $data['$share'] = $share;
  111. if($share){
  112. $data['not_is_distributor'] = 0;
  113. if($share['status'] == 0){
  114. $data['is_distributor_wait_audit'] = 1;
  115. }
  116. if($share['status'] == 2){
  117. $data['is_distributor_audit_reject'] = 1;
  118. }
  119. }
  120. }
  121. $res = [
  122. 'code' => 0,
  123. 'msg' => 'ok',
  124. 'data' => $data,
  125. ];
  126. return $this->asJson($res);
  127. }
  128. //绑定分享员
  129. public function actionBindSharer() {
  130. $store_id = get_store_id();
  131. $user_id = get_user_id();
  132. $mini_id = input_params('vs_mini_id', 0);
  133. $wx_username = input_params('wx_username', '');
  134. $sharer_id = input_params('sharer_id', 0);
  135. if($sharer_id){
  136. $sharer = \app\models\VideoShopSharer::findOne(['id' => $sharer_id, 'store_id' => $store_id, 'user_id' => $user_id, 'is_delete' => 0]);
  137. if($sharer){
  138. $mini_id = $sharer['action_id'];
  139. }
  140. }
  141. if(!$mini_id){
  142. $product_id = input_params('product_id', 0);
  143. if(!$product_id){
  144. return $this->asJson([
  145. 'code' => 1,
  146. 'msg' => '缺少参数',
  147. ]);
  148. }
  149. $goodsExt = \app\models\VideoShopGoodsExt::findOne(['product_id' => (string)$product_id, 'store_id' => $store_id]);
  150. $mini_id = $goodsExt['mini_id'];
  151. }
  152. $base_ = new WechatMini();
  153. $miniProgram = $base_::getWechatConfig($store_id, $mini_id, 1);
  154. if (empty($miniProgram)) {
  155. return $this->asJson([
  156. 'code' => 1,
  157. 'msg' => '应用被取消授权或未绑定产品',
  158. ]);
  159. }
  160. $user = get_user();
  161. $form = new \app\modules\client\models\v1\VideoShopForm();
  162. $form->params = [
  163. 'user_id' => $user_id,
  164. 'sharer_id' => $sharer_id,
  165. 'wx_username' => $wx_username,
  166. ];
  167. $form->miniProgram = $miniProgram;
  168. $form->mini_id = $base_::$mini_id;
  169. $form->store_id = $store_id;
  170. $form->user = $user;
  171. $res = $form->bindSharer();
  172. return $this->asJson($res);
  173. }
  174. //分享员
  175. public function actionUserSharerList() {
  176. $store_id = get_store_id();
  177. $user = get_user();
  178. $form = new \app\modules\client\models\v1\VideoShopForm();
  179. $form->store_id = $store_id;
  180. $form->user = $user;
  181. $res = $form->userSharerList();
  182. return $this->asJson([
  183. 'code' => 0,
  184. 'msg' => 'ok',
  185. 'data' => $res,
  186. ]);
  187. }
  188. }