123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Api\Repositories\WxContRepositories;
- use App\Jobs\System\ChatExpandTypeCheckJob;
- use App\Jobs\UserInputSafeCheckJob;
- use App\Models\Circle\WxCircle;
- use App\Models\Pets\WxPetsAdoption;
- use App\Models\Pets\WxPetsAdoptionApply;
- use App\Models\Posts\WxComment;
- use App\Models\Posts\WxPost;
- use App\Models\Shop\WxShopGoods;
- use App\Models\Shop\WxShopOrderGoods;
- use App\Models\Shop\WxShopService;
- use App\Models\Used\WxUsedGood;
- use App\Models\User\WxUserContactApply;
- use App\Models\User\WxUserStudentCertify;
- use App\Models\Voter\WxVoter;
- use App\Models\Voter\WxVoterPlayer;
- use App\Models\WxAuthentication;
- use App\Models\WxChat;
- use App\Models\User\WxUser;
- use App\Wen\Utils\CircleUtils;
- use App\Wen\Utils\CommentUtils;
- use App\Wen\Utils\FieldUtils;
- use App\Wen\Utils\GatewayUtils;
- use App\Wen\Utils\PetUtils;
- use App\Wen\Utils\PostUtils;
- use App\Wen\Utils\Settings;
- use App\Wen\Utils\ShopUtils;
- use App\Wen\Utils\UserUtils;
- use App\Wen\Utils\Utils;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- class ChatController extends BaseController
- {
- public function massages_process(Request $request) {
- $type = _empty_default_($request->type, '');
- if($type == 'review_object'){
- return $this->review_object($request);
- }
- }
- private function review_object(Request &$request){
- $chat_id = _empty_default_($request->chat_id, 0);
- if(_empty_($chat_id)){
- return $this->fail(200001);
- }
- $chat = WxChat::find($chat_id);
- if(!$chat){
- return $this->fail(200003);
- }
- // 101: 笔记审核 102:评论审核 103:组局审核 104:选票审核 105:选手审核 106:闲置审核 107:圈子审核 108:学生认证审核 109:身份认证审核 110 俱乐部审核
- if(!in_array($chat->expand_type, [101, 102, 103, 104, 105, 106, 107, 108, 109, 110])){
- return $this->fail(200004);
- }
- global $__MINI_GLOBAL_IS_ADMIN_SUPER__,$__MINI_GLOBAL_CURRENT_USER_ID__;
- if(!$__MINI_GLOBAL_IS_ADMIN_SUPER__){
- if($chat->expand_type == 105){
- $voter_id = WxVoterPlayer::where('id', $chat->expand_id)->value('voter_id');
- if(_empty_($voter_id)){
- return $this->fail(200000);
- }
- if(WxVoter::where('id', $voter_id)->value('user_id') != $__MINI_GLOBAL_CURRENT_USER_ID__){
- return $this->fail(200000);
- }
- }else{
- return $this->fail(200000);
- }
- }
- $flag = _empty_default_($request->flag, 0);
- if(!in_array($flag, [1, 2])){
- return $this->fail(200004);
- }
- if($chat->expand_type == 101){
- //expand_id
- $the_object = WxPost::where('is_examine', 0)->where('id', $chat->expand_id)->first();
- if($the_object){
- PostUtils::post_pass($the_object, $flag);
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }else if($chat->expand_type == 102){
- $the_object = WxComment::where('comment_state', 0)->where('id', $chat->expand_id)->first();
- if($the_object){
- CommentUtils::comment_pass($the_object, $flag);
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }else if($chat->expand_type == 104){
- $the_object = WxVoter::find($chat->expand_id);
- if($the_object){
- if($flag == 1){
- if($the_object->status == 0){
- $the_object->status = 1;
- $the_object->save();
- UserUtils::add_user_experience($the_object->user_id, 16, 20);
- }
- }else{
- if($the_object->status == 1){
- $the_object->status = 0;
- $the_object->save();
- }
- }
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }else if($chat->expand_type == 105){
- $the_object = WxVoterPlayer::find($chat->expand_id);
- if($the_object){
- if($flag == 1){
- if($the_object->status == 0){
- $the_object->status = 1;
- $the_object->save();
- UserUtils::add_user_experience($the_object->user_id, 19, 20);
- }
- }else{
- if($the_object->status == 1){
- $the_object->status = 0;
- $the_object->save();
- }
- }
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }else if($chat->expand_type == 106){
- $the_object = WxUsedGood::find($chat->expand_id);
- if($the_object){
- if($flag == 1){
- if($the_object->status == 0){
- $the_object->status = 1;
- $the_object->save();
- UserUtils::add_user_experience($the_object->user_id, 106, 30);
- }
- }else{
- if($the_object->status == 1){
- $the_object->status = 99;
- $the_object->save();
- }
- }
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }else if($chat->expand_type == 107){
- $the_object = WxCircle::where('circle_state', 0)->where('id', $chat->expand_id)->first();
- if($the_object){
- if($flag == 1){
- CircleUtils::circle_pass($the_object, 1, '');
- }else{
- CircleUtils::circle_pass($the_object, 2, '');
- }
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }else if($chat->expand_type == 108){
- $the_object = WxUserStudentCertify::find($chat->expand_id);
- if($the_object){
- if($flag == 1){
- if($the_object->status == 0){
- $the_object->status = 1;
- $the_object->save();
- UserUtils::add_user_experience($the_object->user_id, 18, 30);
- }
- }else{
- if($the_object->status == 1){
- $the_object->status = 0;
- $the_object->save();
- }
- }
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }else if($chat->expand_type == 109){
- $the_object = WxAuthentication::where('authentication_state', 0)->where('id', $chat->expand_id)->first();
- if($the_object){
- if($flag == 1){
- UserUtils::authenticate_pass($the_object, 1, '');
- }else{
- UserUtils::authenticate_pass($the_object, 2, '');
- }
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }else if($chat->expand_type == 110){
- $the_object = WxClub::find($chat->expand_id);
- if($the_object){
- if($flag == 1){
- if($the_object->status == 0){
- $the_object->status = 1;
- $the_object->save();
- }
- }else{
- if($the_object->status == 1){
- $the_object->status = 0;
- $the_object->save();
- }
- }
- return $this->success();
- }else{
- WxChat::where('id', $chat->id)->forceDelete();
- return $this->fail(200003);
- }
- }
- }
- private function after_sale_message(Request &$request){
- }
- /**
- * 用户发起聊天
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function addChat(Request $request)
- {
- $uid = $request->uid;
- $oid = $request->oid;
- if($uid == $oid){
- return $this->fail(200040);
- }
- _limit_user('chat', $uid, 30);
- if(!UserUtils::is_user_can_speak($uid)){
- return $this->fail(200043, [
- 'title' => '禁言中,无法言论',
- 'content' => '是否前往解除限制',
- 'confirmText' => '去解除',
- 'target_type' => 6,
- 'target_id' => '/pagesA/mine/unlock/unlock?user_id='.$uid
- ], '您当前处于禁言期间,无法言论');
- }
- $chat_content = $request->input('chat_content', '');
- $chat_image = $request->input('chat_image', '');
- $chat_audio_url = $request->input('chat_audio_url', '');
- $chat_audio_length = $request->input('chat_audio_length', '');
- $refer_id = $request->input('refer_id', 0);
- $shop_good_id = $request->input('shop_good_id', 0);
- $voter_id = _abs(_empty_default_($request->voter_id, 0));
- $ask_order_id = _abs(_empty_default_($request->ask_order_id, 0));
- if(_empty_($uid) || _empty_($oid)){
- return $this->fail(200001);
- }
- if(_empty_($shop_good_id)){
- $shop_good_id = 0;
- }else{
- $shop_good_id = _abs($shop_good_id);
- }
- if($shop_good_id > 0){
- // 比较特殊,需要转换身份,由商家发送
- $tmp_ = $oid;
- $oid = $uid;
- $uid = $tmp_;
- $last_chat = WxChat::where('user_id', $uid)->where('object_id', $oid)->orderByDesc('id')->first();
- if($last_chat && $last_chat->expand_type == 4 && $last_chat->expand_id == $shop_good_id){
- return $this->success();
- }
- }
- if(_empty_($refer_id)){
- $refer_id = 0;
- }else{
- $refer_id = _abs($refer_id);
- }
- if(_empty_($refer_id) && _empty_($shop_good_id) && _empty_($voter_id)){
- if(_empty_($chat_content) && _empty_($chat_image) && (_empty_($chat_audio_url) || _empty_($chat_audio_length))){
- return $this->fail(200001);
- }
- }
- if(!UserUtils::is_user_can_chat($uid)){
- return $this->fail(200000, [], '抱歉,您没有聊天权限');
- }
- $model = WxContRepositories::add($uid, $oid, $chat_content, $chat_image, $chat_audio_url, $chat_audio_length, $refer_id, 0, 0, $shop_good_id, null, 0, $voter_id,$ask_order_id); //通用聊天
- //付费咨询的逻辑
- if($model){
- if($ask_order_id){
- //如果是答主的第一句话,倒计时开始
- $ask_order = DB::table('ask_order')->where('status',10)->where('id',$ask_order_id)->first();
- if($ask_order){
- $blogger_chat = DB::table('wx_chat')->where([
- ['user_id','=',$ask_order->blogger_user_id],
- ['object_id','=',$ask_order->user_id],
- ['expand_type','=',9],
- ['expand_id','=',$ask_order_id],
- ])->count();
- if($blogger_chat == 1){
- $countdown_time = $ask_order->ask_minute * 60 + time(); //倒计时时间
- DB::table('ask_order')->where('status',10)->where('id',$ask_order_id)->update([
- 'status' => 15, //已回复
- 'countdown_time' => $countdown_time, //倒计时
- ]);
- }
- }
- }
- }
- if($model){
- $websocket_id = GatewayUtils::uid2client_id($oid);
- if($websocket_id){
- GatewayUtils::success($websocket_id, 5, ['chat_content'=>_mini_emoji($chat_content, true), 'chat_image'=>$chat_image,
- 'from_user'=>UserUtils::get_cached_user($uid) ]);
- }
- $model->type = 'user';
- $imgList = array();
- array_push($imgList, ['img_url' => $model->chat_image]);
- $model->imgList = $imgList;
- $model->user = WxUser::where('id', $model->user_id)->first(FieldUtils::userInfoColums());
- $model->datetime = format_datetime($model->created_at);
- if($model->chat_audio_url && $model->chat_audio_length){
- $model->mode = 'audio';
- }else if($model->chat_image){
- $model->mode = 'img';
- }else if($model->refer_id){
- $model->mode = 'refer';
- }else{
- $model->mode = 'text';
- }
- if(!_empty_($model->chat_audio_length)){
- $min = (int)($model->chat_audio_length / 60);
- if($min < 10){
- $min = '0'.$min;
- }
- $sec = $model->chat_audio_length % 60;
- if($sec < 10){
- $sec = '0'.$sec;
- }
- $model->chat_audio_length = $min.':'.$sec;
- }
- }
- UserInputSafeCheckJob::dispatch($uid, _mini_emoji($chat_content, true));
- if($chat_image || $chat_audio_url){
- Utils::image_state_change([$chat_image, $chat_audio_url], 1);
- }
- return $this->success($model);
- }
- /**
- * 查询用户聊天记录
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function getUserChat(Request $request, $limit = 6)
- {
- $uid = $request->uid;
- $oid = $request->oid;
- if(_empty_($uid) || _empty_($oid)){
- return $this->fail(200001);
- }
- $data = WxChat::where(function($query) use ($uid, $oid) {
- $query->where(function ($query) use ($uid, $oid) {
- $query->where('user_id', $uid)
- ->where('object_id', $oid);
- })
- ->orWhere(function ($query) use ($uid, $oid) {
- $query->where('user_id', $oid)
- ->where('object_id', $uid);
- });
- })
- ->where('expand_type','!=',9) //排除问答聊天,因为要独立
- ->orderByRaw('id DESC')
- ->simplePaginate($limit);
- $data->map(function ($v) use ($uid){
- $v->type = 'user';
- $imgList = array();
- array_push($imgList, ['img_url' => $v->chat_image]);
- $v->imgList = $imgList;
- $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
- $v->datetime = format_datetime($v->created_at);
- if($v->chat_audio_url && $v->chat_audio_length){
- $v->mode = 'audio';
- }else if($v->chat_image){
- $v->mode = 'img';
- }else if($v->refer_id){
- $v->mode = 'refer';
- if($v->expand_type != 1 || $v->expand_id != $v->refer_id){
- ChatExpandTypeCheckJob::dispatch();
- }
- }else if($v->adoption_apply_id){
- $v->mode = 'adoption_reply';
- if($v->expand_type != 3 || $v->expand_id != $v->adoption_apply_id){
- ChatExpandTypeCheckJob::dispatch();
- }
- }else if($v->contact_apply_id){
- $v->mode = 'contact_apply';
- if($v->expand_type != 2 || $v->expand_id != $v->contact_apply_id){
- ChatExpandTypeCheckJob::dispatch();
- }
- }else{
- if($v->expand_type > 0){
- if($v->expand_type == 1){
- $v->mode = 'refer';
- $v->refer_id = $v->expand_id;
- }else if($v->expand_type == 2){
- $v->mode = 'contact_apply';
- $v->contact_apply_id = $v->expand_id;
- }else if($v->expand_type == 3){
- $v->mode = 'adoption_reply';
- $v->adoption_apply_id = $v->expand_id;
- }else if($v->expand_type == 4){
- $v->mode = 'shop_good';
- $v->shop_good_id = $v->expand_id;
- }else if($v->expand_type == 5){
- $v->mode = 'used_good';
- $v->used_good_id = $v->expand_id;
- }else if($v->expand_type == 8){
- $v->mode = 'voter';
- $v->voter_id = $v->expand_id;
- }else if($v->expand_type == 9){
- //仅占用
- $v->mode = 'ask_order';
- $v->ask_order_id = $v->expand_id;
- }else if(in_array($v->expand_type, [101, 102, 103, 104, 105, 106, 107, 108, 109, 110])){
- $v->mode = 'review';
- }else{
- // 101: 笔记审核 102:评论审核 103:组局审核 104:选票审核 105:选手审核 106:闲置审核
- return $this->fail(200006, [], '数据库expand_type不合法');
- }
- }else{
- $v->mode = 'text';
- }
- }
- if($v->mode == 'review'){
- if($v->expand_type == 101){
- $the_post = WxPost::find($v->expand_id);
- if($the_post){
- $posts_content = $the_post->posts_content;
- if($posts_content){
- $s_content = preg_replace("/<(img|video).*?src[^\'\"]+[\'\"]([^\"\']+)[^>]+>/is", '', $posts_content);
- $s_content =trim_all_space(strip_tags(html_entity_decode($s_content)), true);
- }
- $v->chat_content = $the_post->posts_title ?: PostUtils::get_the_title($s_content, $the_post->id);
- PostUtils::mediaProcess($the_post, $uid, 90003, 0, true);
- $v->chat_image = Utils::imgWithStyle($the_post->img, 0, false, true);
- $v->review = [
- 'target_type' => 1,
- 'target_id' => $v->expand_id,
- 'state' => $the_post->is_examine,
- 'title_tip' => '笔记',
- 'state_tip' => [0=>'待审核', 1=>'审核通过', 2=>'驳回'][$the_post->is_examine],
- 'can_refuse' => 1,
- 'user' => UserUtils::get_cached_user($the_post->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }else if($v->expand_type == 102){
- $the_comment = WxComment::find($v->expand_id);
- if($the_comment){
- $v->chat_image = $the_comment->comment_img_url;
- $v->chat_content = $the_comment->comment_content;
- $v->review = [
- 'target_type' => 25,
- 'target_id' => '评论不可跳转',
- 'state' => $the_comment->comment_state,
- 'title_tip' => '笔记评论',
- 'state_tip' => [0=>'待审核', 1=>'审核通过', 2=>'驳回'][$the_comment->comment_state],
- 'can_refuse' => 1,
- 'user' => UserUtils::get_cached_user($the_comment->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }else if($v->expand_type == 104){
- $the_voter = WxVoter::find($v->expand_id);
- if($the_voter){
- $v->chat_content = $the_voter->title;
- if($the_voter->banners){
- $v->chat_image = _array_key($the_voter->banners, 0, '');
- }
- $v->review = [
- 'target_type' => 33,
- 'target_id' => $v->expand_id,
- 'state' => $the_voter->status,
- 'title_tip' => '选票',
- 'state_tip' => [0=>'审核中', 1=>'推送中', 2=>'驳回'][$the_voter->status],
- 'can_refuse' => 0,
- 'user' => UserUtils::get_cached_user($the_voter->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }else if($v->expand_type == 105){
- $player = WxVoterPlayer::find($v->expand_id);
- if($player){
- $v->chat_content = $player->show_name;
- if($player->img_urls){
- $v->chat_image = _array_key($player->img_urls, 0, '');
- }
- $v->review = [
- 'target_type' => 6,
- 'target_id' => '/pagesV/voter/detail/player?id='.$v->expand_id,
- 'state' => $player->status,
- 'title_tip' => '选票选手',
- 'state_tip' => [0=>'审核中', 1=>'推送中', 2=>'驳回'][$player->status],
- 'can_refuse' => 0,
- 'user' => UserUtils::get_cached_user($player->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }else if($v->expand_type == 106){
- $the_used = WxUsedGood::find($v->expand_id);
- if($the_used){
- $v->chat_content = $the_used->title;
- if($the_used->image_urls){
- $v->chat_image = _array_key($the_used->image_urls[0], 'url', '');
- }
- $v->review = [
- 'target_type' => 28,
- 'target_id' => $v->expand_id,
- 'state' => $the_used->status == 99 ? 2 : ($the_used->status === 0 ? 0 : 1),
- 'title_tip' => '闲置商品',
- 'state_tip' => FieldUtils::usedGoodState()[$the_used->status],
- 'can_refuse' => 1,
- 'user' => UserUtils::get_cached_user($the_used->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }else if($v->expand_type == 107){
- $the_circle = WxCircle::find($v->expand_id);
- if($the_circle){
- $v->chat_content = $the_circle->circle_name;
- $v->chat_image = $the_circle->head_portrait;
- $v->review = [
- 'target_type' => 2,
- 'target_id' => $v->expand_id,
- 'state' => $the_circle->circle_state,
- 'title_tip' => '新建圈子',
- 'state_tip' => [0=>'审核中', 1=>'推送中', 2=>'驳回'][$the_circle->circle_state],
- 'can_refuse' => 1,
- 'user' => UserUtils::get_cached_user($the_circle->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }else if($v->expand_type == 108){
- $student = WxUserStudentCertify::where('user_id', $v->expand_id)->first();
- if($student){
- $v->chat_content = $student->school;
- $v->chat_image = $student->picture;
- $v->review = [
- 'target_type' => 25,
- 'target_id' => '学生认证暂不可跳转',
- 'state' => $student->status,
- 'title_tip' => '学生认证',
- 'state_tip' => [0=>'待审核', 1=>'已通过', 2=>'驳回'][$student->status],
- 'can_refuse' => 0,
- 'user' => UserUtils::get_cached_user($student->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }else if($v->expand_type == 109){
- $authentication = WxAuthentication::find($v->expand_id);
- if($authentication){
- $v->chat_content = $authentication->name;
- $v->chat_image = $authentication->identity_picture;
- $v->review = [
- 'target_type' => 25,
- 'target_id' => '身份认证暂不可跳转',
- 'state' => $authentication->authentication_state,
- 'title_tip' => '身份认证',
- 'state_tip' => [0=>'审核中', 1=>'已通过', 2=>'驳回'][$authentication->authentication_state],
- 'can_refuse' => 0,
- 'user' => UserUtils::get_cached_user($authentication->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }else if($v->expand_type == 110){
- $club = WxClub::where('id', $v->expand_id)->first();
- if($club){
- $v->chat_content = _empty_default_($club->name_tmp, $club->name);
- $v->chat_image = _empty_default_($club->avatar_tmp, $club->avatar);
- $v->review = [
- 'target_type' => 35,
- 'target_id' => $v->expand_id,
- 'state' => $club->status,
- 'title_tip' => '俱乐部审核',
- 'state_tip' => [0=>'待审核', 1=>'已通过', 2=>'驳回'][$club->status],
- 'can_refuse' => 0,
- 'user' => UserUtils::get_cached_user($club->user_id),
- ];
- }else{
- WxChat::where('id', $v->id)->forceDelete();
- }
- }
- if(_empty_($v->chat_image)){
- $v->chat_image = Settings::get('img_default', '').'?imageMogr2/thumbnail/200x200/crop/200x200/gravity/center/format/jpg/interlace/0/quality/100';
- }else{
- $v->chat_image = $v->chat_image.'?imageMogr2/thumbnail/200x200/crop/200x200/gravity/center/format/jpg/interlace/0/quality/100';
- }
- }
- if(!_empty_($v->chat_audio_length)){
- $min = (int)($v->chat_audio_length / 60);
- if($min < 10){
- $min = '0'.$min;
- }
- $sec = $v->chat_audio_length % 60;
- if($sec < 10){
- $sec = '0'.$sec;
- }
- $v->chat_audio_length = $min.':'.$sec;
- }
- if(!_empty_($v->refer_id)){
- if($v->refer_id && $v->refer_id > 0){
- $refer_post = WxPost::find($v->refer_id);
- if($refer_post){
- PostUtils::mediaProcess($refer_post, $uid, 15, 0, true);
- if($refer_post->posts_content_raw){
- $refer_post->posts_content_raw = strip_tags($refer_post->posts_content_raw);
- }
- $v->refer = $refer_post;
- }else{
- WxChat::where('id', $v->id)->delete();
- }
- }else{
- $v->refer = null;
- }
- }
- if(!_empty_($v->adoption_apply_id)){
- if($v->adoption_apply_id && $v->adoption_apply_id > 0){
- $adoption_reply = WxPetsAdoptionApply::find($v->adoption_apply_id);
- if($adoption_reply){
- $v->adoption_reply = PetUtils::adoption_apply_process($adoption_reply, $uid);
- $v->adoption_reply->adoption = PetUtils::adoption_process(WxPetsAdoption::find($adoption_reply->pet_adoption_id));
- }else{
- WxChat::where('id', $v->id)->delete();
- }
- }else{
- $v->adoption_reply = null;
- }
- }
- if(!_empty_($v->used_good_id)){
- $user_good = WxUsedGood::where('id', $v->used_good_id)->first();
- if($user_good){
- ShopUtils::used_process($user_good);
- if($user_good->pic){
- $user_good->pic = $user_good->pic.'?imageMogr2/quality/100/format/webp/interlace/0/crop/200x200/gravity/center/thumbnail/200x';
- }
- $user_good->servicer_word = '亲,想要可以直接拍';
- $v->used_good = $user_good;
- }else{
- WxChat::where('id', $v->id)->delete();
- }
- }
- if(!_empty_($v->voter_id)){
- $voter = WxVoter::where('id', $v->voter_id)->first();
- if($voter){
- if($voter->banners){
- $voter->pic = $voter->banners[0];
- }
- $v->voter = $voter;
- }else{
- WxChat::where('id', $v->id)->delete();
- }
- }
- if(!_empty_($v->ask_order_id)){
- //仅占用
- }
- if(!_empty_($v->shop_good_id)){
- $data = WxShopGoods::where('id', $v->shop_good_id)->first()->toArray();
- if($data) {
- // 服务
- if (isset($data['service_id'])) {
- $service_tip = '';
- $data['service'] = WxShopService::whereIn('id', json_decode($data['service_id'], true))->get(['name', 'intro'])->map(function ($s) use (&$service_tip){
- if(_empty_($service_tip)){
- $service_tip .= '"'.$s->name.'"';
- }else{
- $service_tip .= ',' . '"'.$s->name.'"';
- }
- return $s;
- });
- if($service_tip){
- $service_tip = '亲,我们这款商品的服务为' . $service_tip . '~';
- }
- $data['service_tip'] = $service_tip;
- if($data['pic'] && is_array($data['pic']) && count($data['pic']) > 0){
- $data['pic'][0] = $data['pic'][0].'?imageMogr2/quality/100/format/webp/interlace/0/crop/200x200/gravity/center/thumbnail/200x';
- }
- } else {
- $data['service'] = null;
- $data['service_tip'] = '';
- }
- $data['user_purchase'] = ShopUtils::user_buy_goods_times($uid, $data['id']);
- $v->shop_good = $data;
- }
- }
- if(!_empty_($v->contact_apply_id)){
- if($v->contact_apply_id && $v->contact_apply_id > 0){
- $contact_apply = WxUserContactApply::find($v->contact_apply_id);
- if($contact_apply){
- if($contact_apply->user_id == $uid){
- // 己方发送
- $title = '申请查看对方的';
- if($contact_apply->is_phone == 1){
- $title .= '手机号';
- }
- if($contact_apply->is_wechat_account == 1){
- if($contact_apply->is_phone == 1){
- $title .= '、微信号';
- }else{
- $title .= '微信号';
- }
- }
- $contact_apply->title = $title;
- }else{
- $title = '我申请查看你的';
- if($contact_apply->is_phone == 1){
- $title .= '手机号';
- }
- if($contact_apply->is_wechat_account == 1){
- if($contact_apply->is_phone == 1){
- $title .= '、微信号';
- }else{
- $title .= '微信号';
- }
- }
- $contact_apply->title = $title;
- }
- $contact_apply->status_tip = '申请中';
- if($contact_apply->status == 1){
- $contact_apply->status_tip = '已同意';
- }else if($contact_apply->status == 2){
- $contact_apply->status_tip = '已过期';
- }
- $v->contact_apply = $contact_apply;
- }else{
- $v->contact_apply = null;
- }
- }else{
- $v->contact_apply = null;
- }
- }
- $allowable[] = [
- 'text' => '复制',
- 'type' => 'copy',
- 'id' => $v->id,
- 'raw' => strip_tags($v->chat_content),
- 'icon' => 'mini-icon mini-fuzhi'
- ];
- $v->allowable = $allowable;
- return $v;
- });
- return $this->success($data);
- }
- /**
- * 查询用户问答订单聊天记录
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function getUserAskOrderChat(Request $request, $limit = 6)
- {
- $uid = $request->uid;
- $oid = $request->oid;
- $ask_order_id = $request->ask_order_id;
- if(_empty_($uid) || _empty_($oid)){
- return $this->fail(200001);
- }
- $data = WxChat::where(function($query) use ($uid, $oid) {
- $query->where(function ($query) use ($uid, $oid) {
- $query->where('user_id', $uid)
- ->where('object_id', $oid);
- })
- ->orWhere(function ($query) use ($uid, $oid) {
- $query->where('user_id', $oid)
- ->where('object_id', $uid);
- });
- })
- ->where('expand_type',9) //只要问答订单的
- ->where('expand_id',$ask_order_id) //只要问答订单的
- ->orderByRaw('id DESC')
- ->simplePaginate($limit);
- $data->map(function ($v) use ($uid){
- $v->type = 'user';
- $imgList = array();
- array_push($imgList, ['img_url' => $v->chat_image]);
- $v->imgList = $imgList;
- $v->user = WxUser::where('id', $v->user_id)->first(FieldUtils::userInfoColums());
- $v->datetime = format_datetime($v->created_at);
- if($v->chat_audio_url && $v->chat_audio_length){
- $v->mode = 'audio';
- }else if($v->chat_image){
- $v->mode = 'img';
- }else{
- $v->mode = 'text';
- }
- if(!_empty_($v->chat_audio_length)){
- $min = (int)($v->chat_audio_length / 60);
- if($min < 10){
- $min = '0'.$min;
- }
- $sec = $v->chat_audio_length % 60;
- if($sec < 10){
- $sec = '0'.$sec;
- }
- $v->chat_audio_length = $min.':'.$sec;
- }
- $allowable[] = [
- 'text' => '复制',
- 'type' => 'copy',
- 'id' => $v->id,
- 'raw' => strip_tags($v->chat_content),
- 'icon' => 'mini-icon mini-fuzhi'
- ];
- $v->allowable = $allowable;
- return $v;
- });
- return $this->success($data);
- }
- /**
- * 已读对应用户信息
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function readUserChat(Request $request)
- {
- $uid = $request->uid;
- $oid = $request->oid;
- if(_empty_($oid)){
- return $this->fail(200001);
- }
- $data = WxChat::where([['user_id','=', $oid],['object_id', '=', $uid],['expand_type', '!=', 9]])->update(['is_read' => 1]);
- return $this->success($data);
- }
- /**
- * 已读对应用户咨询信息
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- */
- public function readAskOrderChat(Request $request)
- {
- $uid = $request->uid;
- $oid = $request->oid;
- $ask_order_id = $request->ask_order_id;
- if(_empty_($oid) || _empty_($ask_order_id)){
- return $this->fail(200001);
- }
- $data = WxChat::where([['user_id','=', $oid],['object_id', '=', $uid],['expand_type', '=', 9],['expand_id', '=', $ask_order_id]])->update(['is_read' => 1]);
- return $this->success($data);
- }
- /**
- * 用户删除聊天记录
- */
- public function userDelMessage(Request $request)
- {
- $uid = $request->uid;
- $userid = $request->userid;
- $data = WxChat::where(function ($query) use ($uid, $userid) {
- $query->where('user_id', $uid)
- ->where('object_id', $userid);
- })
- ->orWhere(function ($query) use ($uid, $userid) {
- $query->where('user_id', $userid)
- ->where('object_id', $uid);
- })->update(['chat_state' => 1]);
- return $this->success($data);
- }
- }
|