Example #1
0
    public static function createDemand(){
    	$validator = self::validator();
        if ($validator->fails()) {
            return back()->withErrors($validator->errors())->withInput();
        }

    	DB::transaction(function() use(&$warehouse){
    		$demand = Demand::create([
    			'type_id'	=>	1,
    			'title' 	=>	request('title'),
    			'user_id'   => User::user()->id,
    			'desc'      => request('desc'),
                'stage'     => 2,
    		]);

    		$warehouse = new self(request()->all());
    		$warehouse = $demand->warehouse()->save($warehouse);
    	});

    	if ($warehouse != null) {
    		return redirect('user/demand');
    	}else {
    		return back()->withErrors('创建失败')->withInput();
    	}
    }
Example #2
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();
	}
Example #3
0
    public static function createSupply()
    {
        $validator = self::validator();
        if ($validator->fails()) {
            return back()->withErrors($validator->errors())->withInput();
        }

        DB::transaction(function() use (&$personal) {
            $supply = Supply::create([
                'type_id'   => 3,
                'title'     => request('title'),
                'user_id'   => User::user()->id,
                'desc'      => request('desc'),
                'stage'     => 2,
            ]);

            $personal = new self(request()->all());

            $personal = $supply->personal()->save($personal);
        });

        if ($personal != null) {
            return redirect('user/supply');
        } else {
            return back()->withErrors('创建失败')->withInput();
        }
    }
    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();
    }
Example #5
0
    public function getEdit($id)
    {
        $supply = Supply::get($id);

        if ($supply->supply->user_id != User::user()->id) {
            return view('errors.common')->withErrors('只能编辑自己发布的信息');
        }

        return view('supply.supply_edit')
            ->withSupply($supply)
            ->withType(strtolower($supply->type->code));
    }
Example #6
0
    public static function editSupply($id)
    {
        $supply = self::get($id);

        if ($supply == null) {
            return back()->withInput();
        }

        if ($supply->supply->user_id != User::user()->id) {
            return view('errors.common')->withErrors('只能编辑自己发布的信息');
        }

        $type = $supply->type->code;

        switch ($type) {
            case 'warehouse':
                return Supply\Warehouse::editSupply($supply);
                break;
            case 'vehicle':
            return Supply\Vehicle::editSupply($supply);
                break;
            case 'personal':
                return Supply\Personal::editSupply($supply);
                break;
            case 'building':
                break;
            case 'general':
                break;
            default:
                return back()->withInput();
        }
    }
Example #7
0
 public function demand()
 {
     $demands = Demand::where('user_id', User::user()->id)->orderBy('created_at', 'desc')->paginate();
     return view('user.demand')->withDemands($demands);
 }