Promoter.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use GuzzleHttp\Client;
  9. use Yii;
  10. use yii\behaviors\TimestampBehavior;
  11. use app\modules\admin\models\wechat_mp\CardForm;
  12. use app\utils\IotCloudHelper;
  13. use yii\redis\Cache;
  14. /**
  15. * This is the model class for table "{{%account_log}}".
  16. *
  17. * @property integer $id
  18. * @property integer $store_id
  19. * @property integer $order_type
  20. * @property integer $order_id
  21. * @property integer $user_id
  22. * @property integer $amount
  23. * @property string $desc
  24. * @property integer $before
  25. * @property integer $after
  26. * @property string $operator
  27. * @property integer $operator_id
  28. * @property integer $log_type
  29. * @property integer $type
  30. * @property integer $operator_type
  31. * @property string $pic_url
  32. * @property string $explain
  33. * @property integer $created_at
  34. * @property integer $from
  35. * @property integer $from_user_id
  36. * @property integer $profit
  37. * @property integer $saas_id
  38. */
  39. class Promoter extends \yii\db\ActiveRecord
  40. {
  41. /**
  42. * 收入类型
  43. */
  44. CONST LOG_TYPE_INCOME = 1;
  45. /**
  46. * 支出类型
  47. */
  48. CONST LOG_TYPE_EXPEND = 2;
  49. public static $type_budget = [
  50. self::LOG_TYPE_INCOME,
  51. self::LOG_TYPE_EXPEND
  52. ];
  53. /**
  54. * 充值订单
  55. */
  56. CONST TYPE_RECHARGE_ORDER = 0;
  57. /**
  58. * 商城订单
  59. */
  60. CONST TYPE_PLATFORM_ORDER = 1;
  61. /**
  62. * 秒杀订单
  63. */
  64. CONST TYPE_MS_ORDER = 2;
  65. /**
  66. * 拼团订单
  67. */
  68. CONST TYPE_PT_ORDER = 3;
  69. /**
  70. * 商城订单退款
  71. */
  72. CONST TYPE_PLATFORM_REFUND_ORDER = 4;
  73. /**
  74. * 充值订单退款(减余额)
  75. */
  76. CONST TYPE_RECHARGE_REFUND_ORDER = 41;
  77. /**
  78. * 商城秒杀退款
  79. */
  80. CONST TYPE_MS_REFUND_ORDER = 5;
  81. /**
  82. * 商城拼团退款
  83. */
  84. CONST TYPE_PT_REFUND_ORDER = 6;
  85. /**
  86. * 商城预约退款
  87. */
  88. CONST TYPE_YY_REFUND_ORDER = 7;
  89. /**
  90. * 预约订单
  91. */
  92. CONST TYPE_YY_ORDER = 8;
  93. /**
  94. * 预约订单
  95. */
  96. CONST TYPE_SCRATCH_ORDER = 9;
  97. /**
  98. * 大转盘
  99. */
  100. CONST TYPE_POND_ORDER = 10;
  101. /**
  102. * 供货商订单
  103. */
  104. CONST TYPE_SUPPLIER_ORDER = 11;
  105. /**
  106. * 会员购买订单
  107. */
  108. CONST TYPE_LEVEL_ORDER = 12;
  109. /**
  110. * 当面付
  111. */
  112. CONST TYPE_SCAN_CODE_PAY = 13;
  113. /**
  114. * saas积分商品订单
  115. */
  116. CONST TYPE_SAAS_INTEGRAL_ORDER = 14;
  117. /**
  118. * saas积分商品订单
  119. */
  120. CONST TYPE_BALANCE_TO_COMMISSION = 15;
  121. /**
  122. * 签到送积分
  123. */
  124. CONST TYPE_REGISTER_INTEGRAL = 16;
  125. /**
  126. * 问答专区提问
  127. */
  128. CONST TYPE_QUESTION_INTEGRAL = 17;
  129. /**
  130. * 问答专区看视频广告
  131. */
  132. const TYPE_QUESTION_AD = 18;
  133. /**
  134. * 充值上级佣金
  135. */
  136. const TYPE_RECHARGE_COMMISSION = 20;
  137. /**
  138. * 充值分销佣金
  139. */
  140. const TYPE_DISTRIBUTION_COMMISSION = 21;
  141. /**
  142. * p大转盘抽奖
  143. */
  144. const TYPE_POND_COMMISSION = 23;
  145. /**
  146. * 采购金
  147. */
  148. const TYPE_CLOUD_INVENTORY_PURCHASE_MONEY = 25;
  149. const TYPE_PURCHASE_CLOUD_INVENTORY_PURCHASE_MONEY = 26;
  150. /**
  151. * 贡献积分
  152. */
  153. const TYPE_COIN = 3;
  154. /**
  155. * 余额
  156. */
  157. const TYPE_BALANCE = 2;
  158. /**
  159. * 积分
  160. */
  161. const TYPE_INTEGRAL = 1;
  162. /**
  163. * 商品余额抵扣
  164. */
  165. const TYPE_GOODS_BALANCE = 19;
  166. /**
  167. * 微信
  168. */
  169. CONST TYPE_WECHAT = 3;
  170. /**
  171. * 支付宝
  172. */
  173. CONST TYPE_ALIPAY = 4;
  174. /**
  175. * 采购金
  176. */
  177. CONST TYPE_PURCHASE_MONEY = 5;
  178. public static $valid_type = [
  179. self::TYPE_BALANCE,
  180. self::TYPE_INTEGRAL,
  181. self::TYPE_WECHAT,
  182. self::TYPE_ALIPAY,
  183. self::TYPE_PURCHASE_MONEY
  184. ];
  185. /**
  186. * 后台改动
  187. */
  188. CONST TYPE_OPERATOR_BACK = 2;
  189. /**
  190. * 前台变化
  191. */
  192. CONST TYPE_OPERATOR_NORMAL= 1;
  193. /**
  194. * AI变化
  195. */
  196. CONST TYPE_OPERATOR_AI= 3;
  197. /**
  198. * @var int[]
  199. */
  200. CONST FROM_TYPE_ORIGINAL = 0; //原始
  201. CONST FROM_TYPE_GIFT = 1; //赠送
  202. CONST FROM_TYPE_GIFTED_GIFT = 1; //被赠送
  203. CONST FROM_TYPE_COMMISSION_TO_BALANCE = 2; //佣金转余额
  204. CONST FROM_TYPE_RECHARGE = 3; //充值
  205. CONST URL_GET_PROMOTE_PRODUCT_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_promote_product_list?access_token=";
  206. CONST URL_GET_PROMOTE_PRODUCT_DETAIL = "https://api.weixin.qq.com/channels/ec/promoter/get_promote_product_detail?access_token=";
  207. CONST URL_CATEGORY_LEAGUE_ALL = "https://api.weixin.qq.com/channels/ec/category/league/all?access_token="; //获取所有类目信息
  208. CONST URL_GET_BIND_SHOP_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_bind_shop_list?access_token="; //获取合作的小店列表
  209. CONST URL_GET_BIND_SHOP_PROMOTER_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_bind_shop_promoter_list?access_token="; //获取合作小店的关联账号列表
  210. CONST URL_GET_BIND_TALENT_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_bind_talent_list?access_token="; //获取合作的带货者列表
  211. CONST URL_GET_PROMOTER_REGISTER_AND_BIND_STATUS = "https://api.weixin.qq.com/channels/ec/promoter/get_promoter_register_and_bind_status?access_token="; //获取推客的注册状态,以及和机构的绑定状态
  212. CONST URL_GET_BIND_SHARER_LIST = "https://api.weixin.qq.com/channels/ec/promoter/get_bind_sharer_list?access_token="; //获取推客的注册状态,以及和机构的绑定状态
  213. /**
  214. * @inheritdoc
  215. */
  216. public static function tableName()
  217. {
  218. return '{{%promoter}}';
  219. }
  220. /**
  221. * @inheritdoc
  222. */
  223. public function rules()
  224. {
  225. return [
  226. [['user_id', 'type', 'amount', 'desc', 'order_type', 'before', 'after',
  227. 'operator_type', 'log_type', 'type'], 'required'],
  228. [['user_id', 'type', 'created_at', 'order_type', 'order_id', 'operator_type', 'log_type', 'operator_id', 'from', 'from_user_id', 'saas_id'
  229. ], 'integer'],
  230. [['amount', 'before', 'after', 'profit'], 'number'],
  231. [['desc', 'pic_url', 'explain', 'operator'], 'string'],
  232. ];
  233. }
  234. /**
  235. * @inheritdoc
  236. */
  237. public function attributeLabels()
  238. {
  239. return [
  240. 'id' => 'ID',
  241. 'user_id' => 'User ID',
  242. 'log_type' => '类型:1=收入,2=支出',
  243. 'type' => '类型:2=余额,1=积分',
  244. 'amount' => '变动数',
  245. 'desc' => '变动说明',
  246. 'before' => '变动前',
  247. 'after' => '变动后',
  248. 'operator' => '操作者',
  249. 'operator_id' => '操作者id',
  250. 'operator_type' => '1:前台,2:后台',
  251. 'pic_url' => '图片',
  252. 'explain' => '说明',
  253. 'created_at' => '添加时间',
  254. 'order_type' => '订单类型 0--充值 1--商城订单 2--秒杀订单 3--拼团订单 4--商城订单退款 5--秒杀订单退款 6--拼团订单退款 7--后台改动,15、团购券, 23、大转盘抽奖',
  255. 'order_id' => '订单ID',
  256. 'from' => '是否为转增',
  257. 'saas_id' => '联盟用户'
  258. ];
  259. }
  260. // 余额支付语音播报
  261. public static function getAccessToken($store_id)
  262. {
  263. $key = 'new_accessToken_promoter_'.$store_id;
  264. /*$token = \Yii::$app->cache->get($key);
  265. if (!$token){*/
  266. $setting = Option::getDecode(Option::PROMOTER_SETTING_NAME,$store_id,Option::PROMOTER_GROUP_NAME);
  267. if (!isset($setting['appId']) && !isset($setting['appSecret'])) throw new \Exception('未配置机构APPID或机构密钥');
  268. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$setting['appId'].'&secret='.$setting['appSecret'];
  269. $client = new Client();
  270. $response = $client->get($url);
  271. //debug_log([__METHOD__, __LINE__, "============".$response->getBody()], "app_debug.log");
  272. $result = json_decode($response->getBody(), true);
  273. // 处理成功响应
  274. if (!isset($result['access_token']) || empty($result['access_token'])) {
  275. throw new \Exception($result['errmsg'] ?? 'Unknown error');
  276. }
  277. $token = $result['access_token'];
  278. \Yii::$app->cache->set($key,$token,7200);
  279. //}
  280. return $token;
  281. }
  282. public static function getUrl($url){
  283. $client = new Client();
  284. $response = $client->get($url);
  285. $result = json_decode($response->getBody(), true);
  286. if (!isset($result['errcode']) || $result['errcode'] !== 0) {
  287. throw new \Exception($result['errmsg'] ?? 'Unknown error');
  288. }
  289. return $result;
  290. }
  291. public static function postUrl($url,$data=[]){
  292. $client = new Client();
  293. $response = $client->post($url, [
  294. 'json' =>$data
  295. ]);
  296. $result = json_decode($response->getBody(), true);
  297. if (!isset($result['errcode']) || $result['errcode'] !== 0) {
  298. throw new \Exception($result['errmsg'] ?? 'Unknown error');
  299. }
  300. return $result;
  301. }
  302. }