| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use GuzzleHttp\Client;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use app\modules\admin\models\wechat_mp\CardForm;
- use app\utils\IotCloudHelper;
- use yii\redis\Cache;
- /**
- * This is the model class for table "{{%account_log}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $order_type
- * @property integer $order_id
- * @property integer $user_id
- * @property integer $amount
- * @property string $desc
- * @property integer $before
- * @property integer $after
- * @property string $operator
- * @property integer $operator_id
- * @property integer $log_type
- * @property integer $type
- * @property integer $operator_type
- * @property string $pic_url
- * @property string $explain
- * @property integer $created_at
- * @property integer $from
- * @property integer $from_user_id
- * @property integer $profit
- * @property integer $saas_id
- */
- class Promoter extends \yii\db\ActiveRecord
- {
- /**
- * 收入类型
- */
- CONST LOG_TYPE_INCOME = 1;
- /**
- * 支出类型
- */
- CONST LOG_TYPE_EXPEND = 2;
- public static $type_budget = [
- self::LOG_TYPE_INCOME,
- self::LOG_TYPE_EXPEND
- ];
- /**
- * 充值订单
- */
- CONST TYPE_RECHARGE_ORDER = 0;
- /**
- * 商城订单
- */
- CONST TYPE_PLATFORM_ORDER = 1;
- /**
- * 秒杀订单
- */
- CONST TYPE_MS_ORDER = 2;
- /**
- * 拼团订单
- */
- CONST TYPE_PT_ORDER = 3;
- /**
- * 商城订单退款
- */
- CONST TYPE_PLATFORM_REFUND_ORDER = 4;
- /**
- * 充值订单退款(减余额)
- */
- CONST TYPE_RECHARGE_REFUND_ORDER = 41;
- /**
- * 商城秒杀退款
- */
- CONST TYPE_MS_REFUND_ORDER = 5;
- /**
- * 商城拼团退款
- */
- CONST TYPE_PT_REFUND_ORDER = 6;
- /**
- * 商城预约退款
- */
- CONST TYPE_YY_REFUND_ORDER = 7;
- /**
- * 预约订单
- */
- CONST TYPE_YY_ORDER = 8;
- /**
- * 预约订单
- */
- CONST TYPE_SCRATCH_ORDER = 9;
- /**
- * 大转盘
- */
- CONST TYPE_POND_ORDER = 10;
- /**
- * 供货商订单
- */
- CONST TYPE_SUPPLIER_ORDER = 11;
- /**
- * 会员购买订单
- */
- CONST TYPE_LEVEL_ORDER = 12;
- /**
- * 当面付
- */
- CONST TYPE_SCAN_CODE_PAY = 13;
- /**
- * saas积分商品订单
- */
- CONST TYPE_SAAS_INTEGRAL_ORDER = 14;
- /**
- * saas积分商品订单
- */
- CONST TYPE_BALANCE_TO_COMMISSION = 15;
- /**
- * 签到送积分
- */
- CONST TYPE_REGISTER_INTEGRAL = 16;
- /**
- * 问答专区提问
- */
- CONST TYPE_QUESTION_INTEGRAL = 17;
- /**
- * 问答专区看视频广告
- */
- const TYPE_QUESTION_AD = 18;
- /**
- * 充值上级佣金
- */
- const TYPE_RECHARGE_COMMISSION = 20;
- /**
- * 充值分销佣金
- */
- const TYPE_DISTRIBUTION_COMMISSION = 21;
- /**
- * p大转盘抽奖
- */
- const TYPE_POND_COMMISSION = 23;
- /**
- * 采购金
- */
- const TYPE_CLOUD_INVENTORY_PURCHASE_MONEY = 25;
- const TYPE_PURCHASE_CLOUD_INVENTORY_PURCHASE_MONEY = 26;
- /**
- * 贡献积分
- */
- const TYPE_COIN = 3;
- /**
- * 余额
- */
- const TYPE_BALANCE = 2;
- /**
- * 积分
- */
- const TYPE_INTEGRAL = 1;
- /**
- * 商品余额抵扣
- */
- const TYPE_GOODS_BALANCE = 19;
- /**
- * 微信
- */
- CONST TYPE_WECHAT = 3;
- /**
- * 支付宝
- */
- CONST TYPE_ALIPAY = 4;
- /**
- * 采购金
- */
- CONST TYPE_PURCHASE_MONEY = 5;
- public static $valid_type = [
- self::TYPE_BALANCE,
- self::TYPE_INTEGRAL,
- self::TYPE_WECHAT,
- self::TYPE_ALIPAY,
- self::TYPE_PURCHASE_MONEY
- ];
- /**
- * 后台改动
- */
- CONST TYPE_OPERATOR_BACK = 2;
- /**
- * 前台变化
- */
- CONST TYPE_OPERATOR_NORMAL= 1;
- /**
- * AI变化
- */
- CONST TYPE_OPERATOR_AI= 3;
- /**
- * @var int[]
- */
- CONST FROM_TYPE_ORIGINAL = 0; //原始
- CONST FROM_TYPE_GIFT = 1; //赠送
- CONST FROM_TYPE_GIFTED_GIFT = 1; //被赠送
- CONST FROM_TYPE_COMMISSION_TO_BALANCE = 2; //佣金转余额
- CONST FROM_TYPE_RECHARGE = 3; //充值
- CONST URL_GET_PROMOTE_PRODUCT_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_promote_product_list?access_token=";
- CONST URL_GET_PROMOTE_PRODUCT_DETAIL = "https://api.weixin.qq.com/channels/ec/promoter/get_promote_product_detail?access_token=";
- CONST URL_CATEGORY_LEAGUE_ALL = "https://api.weixin.qq.com/channels/ec/category/league/all?access_token="; //获取所有类目信息
- CONST URL_GET_BIND_SHOP_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_bind_shop_list?access_token="; //获取合作的小店列表
- CONST URL_GET_BIND_SHOP_PROMOTER_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_bind_shop_promoter_list?access_token="; //获取合作小店的关联账号列表
- CONST URL_GET_BIND_TALENT_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_bind_talent_list?access_token="; //获取合作的带货者列表
- CONST URL_GET_PROMOTER_REGISTER_AND_BIND_STATUS = "https://api.weixin.qq.com/channels/ec/promoter/get_promoter_register_and_bind_status?access_token="; //获取推客的注册状态,以及和机构的绑定状态
- CONST URL_GET_BIND_SHARER_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_bind_sharer_list?access_token="; //获取推客的注册状态,以及和机构的绑定状态
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%promoter}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['user_id', 'type', 'amount', 'desc', 'order_type', 'before', 'after',
- 'operator_type', 'log_type', 'type'], 'required'],
- [['user_id', 'type', 'created_at', 'order_type', 'order_id', 'operator_type', 'log_type', 'operator_id', 'from', 'from_user_id', 'saas_id'
- ], 'integer'],
- [['amount', 'before', 'after', 'profit'], 'number'],
- [['desc', 'pic_url', 'explain', 'operator'], 'string'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'user_id' => 'User ID',
- 'log_type' => '类型:1=收入,2=支出',
- 'type' => '类型:2=余额,1=积分',
- 'amount' => '变动数',
- 'desc' => '变动说明',
- 'before' => '变动前',
- 'after' => '变动后',
- 'operator' => '操作者',
- 'operator_id' => '操作者id',
- 'operator_type' => '1:前台,2:后台',
- 'pic_url' => '图片',
- 'explain' => '说明',
- 'created_at' => '添加时间',
- 'order_type' => '订单类型 0--充值 1--商城订单 2--秒杀订单 3--拼团订单 4--商城订单退款 5--秒杀订单退款 6--拼团订单退款 7--后台改动,15、团购券, 23、大转盘抽奖',
- 'order_id' => '订单ID',
- 'from' => '是否为转增',
- 'saas_id' => '联盟用户'
- ];
- }
- // 余额支付语音播报
- public static function getAccessToken($store_id)
- {
- $key = 'new_accessToken_promoter_'.$store_id;
- /*$token = \Yii::$app->cache->get($key);
- if (!$token){*/
- $setting = Option::getDecode(Option::PROMOTER_SETTING_NAME,$store_id,Option::PROMOTER_GROUP_NAME);
- if (!isset($setting['appId']) && !isset($setting['appSecret'])) throw new \Exception('未配置机构APPID或机构密钥');
- $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$setting['appId'].'&secret='.$setting['appSecret'];
- $client = new Client();
- $response = $client->get($url);
- //debug_log([__METHOD__, __LINE__, "============".$response->getBody()], "app_debug.log");
- $result = json_decode($response->getBody(), true);
- // 处理成功响应
- if (!isset($result['access_token']) || empty($result['access_token'])) {
- throw new \Exception($result['errmsg'] ?? 'Unknown error');
- }
- $token = $result['access_token'];
- \Yii::$app->cache->set($key,$token,7200);
- //}
- return $token;
- }
- public static function getUrl($url){
- $client = new Client();
- $response = $client->get($url);
- $result = json_decode($response->getBody(), true);
- if (!isset($result['errcode']) || $result['errcode'] !== 0) {
- throw new \Exception($result['errmsg'] ?? 'Unknown error');
- }
- return $result;
- }
- public static function postUrl($url,$data=[]){
- $client = new Client();
- $response = $client->post($url, [
- 'json' =>$data
- ]);
- $result = json_decode($response->getBody(), true);
- if (!isset($result['errcode']) || $result['errcode'] !== 0) {
- throw new \Exception($result['errmsg'] ?? 'Unknown error');
- }
- return $result;
- }
- }
|