AccountWechats.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/4/5
  6. * Time: 上午10:00
  7. */
  8. namespace app\common\models;
  9. use Illuminate\Support\Facades\Cache;
  10. class AccountWechats extends BaseModel
  11. {
  12. public $table = 'account_wechats';
  13. public function __construct(array $attributes = [])
  14. {
  15. parent::__construct($attributes);
  16. if (config('app.framework') == 'platform') {
  17. $this->table = 'yz_uniacid_app';
  18. }
  19. }
  20. public static function getAccountByUniacid($uniacid)
  21. {
  22. if (!config('app.framework') == 'platform' || file_exists(base_path().'/bootstrap/install.lock')) {
  23. //这里使用laravel Cache是因为商城cache调用了Yunshop::app()->uniacid导致死循环
  24. return Cache::remember('account_app_'.$uniacid,3600,function () use ($uniacid) {
  25. return self::where('uniacid', $uniacid)->first();
  26. });
  27. }
  28. }
  29. /**
  30. * 设置公众号
  31. * @param $account
  32. */
  33. public static function setConfig($account)
  34. {
  35. if($account){
  36. \Config::set('wechat.app_id',$account->key);
  37. \Config::set('wechat.secret',$account->secret);
  38. \Config::set('wechat.token',$account->token);
  39. \Config::set('wechat.aes_key',$account->encodingaeskey);
  40. }
  41. return;
  42. }
  43. }