Esempio n. 1
0
	public function supply($id){
		$supply = Supply::find($id);

		if($supply == null){
			return API::error([1002, '没有该供应信息']);
		}

		$use = User::user();
		if ($supply->user_id == $user->id) {
            return API::error([1003, '不能给自己创建的供应发送留言']);
        }

        $message = Message::create([
        	'user_id'   => $user->id,
            'type'      => 'supply',
            'supply_id' => $supply->id,
            'demand_id' => null,
            'title'     => request('title'),
        ]);

        if ($message == null) {
            return API::error([1004, '发送意向失败']);
        }

        return API::success();
	}
Esempio n. 2
0
    public function demand($id)
    {
        $demand = Demand::find($id);
        if ($demand == null) {
            return API::error([1002, '没有该需求信息']);
        }

        $user = User::user();
        if ($demand->user_id == $user->id) {
            return API::error([1003, '不能给自己创建的需求发送意见']);
        }

        $coop = Cooperation::create([
            'user_send' => $user->id,
            'user_recv' => $demand->user_id,
            'type'      => 'demand',
            'demand_id' => $demand->id,
            'supply_id' => null,
            'phone'     => request('phone'),
            'contacts'  => request('contacts'),
            'content'   => request('content'),
        ]);

        if ($coop == null) {
            return API::error([1004, '发送意向失败']);
        }

        return API::success();
    }
Esempio n. 3
0
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (User::check() == false) {
            if ($request->ajax() || $request->wantsJson()) {
                return API::error(['code' => 101, '' => '']);
            } else {
                return redirect()->guest('user/login');
            }
        }

        return $next($request);
    }
Esempio n. 4
0
    public function image()
    {
        $config = [
            'rootDir'       => 'uploads/images',
            'subDir'        => 'Y-m-d',
            'maxSize'       => 5000000,
            'extensions'    => ['jpg', 'png', 'jpeg', 'bmp', 'gif'],
        ];

        try {
            $file = new FileUpload('file', $config);
            $info = $file->upload();
            return API::success($info);
        } catch (FileUploadException $e) {
            return API::error([$e->getCode(), $e->getMessage()]);
        }
    }