PromoterGoods.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "{{%promoter_skus}}".
  16. *
  17. * @property integer $id
  18. * @property integer $store_id
  19. * @property integer $shop_appid
  20. * @property integer $product_id
  21. * @property string $product_promotion_link
  22. * @property string $title
  23. * @property string $sub_title
  24. * @property string $price
  25. * @property string $image
  26. * @property string $head_imgs
  27. * @property string $desc_info
  28. * @property string $cats_v2
  29. * @property integer $status
  30. * @property integer $item_status
  31. * @property integer $group_id
  32. * @property integer $stock_num
  33. * @property integer $sort
  34. * @property integer $service_ratio
  35. * @property integer $is_show
  36. * @property integer $plan_type
  37. * @property string $created_at
  38. * @property string $updated_at
  39. * @property string $commission_info
  40. * @property string $publish_coupons
  41. * @property string $cooperative_coupons
  42. */
  43. class PromoterGoods extends \yii\db\ActiveRecord
  44. {
  45. /**
  46. * @inheritdoc
  47. */
  48. public static function tableName()
  49. {
  50. return '{{%promoter_goods}}';
  51. }
  52. public function beforeSave($insert)
  53. {
  54. if (parent::beforeSave($insert)) {
  55. if ($this->isNewRecord) {
  56. $this->created_at = date('Y-m-d H:i:s');
  57. }else{
  58. $this->updated_at = date('Y-m-d H:i:s');
  59. }
  60. return true;
  61. }
  62. return false;
  63. }
  64. /**
  65. * @inheritdoc
  66. */
  67. public function rules()
  68. {
  69. return [
  70. [[], 'required'],
  71. [['id', 'status','product_id','plan_type','group_id','stock_num','is_show','item_status','service_ratio','sort','store_id'], 'integer'],
  72. [['price'], 'number'],
  73. [['image','cooperative_coupons','shop_appid','publish_coupons','commission_info', 'product_promotion_link','sub_title', 'title', 'head_imgs','desc_info','cats_v2','created_at','updated_at'], 'string'],
  74. ];
  75. }
  76. /**
  77. * @inheritdoc
  78. */
  79. public function attributeLabels()
  80. {
  81. return [
  82. 'id' => 'ID',
  83. 'user_id' => 'User ID',
  84. 'log_type' => '类型:1=收入,2=支出',
  85. 'type' => '类型:2=余额,1=积分',
  86. 'amount' => '变动数',
  87. 'desc' => '变动说明',
  88. 'before' => '变动前',
  89. 'after' => '变动后',
  90. 'operator' => '操作者',
  91. 'operator_id' => '操作者id',
  92. 'operator_type' => '1:前台,2:后台',
  93. 'pic_url' => '图片',
  94. 'explain' => '说明',
  95. 'created_at' => '添加时间',
  96. 'order_type' => '订单类型 0--充值 1--商城订单 2--秒杀订单 3--拼团订单 4--商城订单退款 5--秒杀订单退款 6--拼团订单退款 7--后台改动,15、团购券, 23、大转盘抽奖',
  97. 'order_id' => '订单ID',
  98. 'from' => '是否为转增',
  99. 'saas_id' => '联盟用户'
  100. ];
  101. }
  102. // 余额支付语音播报
  103. public static function getAccessToken($store_id)
  104. {
  105. $key = 'accessToken_promoter_'.$store_id;
  106. $token = \Yii::$app->cache->get($key);
  107. if (!$token){
  108. $setting = Option::getDecode(Option::PROMOTER_SETTING_NAME,$store_id,Option::PROMOTER_GROUP_NAME);
  109. if (!isset($setting['appId']) && !isset($setting['appSecret'])) throw new \Exception('未配置机构APPID或机构密钥');
  110. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$setting['appId'].'&secret='.$setting['appSecret'];
  111. $client = new Client();
  112. $response = $client->get($url);
  113. //debug_log([__METHOD__, __LINE__, "============".$response->getBody()], "app_debug.log");
  114. $result = json_decode($response->getBody(), true);
  115. // 处理成功响应
  116. if (!isset($result['access_token']) || empty($result['access_token'])) {
  117. throw new \Exception($result['errmsg'] ?? 'Unknown error');
  118. }
  119. $token = $result['access_token'];
  120. \Yii::$app->cache->set($key,$token,7200);
  121. }
  122. return $token;
  123. }
  124. }