123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- namespace App\Http\Controllers\Channel\User;
- use Illuminate\Http\Request;
- use App\Modules\User\Services\UserService;
- use App\Http\Controllers\Channel\BaseController;
- use App\Modules\Subscribe\Services\BookOrderService;
- use App\Modules\Subscribe\Services\ChapterOrderService;
- use App\Modules\Subscribe\Services\OrderService;
- use App\Modules\OfficialAccount\Services\ForceSubscribeService;
- use GuzzleHttp\Client;
- use App\Modules\OfficialAccount\Services\OfficialAccountService;
- use App\Modules\Book\Services\BookConfigService;
- use Log;
- class UserController extends BaseController
- {
- protected $secret_key = 'zhuishuyun#_2017';
-
-
- public function index(Request $request){
- $uid = $request->input('uid');
- if(empty($uid)){
- return response()->error('PARAM_EMPTY');
- }
- $channel_id = $this->getChannelId();
- if(empty($channel_id)){
- return response()->error('PARAM_EMPTY');
- }
- $data = UserService::getById($uid);
- if(!$data){
- return response()->error('USER_NOT_FOUND');
- }
- if($data->distribution_channel_id != $channel_id){
- return response()->error('USER_NOT_FOUND');
- }
-
- $forceSubscribe = ForceSubscribeService::forceSubscribeUsersByUidIncludeCancel(['uid'=>$uid]);
- if($forceSubscribe){
- $data->is_subscribed = $forceSubscribe->is_subscribed;
- $data->subscribed_time = date('Y-m-d H:i:s',strtotime($forceSubscribe->created_at));
- $official_info = OfficialAccountService::officialAccountByAppid(['appid'=>$forceSubscribe->appid]);
- if($official_info){
- $data->subscribe_official = $official_info->nickname;
- }else{
- $data->subscribe_official = '';
- }
- $data->subscribed_src = $official_info->qrcode_url;
-
- $data->label = '';
- if($forceSubscribe->bid){
- $book_info = BookConfigService::getBookById($forceSubscribe->bid);
- if($book_info) $data->label = $book_info->category_name;
- }
- if($forceSubscribe->is_subscribed == 1){
- $data->is_subscribed_text = '已关注';
- }else{
- $data->is_subscribed_text = '取关';
- }
- }else{
- $data->label = '';
- $data->is_subscribed = -1;
- $data->is_subscribed_text = '未关注';
- $data->subscribed_time = '';
- $data->subscribe_official = '';
- $data->subscribed_src = '';
- }
- $charge_lists = OrderService::totalChargeList($uid);
- $total_charge = 0;
- $total_money = 0;
- if($charge_lists){
- foreach ($charge_lists as $v){
- $total_charge += 100*$v->price+$v->given;
- $total_money += $v->price;
- }
- }
- $data->total_charge = number_format($total_charge);
- $data->balance = number_format($data->balance);
- $chapter_consume = ChapterOrderService::getChapterTotalConsume($uid);
- $book_consume = BookOrderService::getBookTotalConsume($uid);
- $data->total_consume = number_format($chapter_consume+$book_consume);
- $data->total_get = 0;
- $data->total_money = $total_money;
- return response()->success($data);
- }
- protected function getRcodeInfo($param,$bid,$uid){
- $param_need = [
- 'gzh_app_id'=>$param['appid'],
- 'scene_id' =>$uid,
- 'timestamp'=>time(),
- ];
- $param_need['sign'] = $this->getSign($param_need);
- $client = new Client(['timeout' => 3.0,]);
- try{
- $qrcode_url_res = $client->request('get','http://zsyauth.aizhuishu.com/api/get_qrcode_url?'.http_build_query($param_need))->getBody()->getContents();
- if($qrcode_url_res){
- $qrcode_url = json_decode($qrcode_url_res,true);
- if($qrcode_url['code'] == 1){
-
- Redis::hset('force_subscribe_from_bid',$param['appid'].'_'.$this->uid,$bid);
- return $qrcode_url['data'];
- }
- }
- }catch (\Exception $e){
- }
- return false;
- }
-
- protected function getSign($params)
- {
- $url = $this->arr_to_url($params, false);
- $url = $url . '&key=' . $this->secret_key;
- $sign = md5($url);
- return $sign;
- }
-
- protected function arr_to_url($array, $has_sign = false)
- {
- ksort($array);
- reset($array);
- $arg = "";
- while (list ($name, $val) = each($array)) {
- if ($name == 'sign' && !$has_sign) continue;
- if (strpos($name, "_") === 0)
- continue;
- if (is_array($val))
- $val = join(',', $val);
- if ($val === "")
- continue;
- $arg .= $name . "=" . $val . "&";
- }
- $arg = substr($arg, 0, count($arg) - 2);
- return $arg;
- }
- }
|