uid; $app_id = $item->user && $item->user->force_subscribe_user ? $item->user->force_subscribe_user->appid : ''; $opend_id = $item->user && $item->user->force_subscribe_user ? $item->user->force_subscribe_user->openid : ''; if($app_id == ''){ $app_id = empty($item->app_ids) ? '' : $item->app_ids[0]; } if ($opend_id == ''){ $res = $service->getUserOpenidsData($uid,$app_id); if ($res){ $opend_id = $res['openid']; } } return [ 'uid' => $uid, 'price' => (float) $item->price, 'trade_no' => $item->trade_no, 'status' => $item->status, 'created_at' => (string)$item->created_at, 'pay_end_at' => $item->pay_end_at, 'send_order_id' => $item->send_order_id, 'send_order_name' => $item->send_order_name, 'push_msg_id' => $item->inner_send_order_id, 'ip' => $item->create_ip, 'activity_id' => $item->activity_id, 'order_type' => $this->getOrderType($item->order_type), 'activity_name' => ($item->pay_merchant_source == 'MONTH') ? '包月' : ($item->activity ? (string) $item->activity->name : ''), 'keyword' => $this->getKeyword($item), 'user_charge_times' => (isset($item->pay_type) && $item->status == 'PAID') ? $item->pay_type : 0, 'bid' => CommonHelper::book_hash_encode($item->from_bid), 'register_time' => $item->user ? (string)$item->user->created_at : '', 'book_name' => $item->book_config ? $item->book_config->book_name : '', 'promotion_url' => $item->send_order ? CommonHelper::getPromotionUrl($item->send_order) : '', 'app_id' => $app_id, 'opend_id' => $opend_id, 'register_open_id' => $item->user ? $item->user->openid : '', 'subscribe_time' => $item->user && $item->user->force_subscribe_user ? $item->user->force_subscribe_user->subscribe_time : '', 'wechat_name' => $item->user && $item->user->force_subscribe_user && $item->user->force_subscribe_user->official_account ? $item->user->force_subscribe_user->official_account->nickname : '', ]; } protected function getOrderType(string $type) { switch ($type) { case 'RECHARGE': return '普通充值'; case 'MONTH': return '包月'; case 'QUARTER': return '包季'; case 'YEAR': return '包年'; } } protected function getKeyword(Order $order) { if ($order->from_type && starts_with($order->from_type, 'keyword')) { $key_array = explode('_', $order->from_type); if (isset($key_array[1]) && !empty($key_array[1])) { $keyword_info = WechatKeywordMsgs::find($key_array[1]); return sprintf('%s(%s)', $keyword_info->keyword, $keyword_info->book_name); } } return ''; } }