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();
    	}
    }
    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 #3
0
 public function demand()
 {
     $demands = Demand::where('user_id', User::user()->id)->orderBy('created_at', 'desc')->paginate();
     return view('user.demand')->withDemands($demands);
 }