|
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 供需
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Mobile;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Helpers\ResponseCode;
|
|
|
|
|
|
use App\Models\AppointmentConfig;
|
|
|
|
|
|
use App\Models\AppointmentType;
|
|
|
|
|
|
use App\Models\Banner;
|
|
|
|
|
|
use App\Models\Config;
|
|
|
|
|
|
use App\Models\Dialogue;
|
|
|
|
|
|
use App\Models\Message;
|
|
|
|
|
|
use App\Models\SupplyDemand;
|
|
|
|
|
|
use App\Models\SupplyDemandKeep;
|
|
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Services\SupplyDemand\Profiles;
|
|
|
|
|
|
use App\Services\SupplyDemand\Conversations;
|
|
|
|
|
|
use App\Services\SupplyDemand\Settings;
|
|
|
|
|
|
|
|
|
|
|
|
class SupplyDemandController extends CommonController
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/index",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="供需列表",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="myself", in="query", @OA\Schema(type="integer"), required=true, description="是否只看自己的0否1是"),
|
|
|
|
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="integer"), required=true, description="类型"),
|
|
|
|
|
|
* @OA\Parameter(name="keyword", in="query", @OA\Schema(type="integer"), required=true, description="关键词"),
|
|
|
|
|
|
* @OA\Parameter(name="status", in="query", @OA\Schema(type="integer"), required=true, description="状态0待审核1通过2拒绝3退回修改4永久隐藏"),
|
|
|
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
|
|
|
|
|
|
* @OA\Parameter(name="expire_type", in="query", @OA\Schema(type="string"), required=false, description="有效期类型1有效期内2失效的"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function index()
|
|
|
|
|
|
{
|
|
|
|
|
|
$q = SupplyDemand::with('user');
|
|
|
|
|
|
if (request('myself') == 1) {
|
|
|
|
|
|
if (!\App\Http\Middleware\SupplyDemandAccess::registered($this->getUser())) return $this->fail([10003, '请先登录或注册']);
|
|
|
|
|
|
$q->where('user_id', $this->getUserId());
|
|
|
|
|
|
if (request()->has('status') && request('status') != -1) $q->where('status', request('status'));
|
|
|
|
|
|
} else { $q->where('status', 1); }
|
|
|
|
|
|
if (request('type')) $q->where('type', request('type'));
|
|
|
|
|
|
if (request('keyword')) $q->where(function ($s) { $s->where('title', 'like', '%' . request('keyword') . '%')->orWhere('content', 'like', '%' . request('keyword') . '%'); });
|
|
|
|
|
|
if (request('expire_type')) {
|
|
|
|
|
|
if (request('expire_type') == 1) $q->where(function ($s) { $s->whereNull('expire_time')->orWhere('expire_time', '>', now()); });
|
|
|
|
|
|
else $q->where('expire_time', '<=', now());
|
|
|
|
|
|
}
|
|
|
|
|
|
$list = $q->orderBy('id', 'desc')->paginate(min(100, max(1, (int) request('page_size', 20))));
|
|
|
|
|
|
$list->getCollection()->transform(function ($d) { return Profiles::demand($d, false, $this->getUserId()); });
|
|
|
|
|
|
return $this->success(['supplyDemands' => $list]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/detail",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="详情",
|
|
|
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="integer"), required=true, description="id"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response=200,
|
|
|
|
|
|
* description="操作成功"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function detail()
|
|
|
|
|
|
{
|
|
|
|
|
|
$d = SupplyDemand::with('user')->find(request('id'));
|
|
|
|
|
|
$isOwner = $this->getUserId() && $d && (int) $d->user_id === (int) $this->getUserId();
|
|
|
|
|
|
if (!$d || ((int) $d->status !== 1 && !$isOwner)) return $this->fail([ResponseCode::ERROR_BUSINESS, '供需信息不存在或已下架']);
|
|
|
|
|
|
$d->increment('view_count');
|
|
|
|
|
|
$out = Profiles::demand($d, false, $this->getUserId());
|
|
|
|
|
|
$out['messages_count'] = $d->messages()->where('user_id', $this->getUserId())->count();
|
|
|
|
|
|
$out['tips'] = Settings::tips();
|
|
|
|
|
|
return $this->success($out);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Post(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/save",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="更新",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="integer"), required=false, description="需求供应表ID(存在则更新,不存在则新增)"),
|
|
|
|
|
|
* @OA\Parameter(name="title", in="query", @OA\Schema(type="string"), required=false, description="标题"),
|
|
|
|
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="integer"), required=false, description="分类1供应2需求"),
|
|
|
|
|
|
* @OA\Parameter(name="content", in="query", @OA\Schema(type="string"), required=false, description="内容"),
|
|
|
|
|
|
* @OA\Parameter(name="tag", in="query", @OA\Schema(type="string"), required=false, description="标签"),
|
|
|
|
|
|
* @OA\Parameter(name="wechat", in="query", @OA\Schema(type="string"), required=false, description="微信号"),
|
|
|
|
|
|
* @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), required=false, description="电话"),
|
|
|
|
|
|
* @OA\Parameter(name="email", in="query", @OA\Schema(type="string"), required=false, description="邮箱"),
|
|
|
|
|
|
* @OA\Parameter(name="expire_time", in="query", @OA\Schema(type="string"), required=false, description="过期时间"),
|
|
|
|
|
|
* @OA\Parameter(name="public_way", in="query", @OA\Schema(type="string"), required=false, description="公开模式1直接公开2私信后自动公开3不公开"),
|
|
|
|
|
|
* @OA\Parameter(name="file_ids", in="query", @OA\Schema(type="string"), required=false, description="文件id数组"),
|
|
|
|
|
|
* @OA\Parameter(name="contact_name", in="query", @OA\Schema(type="string"), required=false, description="联系人名字"),
|
|
|
|
|
|
* @OA\Parameter(name="status", in="query", @OA\Schema(type="integer"), required=false, description="状态0待审核1通过2拒绝3退回修改4永久隐藏"),
|
|
|
|
|
|
* @OA\Parameter(name="tags", in="query", @OA\Schema(type="integer"), required=false, description="标签,多个英文逗号分隔"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function save()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = request()->only(['id','title','type','content','tag','wechat','mobile','email','expire_time','public_way','file_ids','contact_name','fund_type','amount','fund_stage','fund_company','industry_type','product','desc','status']);
|
|
|
|
|
|
if (isset($all['status']) && !in_array((int) $all['status'], [0, 1, 4], true)) unset($all['status']);
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (isset($all['id'])) {
|
|
|
|
|
|
$model = SupplyDemand::where('user_id', $this->getUserId())->find($all['id']);
|
|
|
|
|
|
if (empty($model)) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '数据不存在']);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
$model = new SupplyDemand();
|
|
|
|
|
|
$all['user_id'] = $this->getUserId();
|
|
|
|
|
|
// 短信通知
|
|
|
|
|
|
$supply_demand_mobile = Config::getValueByKey('supply_demand_mobile');
|
|
|
|
|
|
$supply_demand_mobile = explode(',', $supply_demand_mobile);
|
|
|
|
|
|
$smsSign = Config::getValueByKey('sms_sign');
|
|
|
|
|
|
$content = "{$smsSign}【{$this->getUser()->name}】发布了一条新的供需信息";
|
|
|
|
|
|
foreach ($supply_demand_mobile as $mobile) {
|
|
|
|
|
|
ymSms($mobile, $content);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($model->is_proxy) { $all['public_way'] = 3; $all['status'] = isset($all['status']) && (int) $all['status'] === 4 ? 4 : ((int) $model->status === 1 ? 1 : 0); }
|
|
|
|
|
|
$model->fill($all);
|
|
|
|
|
|
$model->save();
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
return $this->success($model);
|
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
|
return $this->fail([$exception->getCode(), $exception->getMessage()]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/destroy",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="删除",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"),
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function destroy()
|
|
|
|
|
|
{
|
|
|
|
|
|
$d = SupplyDemand::where('user_id', $this->getUserId())->find(request('id'));
|
|
|
|
|
|
if (!$d) return $this->fail([ResponseCode::ERROR_BUSINESS, '数据不存在']);
|
|
|
|
|
|
$d->delete(); return $this->success('删除成功');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Post(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/send-message",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="发送消息",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="supply_demand_id", in="query", @OA\Schema(type="string"), required=true, description="供需信息id(选填)"),
|
|
|
|
|
|
* @OA\Parameter(name="content", in="query", @OA\Schema(type="string"), required=true, description="内容"),
|
|
|
|
|
|
* @OA\Parameter(name="to_user_id", in="query", @OA\Schema(type="string"), required=true, description="接收人用户id"),
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function sendMessage()
|
|
|
|
|
|
{
|
|
|
|
|
|
try { return $this->success(Conversations::send($this->getUserId(), request()->all())); }
|
|
|
|
|
|
catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return $this->fail([ResponseCode::ERROR_BUSINESS, '对接记录或需求不存在']); }
|
|
|
|
|
|
catch (\InvalidArgumentException $e) { return $this->fail([ResponseCode::ERROR_BUSINESS, $e->getMessage()]); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/message-list",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="消息列表",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="to_user_id", in="query", @OA\Schema(type="string"), required=true, description="对方的用户id"),
|
|
|
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function messageList()
|
|
|
|
|
|
{
|
|
|
|
|
|
try {
|
|
|
|
|
|
$viewer = $this->getUserId();
|
|
|
|
|
|
$d = Conversations::resolve($viewer, request()->all());
|
|
|
|
|
|
if (!$d) return $this->success(['message' => ['data' => [], 'current_page' => 1, 'last_page' => 1], 'dialogue_id' => null]);
|
|
|
|
|
|
$messages = $d->messages()->with(['user', 'toUser', 'supplyDemand'])->orderBy('id', 'desc')->paginate(min(100, max(1, (int) request('page_size', 20))));
|
|
|
|
|
|
Message::whereIn('id', $messages->pluck('id'))->where('to_user_id', $viewer)->update(['is_read' => 1]);
|
|
|
|
|
|
$messages->getCollection()->transform(function ($m) use ($viewer) {
|
|
|
|
|
|
return ['id' => $m->id, 'user_id' => $m->user_id, 'to_user_id' => $m->to_user_id, 'content' => $m->content,
|
|
|
|
|
|
'created_at' => $m->created_at->format('Y-m-d H:i:s'), 'supply_demand_id' => $m->supply_demand_id,
|
|
|
|
|
|
'user' => Profiles::user($m->user), 'to_user' => Profiles::user($m->toUser),
|
|
|
|
|
|
'supply_demand' => $m->supplyDemand ? ['id' => $m->supplyDemand->id, 'title' => $m->supplyDemand->title] : null];
|
|
|
|
|
|
});
|
|
|
|
|
|
$summary = Conversations::summary($d, $viewer);
|
|
|
|
|
|
return $this->success(['message' => $messages, 'dialogue_id' => $d->id, 'supplyDemand' => $summary['supply_demand'], 'other_profile' => $summary['other_profile'], 'tips' => Settings::tips()]);
|
|
|
|
|
|
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return $this->fail([ResponseCode::ERROR_BUSINESS, '对接记录或需求不存在']); }
|
|
|
|
|
|
catch (\InvalidArgumentException $e) { return $this->fail([ResponseCode::ERROR_BUSINESS, $e->getMessage()]); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/dialogues",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="会话列表",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
|
|
|
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function dialogues()
|
|
|
|
|
|
{
|
|
|
|
|
|
$viewer = $this->getUserId();
|
|
|
|
|
|
$list = Dialogue::with(['user', 'toUser', 'supplyDemand'])->where(function ($q) use ($viewer) { $q->where('user_id', $viewer)->orWhere('to_user_id', $viewer); })
|
|
|
|
|
|
->whereColumn('user_id', '<>', 'to_user_id')->whereHas('messages')->orderBy('last_datetime', 'desc')->paginate(min(100, max(1, (int) request('page_size', 30))));
|
|
|
|
|
|
$list->getCollection()->transform(function ($d) use ($viewer) { return Conversations::summary($d, $viewer); });
|
|
|
|
|
|
return $this->success(['dialogue' => $list]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/keep-index",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="收藏列表",
|
|
|
|
|
|
* description="",
|
|
|
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
|
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
|
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
|
* response="200",
|
|
|
|
|
|
* description="暂无"
|
|
|
|
|
|
* )
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function keepIndex()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = request()->all();
|
|
|
|
|
|
$supplyDemands = SupplyDemandKeep::where('user_id', $this->getUserId())
|
|
|
|
|
|
->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')
|
|
|
|
|
|
->paginate($all['page_size'] ?? 20);
|
|
|
|
|
|
return $this->success(compact('supplyDemands'));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Post(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/keep-supply-demand",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="收藏供需帖子",
|
|
|
|
|
|
* @OA\Parameter(name="supply_demand_id", in="query", @OA\Schema(type="integer"), required=true, description="供需帖子id"),
|
|
|
|
|
|
* @OA\Response(response=200, description="操作成功")
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function keepSupplyDemand()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = \request()->all();
|
|
|
|
|
|
$messages = [
|
|
|
|
|
|
'supply_demand_id.required' => '供需信息id必填'
|
|
|
|
|
|
];
|
|
|
|
|
|
$validator = Validator::make($all, [
|
|
|
|
|
|
'supply_demand_id' => 'required',
|
|
|
|
|
|
], $messages);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
|
|
|
}
|
|
|
|
|
|
$data = [
|
|
|
|
|
|
'user_id' => $this->getUserId(),
|
|
|
|
|
|
'supply_demand_id' => $all['supply_demand_id']
|
|
|
|
|
|
];
|
|
|
|
|
|
SupplyDemandKeep::firstOrCreate($data);
|
|
|
|
|
|
return $this->success('收藏成功');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @OA\Post(
|
|
|
|
|
|
* path="/api/mobile/supply-demand/un-keep-supply-demand",
|
|
|
|
|
|
* tags={"小程序-供需"},
|
|
|
|
|
|
* summary="取消收藏供需帖子",
|
|
|
|
|
|
* @OA\Parameter(name="supply_demand_id", in="query", @OA\Schema(type="integer"), required=true, description="供需帖子id"),
|
|
|
|
|
|
* @OA\Response(response=200, description="操作成功")
|
|
|
|
|
|
* )
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function unKeepSupplyDemand()
|
|
|
|
|
|
{
|
|
|
|
|
|
$all = \request()->all();
|
|
|
|
|
|
$messages = [
|
|
|
|
|
|
'supply_demand_id.required' => '供需信息id必填'
|
|
|
|
|
|
];
|
|
|
|
|
|
$validator = Validator::make($all, [
|
|
|
|
|
|
'supply_demand_id' => 'required',
|
|
|
|
|
|
], $messages);
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
|
|
|
}
|
|
|
|
|
|
$keep = SupplyDemandKeep::where('user_id', $this->getUserId())->where('supply_demand_id', $all['supply_demand_id'])->first();
|
|
|
|
|
|
if (empty($keep)) {
|
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '该信息没有收藏']);
|
|
|
|
|
|
}
|
|
|
|
|
|
$keep->delete();
|
|
|
|
|
|
return $this->success('取消收藏成功');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function unreadCount()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->success(['unread_count' => Message::where('to_user_id', $this->getUserId())->whereColumn('user_id', '<>', 'to_user_id')->where('is_read', 0)->count()]);
|
|
|
|
|
|
}
|
|
|
|
|
|
public function session()
|
|
|
|
|
|
{
|
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
|
return $this->success(['registered' => (bool) \App\Http\Middleware\SupplyDemandAccess::registered($user),
|
|
|
|
|
|
'user' => $user ? ['id' => $user->id, 'name' => $user->name, 'mobile' => $user->getRawOriginal('mobile'), 'company_name' => $user->company_name, 'nickname' => $user->nickname, 'headimgurl' => $user->headimgurl] : null]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|